1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-22 23:49:03 +00:00

Some patches from Marek

This commit is contained in:
fyodor
2006-07-04 08:00:11 +00:00
parent 30190d664a
commit d3055b26bf
9 changed files with 18 additions and 141 deletions

View File

@@ -2927,84 +2927,3 @@ if (echots) *echots = 0;
return 0;
}
IPProbe::IPProbe() {
packetbuflen = 0;
packetbuf = NULL;
Reset();
}
void IPProbe::Reset() {
if (packetbuf)
free(packetbuf);
packetbuflen = 0;
packetbuf = NULL;
ipv4 = NULL;
icmp = NULL;
tcp = NULL;
udp = NULL;
}
IPProbe::~IPProbe() {
if (packetbuf) {
free(packetbuf);
packetbuf = NULL;
packetbuflen = 0;
}
Reset();
}
int IPProbe::storePacket(u8 *ippacket, u32 len) {
assert(packetbuf == NULL);
af = AF_INET;
packetbuf = (u8 *) safe_malloc(len);
memcpy(packetbuf, ippacket, len);
packetbuflen = len;
ipv4 = (struct ip *) packetbuf;
assert(ipv4->ip_v == 4);
assert(len >= 20);
assert(len == (u32) ntohs(ipv4->ip_len));
if (ipv4->ip_p == IPPROTO_TCP) {
if (len >= (unsigned) ipv4->ip_hl * 4 + 20)
tcp = (struct tcphdr *) ((u8 *) ipv4 + ipv4->ip_hl * 4);
} else if (ipv4->ip_p == IPPROTO_ICMP) {
if (len >= (unsigned) ipv4->ip_hl * 4 + 8)
icmp = (struct icmp *) ((u8 *) ipv4 + ipv4->ip_hl * 4);
} else if (ipv4->ip_p == IPPROTO_UDP) {
if (len >= (unsigned) ipv4->ip_hl * 4 + 8)
udp = (udphdr_bsd *) ((u8 *) ipv4 + ipv4->ip_hl * 4);
}
return 0;
}
ArpProbe::ArpProbe() {
packetbuflen = 0;
packetbuf = NULL;
Reset();
}
void ArpProbe::Reset() {
if (packetbuf)
free(packetbuf);
packetbuflen = 0;
packetbuf = NULL;
ipquery = NULL;
}
ArpProbe::~ArpProbe() {
if (packetbuf) {
free(packetbuf);
packetbuf = NULL;
packetbuflen = 0;
}
Reset();
}
int ArpProbe::storePacket(u8 *arppacket, u32 len) {
assert(packetbuf == NULL);
assert(len == 42);
packetbuf = (u8 *) safe_malloc(len);
memcpy(packetbuf, arppacket, len);
packetbuflen = len;
ipquery = (struct in_addr *) ((u8 *)arppacket + 38);
return 0;
}