Nmap Development mailing list archives
[Exp PATCH] More standardizing on dnet headers
From: Kris Katterjohn <katterjohn () gmail com>
Date: Sun, 21 Jan 2007 19:09:44 -0600
The attached patch (/nmap-exp/kris SVN r4373) does some more dnet header "converting". This one handles the IP stuff. SVN log: ------------------------------------------------------------------------ r4373 | kris | 2007-01-21 18:51:50 -0600 (Sun, 21 Jan 2007) | 1 line More dnet header standardizing. This changes the IP stuff over, and modifies dnet slightly. It removes the netinet/ip.h references from nmap.h and tcpip.h, the struct ip from tcpip.h, and converts struct ip -> struct ip_hdr everywhere. It all compiles and runs fine for me, and hopefully for everyone else too. ------------------------------------------------------------------------ If anybody can test this and leave some feedback, especially Windows users, that'd be awesome. I'm going to merge it into /nmap in a few days if no problems are reported. Thanks a lot, Kris Katterjohn
Index: targets.cc =================================================================== --- targets.cc (revision 4372) +++ targets.cc (revision 4373) @@ -399,7 +399,7 @@ char response[16536]; struct tcp_hdr *tcp; struct udp_hdr *udp; - struct ip *ip, *ip2; + struct ip_hdr *ip, *ip2; u32 hostnum = 0xFFFFFF; /* This ought to crash us if it is used uninitialized */ int tm; int dotimeout = 1; @@ -441,7 +441,7 @@ tmpto = myto; if (pd) { - ip = (struct ip *) readip_pcap(pd, &bytes, to->timeout, &rcvdtime, &linkhdr); + ip = (struct ip_hdr *) readip_pcap(pd, &bytes, to->timeout, &rcvdtime, &linkhdr); if (!ip) gettimeofday(&rcvdtime, NULL); } else { @@ -450,7 +450,7 @@ res = select(sd+1, &fd_r, NULL, &fd_x, &tmpto); if (res == 0) break; bytes = recv(sd, response,sizeof(response), 0 ); - ip = (struct ip *) response; + ip = (struct ip_hdr *) response; gettimeofday(&rcvdtime, NULL); if (bytes > 0) { PacketTrace::trace(PacketTrace::RCVD, (u8 *) response, bytes, &rcvdtime); @@ -528,7 +528,7 @@ continue; } - ip2 = (struct ip *) ((char *)ip + ip->ip_hl * 4 + 8); + ip2 = (struct ip_hdr *) ((char *)ip + ip->ip_hl * 4 + 8); if (bytes < ip->ip_hl * 4 + 8U + ip2->ip_hl * 4 + 8U) { if (o.debugging) error("ICMP (embedded) type %d code %d packet is only %d bytes\n", ping->type, ping->code, bytes); Index: nmap.h =================================================================== --- nmap.h (revision 4372) +++ nmap.h (revision 4373) @@ -159,7 +159,7 @@ #include <sys/param.h> /* Defines MAXHOSTNAMELEN on BSD*/ #endif -/* Linux uses these defines in netinet/ip.h to use the correct struct ip */ +/* Linux uses these defines */ #ifndef __FAVOR_BSD #define __FAVOR_BSD #endif @@ -170,7 +170,10 @@ #define __BSD_SOURCE #endif -/* BSDI needs this to insure the correct struct ip */ +/* BSDI needed this to insure the correct struct ip, but I'm keeping this around + so it doesn't break anything (and there are _IP_VHL references here on my Linux + box) + */ #undef _IP_VHL #include <stdio.h> @@ -214,13 +217,9 @@ #endif #ifndef NETINET_IN_SYSTEM_H /* why does OpenBSD not do this? */ -#include <netinet/in_systm.h> /* defines n_long needed for netinet/ip.h */ +#include <netinet/in_systm.h> /* defines n_long */ #define NETINET_IN_SYSTEM_H #endif -#ifndef NETINET_IP_H /* why does OpenBSD not do this? */ -#include <netinet/ip.h> -#define NETINET_IP_H -#endif // #include <netinet/ip_icmp.h> #if HAVE_ARPA_INET_H Index: osscan2.cc =================================================================== --- osscan2.cc (revision 4372) +++ osscan2.cc (revision 4373) @@ -372,7 +372,7 @@ int TWinReplyNum; /* how many TWin replies are received. */ int TOpsReplyNum; /* how many TOps replies are received. Actually it is the same with TOpsReplyNum. */ - struct ip *icmpEchoReply; /* To store one of the two icmp replies */ + struct ip_hdr *icmpEchoReply; /* To store one of the two icmp replies */ int storedIcmpReply; /* Which one of the two icmp replies is stored? */ struct udpprobeinfo upi; /* info of the udp probe we sent */ @@ -423,7 +423,7 @@ /* Process one response. * If the response is useful, return true. */ - bool processResp(HostOsScanStats *hss, struct ip *ip, unsigned int len, struct timeval *rcvdtime); + bool processResp(HostOsScanStats *hss, struct ip_hdr *ip, unsigned int len, struct timeval *rcvdtime); /* Make up the fingerprint. */ void makeFP(HostOsScanStats *hss); @@ -465,13 +465,13 @@ void sendTUdpProbe(HostOsScanStats *hss, int probeNo); void sendTIcmpProbe(HostOsScanStats *hss, int probeNo); /* Response process functions. */ - bool processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyNo); + bool processTSeqResp(HostOsScanStats *hss, struct ip_hdr *ip, int replyNo); bool processTOpsResp(HostOsScanStats *hss, struct tcp_hdr *tcp, int replyNo); bool processTWinResp(HostOsScanStats *hss, struct tcp_hdr *tcp, int replyNo); - bool processTEcnResp(HostOsScanStats *hss, struct ip *ip); - bool processT1_7Resp(HostOsScanStats *hss, struct ip *ip, int replyNo); - bool processTUdpResp(HostOsScanStats *hss, struct ip *ip); - bool processTIcmpResp(HostOsScanStats *hss, struct ip *ip, int replyNo); + bool processTEcnResp(HostOsScanStats *hss, struct ip_hdr *ip); + bool processT1_7Resp(HostOsScanStats *hss, struct ip_hdr *ip, int replyNo); + bool processTUdpResp(HostOsScanStats *hss, struct ip_hdr *ip); + bool processTIcmpResp(HostOsScanStats *hss, struct ip_hdr *ip, int replyNo); void makeTSeqFP(HostOsScanStats *hss); void makeTOpsFP(HostOsScanStats *hss); @@ -1407,8 +1407,8 @@ hss->closedUDPPort); } -bool HostOsScan::processResp(HostOsScanStats *hss, struct ip *ip, unsigned int len, struct timeval *rcvdtime) { - struct ip *ip2; +bool HostOsScan::processResp(HostOsScanStats *hss, struct ip_hdr *ip, unsigned int len, struct timeval *rcvdtime) { + struct ip_hdr *ip2; struct tcp_hdr *tcp; struct icmp *icmp; int testno; @@ -1500,7 +1500,7 @@ if (icmp->icmp_type == 3 && icmp->icmp_code == 3) { len -= 8; /* icmp destination unreachable header len. */ if(len < 28) return false; /* must larger than an ip and an udp header length */ - ip2 = (struct ip*)((char *)icmp + 8); + ip2 = (struct ip_hdr*)((char *)icmp + 8); len -= 4 * ip2->ip_hl; if(len < 8) return false; @@ -1970,7 +1970,7 @@ hss->FP_TWin->name = "WIN"; } -bool HostOsScan::processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyNo) { +bool HostOsScan::processTSeqResp(HostOsScanStats *hss, struct ip_hdr *ip, int replyNo) { assert(replyNo>=0 && replyNo<NUM_SEQ_SAMPLES); struct tcp_hdr *tcp; @@ -2110,7 +2110,7 @@ return true; } -bool HostOsScan::processTEcnResp(HostOsScanStats *hss, struct ip *ip) { +bool HostOsScan::processTEcnResp(HostOsScanStats *hss, struct ip_hdr *ip) { struct AVal *AVs; int i; char *p; @@ -2203,7 +2203,7 @@ return true; } -bool HostOsScan::processT1_7Resp(HostOsScanStats *hss, struct ip *ip, int replyNo) { +bool HostOsScan::processT1_7Resp(HostOsScanStats *hss, struct ip_hdr *ip, int replyNo) { assert(replyNo>=0 && replyNo<7); @@ -2364,15 +2364,14 @@ return true; } -bool HostOsScan::processTUdpResp(HostOsScanStats *hss, struct ip *ip) { +bool HostOsScan::processTUdpResp(HostOsScanStats *hss, struct ip_hdr *ip) { assert(hss); assert(ip); struct icmp *icmp; - struct ip *ip2; + struct ip_hdr *ip2; int numtests; unsigned short checksum; - unsigned short *checksumptr; struct udp_hdr *udp; struct AVal *AVs; int i; @@ -2394,7 +2393,7 @@ /* Make sure this is icmp port unreachable. */ assert(icmp->icmp_type == 3 && icmp->icmp_code == 3); - ip2 = (struct ip*)((char *)icmp + 8); + ip2 = (struct ip_hdr*)((char *)icmp + 8); udp = (struct udp_hdr *)((char *)ip2 + 4 * ip->ip_hl); /* The ports should match. */ @@ -2481,21 +2480,19 @@ /* Let us see if the IP checksum we got back computes */ AVs[current_testno].attribute = "RIPCK"; - /* Thanks to some machines not having struct ip member ip_sum we - have to go with this BS */ - checksumptr = (unsigned short *) ((char *) ip2 + 10); - checksum = *checksumptr; + checksum = ip2->ip_sum; + if (checksum == 0) strcpy(AVs[current_testno].value, "Z"); else { - *checksumptr = 0; + ip2->ip_sum = 0; if (in_cksum((unsigned short *)ip2, 20) == checksum) { strcpy(AVs[current_testno].value, "G"); /* The "expected" good value */ } else { strcpy(AVs[current_testno].value, "I"); /* They fucked it up */ } - *checksumptr = checksum; + ip2->ip_sum = checksum; } current_testno++; @@ -2544,12 +2541,12 @@ return true; } -bool HostOsScan::processTIcmpResp(HostOsScanStats *hss, struct ip *ip, int replyNo) { +bool HostOsScan::processTIcmpResp(HostOsScanStats *hss, struct ip_hdr *ip, int replyNo) { assert(replyNo==0 || replyNo==1); int numtests = 7; struct AVal *AVs; - struct ip *ip1, *ip2; + struct ip_hdr *ip1, *ip2; struct icmp *icmp1, *icmp2; unsigned short value1, value2; int i; @@ -2559,7 +2556,7 @@ if (hss->icmpEchoReply == NULL) { /* This is the first icmp reply we get, store it and return. */ - hss->icmpEchoReply = (struct ip *) safe_malloc(ntohs(ip->ip_len)); + hss->icmpEchoReply = (struct ip_hdr *) safe_malloc(ntohs(ip->ip_len)); memcpy(hss->icmpEchoReply, ip, ntohs(ip->ip_len)); hss->storedIcmpReply = replyNo; return true; @@ -3001,8 +2998,8 @@ static u8 patternbyte = 0x43; /* character 'C' */ static u16 id = 0x1042; u8 packet[328]; /* 20 IP hdr + 8 UDP hdr + 300 data */ - struct ip *ip = (struct ip *) packet; - struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); + struct ip_hdr *ip = (struct ip_hdr *) packet; + struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip_hdr)); struct in_addr *source; int datalen = 300; unsigned char *data = packet + 28; @@ -3030,7 +3027,7 @@ for(decoy=0; decoy < o.numdecoys; decoy++) { source = &o.decoys[decoy]; - memset((char *) packet, 0, sizeof(struct ip) + sizeof(struct udp_hdr)); + memset((char *) packet, 0, sizeof(struct ip_hdr) + sizeof(struct udp_hdr)); udp->uh_sport = htons(sport); udp->uh_dport = htons(dport); @@ -3048,17 +3045,15 @@ /* Now for the ip header */ ip->ip_v = 4; ip->ip_hl = 5; - ip->ip_len = htons(sizeof(struct ip) + sizeof(struct udp_hdr) + datalen); + ip->ip_len = htons(sizeof(struct ip_hdr) + sizeof(struct udp_hdr) + datalen); ip->ip_id = id; ip->ip_ttl = myttl; ip->ip_p = IPPROTO_UDP; ip->ip_src.s_addr = source->s_addr; ip->ip_dst.s_addr= victim->s_addr; - upi.ipck = in_cksum((unsigned short *)ip, sizeof(struct ip)); -#if HAVE_IP_IP_SUM + upi.ipck = in_cksum((unsigned short *)ip, sizeof(struct ip_hdr)); ip->ip_sum = upi.ipck; -#endif /* OK, now if this is the real she-bang (ie not a decoy) then we stick all the inph0 in our upi */ @@ -3292,7 +3287,7 @@ long to_usec; int timeToSleep = 0; - struct ip *ip = NULL; + struct ip_hdr *ip = NULL; struct link_header linkhdr; struct sockaddr_in sin; unsigned int bytes; @@ -3388,7 +3383,7 @@ if(o.debugging > 2) printf("pcap wait time is %ld.\n", to_usec); - ip = (struct ip*) readip_pcap(HOS->pd, &bytes, to_usec, &rcvdtime, &linkhdr); + ip = (struct ip_hdr*) readip_pcap(HOS->pd, &bytes, to_usec, &rcvdtime, &linkhdr); gettimeofday(&now, NULL); @@ -3456,7 +3451,7 @@ long to_usec; int timeToSleep = 0; - struct ip *ip = NULL; + struct ip_hdr *ip = NULL; struct link_header linkhdr; struct sockaddr_in sin; unsigned int bytes; @@ -3557,7 +3552,7 @@ if(o.debugging > 2) printf("pcap wait time is %ld.\n", to_usec); - ip = (struct ip*) readip_pcap(HOS->pd, &bytes, to_usec, &rcvdtime, &linkhdr); + ip = (struct ip_hdr*) readip_pcap(HOS->pd, &bytes, to_usec, &rcvdtime, &linkhdr); gettimeofday(&now, NULL); Index: tcpip.cc =================================================================== --- tcpip.cc (revision 4372) +++ tcpip.cc (revision 4373) @@ -406,7 +406,7 @@ returned buffer is NUL-terminated */ static const char *ippackethdrinfo(const u8 *packet, u32 len) { static char protoinfo[512]; - struct ip *ip = (struct ip *) packet; + struct ip_hdr *ip = (struct ip_hdr *) packet; struct tcp_hdr *tcp; struct udp_hdr *udp; char ipinfo[512]; @@ -418,7 +418,7 @@ if (ip->ip_v != 4) return "BOGUS! IP Version in packet is not 4"; - if (len < sizeof(struct ip)) + if (len < sizeof(struct ip_hdr)) return "BOGUS! Packet too short."; saddr.s_addr = ip->ip_src.s_addr; @@ -437,7 +437,7 @@ snprintf(ipinfo, sizeof(ipinfo), "ttl=%d id=%d iplen=%d%s %s%s%s", ip->ip_ttl, ntohs(ip->ip_id), ntohs(ip->ip_len), fragnfo, ip->ip_hl==5?"":"ipopts={", - ip->ip_hl==5?"":print_ip_options((u8*)ip + sizeof(struct ip), MIN((ip->ip_hl-5)*4,len-sizeof(struct ip))), + ip->ip_hl==5?"":print_ip_options((u8*)ip + sizeof(struct ip_hdr), MIN((unsigned)(ip->ip_hl-5)*4,len-sizeof(struct ip_hdr))), ip->ip_hl==5?"":"}"); if (ip->ip_p == IPPROTO_TCP) { @@ -526,7 +526,7 @@ } else if (ip->ip_p == IPPROTO_UDP && frag_off) { snprintf(protoinfo, sizeof(protoinfo), "UDP %s:?? > %s:?? fragment %s (incomplete)", srchost, dsthost, ipinfo); } else if (ip->ip_p == IPPROTO_UDP) { - udp = (struct udp_hdr *) (packet + sizeof(struct ip)); + udp = (struct udp_hdr *) (packet + sizeof(struct ip_hdr)); snprintf(protoinfo, sizeof(protoinfo), "UDP %s:%d > %s:%d %s", srchost, ntohs(udp->uh_sport), dsthost, ntohs(udp->uh_dport), @@ -1041,7 +1041,7 @@ // fill ip header. no error check. // This function is also changing what's needed from host to network order. static inline int fill_ip_raw( - struct ip *ip, int packetlen, u8* ipopt, int ipoptlen, + struct ip_hdr *ip, int packetlen, u8* ipopt, int ipoptlen, int ip_tos, int ip_id, int ip_off, int ip_ttl, int ip_p, const struct in_addr *ip_src, const struct in_addr *ip_dst) { @@ -1057,11 +1057,11 @@ ip->ip_dst.s_addr = ip_dst->s_addr; if (ipoptlen) - memcpy((u8*)ip + sizeof(struct ip), ipopt, ipoptlen); + memcpy((u8*)ip + sizeof(struct ip_hdr), ipopt, ipoptlen); // ip options source routing hack: if(ipoptlen && o.ipopt_firsthop && o.ipopt_lasthop) { - u8* ipo = (u8*)ip + sizeof(struct ip); + u8* ipo = (u8*)ip + sizeof(struct ip_hdr); struct in_addr *newdst = (struct in_addr *) &ipo[o.ipopt_firsthop]; struct in_addr *olddst = (struct in_addr *) &ipo[o.ipopt_lasthop]; // our destination is somewhere else :) @@ -1072,11 +1072,9 @@ } - #if HAVE_IP_IP_SUM ip->ip_sum = 0; - ip->ip_sum = in_cksum((unsigned short *)ip, sizeof(struct ip) + ipoptlen); - #endif - return(sizeof(struct ip) + ipoptlen); + ip->ip_sum = in_cksum((unsigned short *)ip, sizeof(struct ip_hdr) + ipoptlen); + return(sizeof(struct ip_hdr) + ipoptlen); } @@ -1120,11 +1118,11 @@ u8 *tcpopt, int tcpoptlen, char *data, u16 datalen, u32 *outpacketlen) { -int packetlen = sizeof(struct ip) + ipoptlen + +int packetlen = sizeof(struct ip_hdr) + ipoptlen + sizeof(struct tcp_hdr) + tcpoptlen + datalen; u8 *packet = (u8 *) safe_malloc(packetlen); -struct ip *ip = (struct ip *) packet; -struct tcp_hdr *tcp = (struct tcp_hdr *) ((u8*)ip + sizeof(struct ip) + ipoptlen); +struct ip_hdr *ip = (struct ip_hdr *) packet; +struct tcp_hdr *tcp = (struct tcp_hdr *) ((u8*)ip + sizeof(struct ip_hdr) + ipoptlen); static int myttl = 0; assert(victim); @@ -1230,8 +1228,8 @@ int send_frag_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetlen, unsigned int mtu) { - struct ip *ip = (struct ip *) packet; - int headerlen = ip->ip_hl * 4; // better than sizeof(struct ip) + struct ip_hdr *ip = (struct ip_hdr *) packet; + int headerlen = ip->ip_hl * 4; // better than sizeof(struct ip_hdr) unsigned int datalen = packetlen - headerlen; int fdatalen = 0, res = 0; @@ -1246,7 +1244,7 @@ u8 *fpacket = (u8 *) safe_malloc(headerlen + mtu); memcpy(fpacket, packet, headerlen + mtu); - ip = (struct ip *) fpacket; + ip = (struct ip_hdr *) fpacket; // create fragments and send them for (int fragment = 1; fragment * mtu < datalen + mtu; fragment++) { @@ -1255,9 +1253,7 @@ ip->ip_off = htons((fragment-1) * mtu / 8); if ((fragment-1) * mtu + fdatalen < datalen) ip->ip_off |= htons(IP_MF); -#if HAVE_IP_IP_SUM ip->ip_sum = in_cksum((unsigned short *)ip, headerlen); -#endif if (fragment > 1) // copy data payload memcpy(fpacket + headerlen, packet + headerlen + (fragment - 1) * mtu, fdatalen); res = send_ip_packet(sd, eth, fpacket, headerlen + fdatalen); @@ -1317,7 +1313,7 @@ int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetlen) { struct sockaddr_in sock; int res; - struct ip *ip = (struct ip *) packet; + struct ip_hdr *ip = (struct ip_hdr *) packet; struct tcp_hdr *tcp = NULL; struct udp_hdr *udp; u8 *eth_frame = NULL; @@ -1512,9 +1508,9 @@ of a TCP packet*/ int readtcppacket(const u8 *packet, int readdata) { -struct ip *ip = (struct ip *) packet; -struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip)); -const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct tcp_hdr); +struct ip_hdr *ip = (struct ip_hdr *) packet; +struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip_hdr)); +const unsigned char *data = packet + sizeof(struct ip_hdr) + sizeof(struct tcp_hdr); int tot_len; struct in_addr bullshit, bullshit2; char sourcehost[16]; @@ -1572,9 +1568,9 @@ of a UDP packet*/ int readudppacket(const u8 *packet, int readdata) { -struct ip *ip = (struct ip *) packet; -struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); -const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct udp_hdr); +struct ip_hdr *ip = (struct ip_hdr *) packet; +struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip_hdr)); +const unsigned char *data = packet + sizeof(struct ip_hdr) + sizeof(struct udp_hdr); int tot_len; struct in_addr bullshit, bullshit2; char sourcehost[16]; @@ -1644,10 +1640,10 @@ u16 sport, u16 dport, char *data, u16 datalen, u32 *outpacketlen) { - int packetlen = sizeof(struct ip) + ipoptlen + sizeof(struct udp_hdr) + datalen; + int packetlen = sizeof(struct ip_hdr) + ipoptlen + sizeof(struct udp_hdr) + datalen; u8 *packet = (u8 *) safe_malloc(packetlen); - struct ip *ip = (struct ip *) packet; - struct udp_hdr *udp = (struct udp_hdr *) ((u8*)ip + sizeof(struct ip) + ipoptlen); + struct ip_hdr *ip = (struct ip_hdr *) packet; + struct udp_hdr *udp = (struct udp_hdr *) ((u8*)ip + sizeof(struct ip_hdr) + ipoptlen); static int myttl = 0; /* check that required fields are there and not too silly */ @@ -1724,9 +1720,9 @@ char *data, u16 datalen, u32 *outpacketlen) { -int packetlen = sizeof(struct ip) + ipoptlen + datalen; +int packetlen = sizeof(struct ip_hdr) + ipoptlen + datalen; u8 *packet = (u8 *) safe_malloc(packetlen); -struct ip *ip = (struct ip *) packet; +struct ip_hdr *ip = (struct ip_hdr *) packet; static int myttl = 0; /* check that required fields are there and not too silly */ @@ -1747,7 +1743,7 @@ /* We should probably copy the data over too */ if (data) - memcpy((u8*)ip + sizeof(struct ip) + ipoptlen, data, datalen); + memcpy((u8*)ip + sizeof(struct ip_hdr) + ipoptlen, data, datalen); *outpacketlen = packetlen; return packet; @@ -2234,7 +2230,7 @@ */ int setTargetMACIfAvailable(Target *target, struct link_header *linkhdr, - struct ip *ip, int overwrite) { + struct ip_hdr *ip, int overwrite) { if (!linkhdr || !target || !ip) return 1; Index: tcpip.h =================================================================== --- tcpip.h (revision 4372) +++ tcpip.h (revision 4373) @@ -142,7 +142,7 @@ #include <sys/param.h> /* Defines MAXHOSTNAMELEN on BSD*/ #endif -/* Linux uses these defines in netinet/ip.h to use the correct struct ip */ +/* Linux uses these defines */ #ifndef __FAVOR_BSD #define __FAVOR_BSD 1 #endif @@ -152,7 +152,10 @@ #ifndef __USE_BSD #define __USE_BSD 1 #endif -/* BSDI needs this to insure the correct struct ip */ +/* BSDI needed this to insure the correct struct ip, but I'm keeping this around + so it doesn't break anything (and there are _IP_VHL references here on my Linux + box) + */ #undef _IP_VHL #include <stdio.h> @@ -175,13 +178,9 @@ #include <arpa/inet.h> #ifndef NETINET_IN_SYSTEM_H /* why the HELL does OpenBSD not do this? */ -#include <netinet/in_systm.h> /* defines n_long needed for netinet/ip.h */ +#include <netinet/in_systm.h> /* defines n_long */ #define NETINET_IN_SYSTEM_H #endif -#ifndef NETINET_IP_H /* why the HELL does OpenBSD not do this? */ -#include <netinet/ip.h> -#define NETINET_IP_H -#endif #if HAVE_UNISTD_H #include <unistd.h> #endif @@ -325,39 +324,6 @@ char devname[16]; // Only needed if ethsd is NULL. }; -#ifndef HAVE_STRUCT_IP -#define HAVE_STRUCT_IP - -/* From Linux glibc, which apparently borrowed it from - BSD code. Slightly modified for portability --fyodor () insecure org */ -/* - * Structure of an internet header, naked of options. - */ -struct ip - { -#if WORDS_BIGENDIAN - u_int8_t ip_v:4; /* version */ - u_int8_t ip_hl:4; /* header length */ -#else - u_int8_t ip_hl:4; /* header length */ - u_int8_t ip_v:4; /* version */ -#endif - u_int8_t ip_tos; /* type of service */ - u_short ip_len; /* total length */ - u_short ip_id; /* identification */ - u_short ip_off; /* fragment offset field */ -#define IP_RF 0x8000 /* reserved fragment flag */ -#define IP_DF 0x4000 /* dont fragment flag */ -#define IP_MF 0x2000 /* more fragments flag */ -#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ - u_int8_t ip_ttl; /* time to live */ - u_int8_t ip_p; /* protocol */ - u_short ip_sum; /* checksum */ - struct in_addr ip_src, ip_dst; /* source and dest address */ - }; - -#endif /* HAVE_STRUCT_IP */ - #ifndef HAVE_STRUCT_ICMP #define HAVE_STRUCT_ICMP /* From Linux /usr/include/netinet/ip_icmp.h GLIBC */ @@ -418,7 +384,7 @@ } id_ts; struct { - struct ip idi_ip; + struct ip_hdr idi_ip; /* options and then 64 bits of data */ } id_ip; struct icmp_ra_addr id_radv; @@ -680,7 +646,7 @@ */ int setTargetMACIfAvailable(Target *target, struct link_header *linkhdr, - struct ip *ip, int overwrite); + struct ip_hdr *ip, int overwrite); /* This function ensures that the next hop MAC address for a target is filled in. This address is the target's own MAC if it is directly Index: idle_scan.cc =================================================================== --- idle_scan.cc (revision 4372) +++ idle_scan.cc (revision 4373) @@ -167,7 +167,7 @@ unsigned int bytes; int timedout = 0; int base_port; - struct ip *ip; + struct ip_hdr *ip; struct tcp_hdr *tcp; static u32 seq_base = 0; static u32 ack = 0; @@ -204,7 +204,7 @@ to_usec = proxy->host.to.timeout - TIMEVAL_SUBTRACT(tv_end, tv_sent[tries-1]); if (to_usec < 0) to_usec = 0; // Final no-block poll - ip = (struct ip *) readip_pcap(proxy->pd, &bytes, to_usec, &rcvdtime, NULL); + ip = (struct ip_hdr *) readip_pcap(proxy->pd, &bytes, to_usec, &rcvdtime, NULL); gettimeofday(&tv_end, NULL); if (ip) { if (bytes < ( 4 * ip->ip_hl) + 14U) @@ -300,7 +300,7 @@ u32 ack = 0; struct timeval probe_send_times[NUM_IPID_PROBES], tmptv, rcvdtime; u16 lastipid = 0; - struct ip *ip; + struct ip_hdr *ip; struct tcp_hdr *tcp; int distance; u16 ipids[NUM_IPID_PROBES]; @@ -433,7 +433,7 @@ while(probes_returned < probes_sent && !timedout) { to_usec = (probes_sent == NUM_IPID_PROBES)? hardtimeout : 1000; - ip = (struct ip *) readip_pcap(proxy->pd, &bytes, to_usec, &rcvdtime, NULL); + ip = (struct ip_hdr *) readip_pcap(proxy->pd, &bytes, to_usec, &rcvdtime, NULL); gettimeofday(&tmptv, NULL); Index: osscan.cc =================================================================== --- osscan.cc (revision 4372) +++ osscan.cc (revision 4373) @@ -131,8 +131,8 @@ static u8 patternbyte = 0; static u16 id = 0; u8 packet[328]; /* 20 IP hdr + 8 UDP hdr + 300 data */ -struct ip *ip = (struct ip *) packet; -struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); +struct ip_hdr *ip = (struct ip_hdr *) packet; +struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip_hdr)); struct in_addr *source; int datalen = 300; unsigned char *data = packet + 28; @@ -156,7 +156,7 @@ for(decoy=0; decoy < o.numdecoys; decoy++) { source = &o.decoys[decoy]; - memset((char *) packet, 0, sizeof(struct ip) + sizeof(struct udp_hdr)); + memset((char *) packet, 0, sizeof(struct ip_hdr) + sizeof(struct udp_hdr)); udp->uh_sport = htons(sport); udp->uh_dport = htons(dport); @@ -177,17 +177,15 @@ /* Now for the ip header */ ip->ip_v = 4; ip->ip_hl = 5; - ip->ip_len = htons(sizeof(struct ip) + sizeof(struct udp_hdr) + datalen); + ip->ip_len = htons(sizeof(struct ip_hdr) + sizeof(struct udp_hdr) + datalen); ip->ip_id = id; ip->ip_ttl = myttl; ip->ip_p = IPPROTO_UDP; ip->ip_src.s_addr = source->s_addr; ip->ip_dst.s_addr= victim->s_addr; - upi.ipck = in_cksum((unsigned short *)ip, sizeof(struct ip)); -#if HAVE_IP_IP_SUM + upi.ipck = in_cksum((unsigned short *)ip, sizeof(struct ip_hdr)); ip->ip_sum = upi.ipck; -#endif /* OK, now if this is the real she-bang (ie not a decoy) then we stick all the inph0 in our upi */ @@ -212,7 +210,7 @@ return &upi; } -static struct AVal *fingerprint_iptcppacket(struct ip *ip, int mss, u32 syn) { +static struct AVal *fingerprint_iptcppacket(struct ip_hdr *ip, int mss, u32 syn) { struct AVal *AVs; int length; int opcode; @@ -317,12 +315,11 @@ } -static struct AVal *fingerprint_portunreach(struct ip *ip, struct udpprobeinfo *upi) { +static struct AVal *fingerprint_portunreach(struct ip_hdr *ip, struct udpprobeinfo *upi) { struct icmp *icmp; - struct ip *ip2; + struct ip_hdr *ip2; int numtests = 10; unsigned short checksum; - unsigned short *checksumptr; struct udp_hdr *udp; struct AVal *AVs; int i; @@ -343,7 +340,7 @@ if (icmp->icmp_type != 3 || icmp->icmp_code != 3) return NULL; /* Not a port unreachable */ - ip2 = (struct ip*) ((char *)icmp + 8); + ip2 = (struct ip_hdr*) ((char *)icmp + 8); udp = (struct udp_hdr *) ((char *)ip2 + 20); /* The ports better match as well ... */ @@ -412,21 +409,19 @@ /* Let us see if the IP checksum we got back computes */ AVs[current_testno].attribute = "RIPCK"; - /* Thanks to some machines not having struct ip member ip_sum we - have to go with this BS */ - checksumptr = (unsigned short *) ((char *) ip2 + 10); - checksum = *checksumptr; + checksum = ip2->ip_sum; + if (checksum == 0) strcpy(AVs[current_testno].value, "0"); else { - *checksumptr = 0; + ip2->ip_sum = 0; if (in_cksum((unsigned short *)ip2, 20) == checksum) { strcpy(AVs[current_testno].value, "E"); /* The "expected" value */ } else { strcpy(AVs[current_testno].value, "F"); /* They fucked it up */ } - *checksumptr = checksum; + ip2->ip_sum = checksum; } current_testno++; @@ -473,7 +468,7 @@ u16 lastipid=0; /* For catching duplicate packets */ int last; u32 timestamp = 0; /* TCP timestamp we receive back */ - struct ip *ip; + struct ip_hdr *ip; struct tcp_hdr *tcp; struct icmp *icmp; struct timeval t1,t2; @@ -664,7 +659,7 @@ if (target->timedOut(&t1)) goto osscan_timedout; - while(( ip = (struct ip*) readip_pcap(pd, &bytes, oshardtimeout, NULL, &linkhdr)) && !timeout) { + while(( ip = (struct ip_hdr*) readip_pcap(pd, &bytes, oshardtimeout, NULL, &linkhdr)) && !timeout) { gettimeofday(&t2, NULL); if (TIMEVAL_SUBTRACT(t2,t1) > oshardtimeout) { timeout = 1; @@ -747,8 +742,8 @@ while(si->responses < seq_packets_sent && !timeout) { if (seq_packets_sent == NUM_SEQ_SAMPLES) - ip = (struct ip*) readip_pcap(pd, &bytes, oshardtimeout, NULL, &linkhdr); - else ip = (struct ip*) readip_pcap(pd, &bytes, 10, NULL, &linkhdr); + ip = (struct ip_hdr*) readip_pcap(pd, &bytes, oshardtimeout, NULL, &linkhdr); + else ip = (struct ip_hdr*) readip_pcap(pd, &bytes, 10, NULL, &linkhdr); gettimeofday(&t2, NULL); /* error("DEBUG: got a response (len=%d):\n", bytes); */ Index: scan_engine.cc =================================================================== --- scan_engine.cc (revision 4372) +++ scan_engine.cc (revision 4373) @@ -670,7 +670,7 @@ because pspec.type is ambiguous with just the ippacket (e.g. a tcp packet could be PS_PROTO or PS_TCP). */ void UltraProbe::setIP(u8 *ippacket, u32 iplen, const probespec *pspec) { - struct ip *ipv4 = (struct ip *) ippacket; + struct ip_hdr *ipv4 = (struct ip_hdr *) ippacket; struct tcp_hdr *tcp = NULL; struct udp_hdr *udp = NULL; @@ -2800,7 +2800,7 @@ bool goodone = false; bool timedout = false; struct timeval rcvdtime; - struct ip *ip = NULL, *ip2 = NULL; + struct ip_hdr *ip = NULL, *ip2 = NULL; struct tcp_hdr *tcp = NULL; struct icmp *icmp = NULL; struct udp_hdr *udp = NULL; @@ -2827,7 +2827,7 @@ do { to_usec = TIMEVAL_SUBTRACT(*stime, USI->now); if (to_usec < 2000) to_usec = 2000; - ip = (struct ip *) readip_pcap(USI->pd, &bytes, to_usec, &rcvdtime, &linkhdr); + ip = (struct ip_hdr *) readip_pcap(USI->pd, &bytes, to_usec, &rcvdtime, &linkhdr); gettimeofday(&USI->now, NULL); if (!ip && TIMEVAL_SUBTRACT(*stime, USI->now) < 0) { timedout = true; @@ -2982,7 +2982,7 @@ if (icmp->icmp_type != 3) continue; - ip2 = (struct ip *) (((char *) ip) + 4 * ip->ip_hl + 8); + ip2 = (struct ip_hdr *) (((char *) ip) + 4 * ip->ip_hl + 8); requiredbytes = /* IPlen*/ 4 * ip->ip_hl + /* ICMPLen */ 8 + /* IP2 Len */ 4 * ip2->ip_hl; @@ -3053,7 +3053,7 @@ error("Unexpected ICMP type/code 3/%d unreachable packet:", icmp->icmp_code); hdump((unsigned char *)icmp, ntohs(ip->ip_len) - - sizeof(struct ip)); + sizeof(struct ip_hdr)); break; } switch(icmp->icmp_code) { @@ -3085,7 +3085,7 @@ error("Unexpected ICMP type/code 3/%d unreachable packet:", icmp->icmp_code); hdump((unsigned char *)icmp, ntohs(ip->ip_len) - - sizeof(struct ip)); + sizeof(struct ip_hdr)); break; } if (newstate == PORT_UNKNOWN) break; Index: libdnet-stripped/include/dnet/ip.h =================================================================== --- libdnet-stripped/include/dnet/ip.h (revision 4372) +++ libdnet-stripped/include/dnet/ip.h (revision 4373) @@ -51,8 +51,8 @@ uint8_t ip_ttl; /* time to live */ uint8_t ip_p; /* protocol */ uint16_t ip_sum; /* checksum */ - ip_addr_t ip_src; /* source address */ - ip_addr_t ip_dst; /* destination address */ + struct in_addr ip_src; /* source address */ + struct in_addr ip_dst; /* destination address */ }; /* Index: libdnet-stripped/src/ip.c =================================================================== --- libdnet-stripped/src/ip.c (revision 4372) +++ libdnet-stripped/src/ip.c (revision 4373) @@ -72,7 +72,7 @@ sin.sin_len = sizeof(sin); #endif sin.sin_family = AF_INET; - sin.sin_addr.s_addr = ip->ip_dst; + sin.sin_addr = ip->ip_dst; #ifdef HAVE_RAWIP_HOST_OFFLEN ip->ip_len = ntohs(ip->ip_len); Index: libdnet-stripped/src/ip-win32.c =================================================================== --- libdnet-stripped/src/ip-win32.c (revision 4372) +++ libdnet-stripped/src/ip-win32.c (revision 4373) @@ -58,7 +58,7 @@ { struct ip_hdr *hdr = (struct ip_hdr *)buf; - ip->sin.sin_addr.s_addr = hdr->ip_src; + ip->sin.sin_addr = hdr->ip_src; if ((len = sendto(ip->fd, (const char *)buf, (int) len, 0, (struct sockaddr *)&ip->sin, sizeof(ip->sin))) != SOCKET_ERROR) Index: libdnet-stripped/src/ip-cooked.c =================================================================== --- libdnet-stripped/src/ip-cooked.c (revision 4372) +++ libdnet-stripped/src/ip-cooked.c (revision 4373) @@ -153,13 +153,13 @@ iph = (struct ip_hdr *)buf; - if ((ipi = _lookup_ip_intf(ip, iph->ip_dst)) == NULL) { + if ((ipi = _lookup_ip_intf(ip, (ip_addr_t) iph->ip_dst.s_addr)) == NULL) { errno = EHOSTUNREACH; return (-1); } arpent.arp_pa.addr_type = ADDR_TYPE_IP; arpent.arp_pa.addr_bits = IP_ADDR_BITS; - arpent.arp_pa.addr_ip = iph->ip_dst; + arpent.arp_pa.addr_ip = (ip_addr_t) iph->ip_dst.s_addr; memcpy(&rtent.route_dst, &arpent.arp_pa, sizeof(rtent.route_dst)); for (i = 0, usec = 10; i < 3; i++, usec *= 100) { Index: libdnet-stripped/NMAP_MODIFICATIONS =================================================================== --- libdnet-stripped/NMAP_MODIFICATIONS (revision 4372) +++ libdnet-stripped/NMAP_MODIFICATIONS (revision 4373) @@ -326,3 +326,73 @@ if (len < 46) return (NULL); +o I (Kris) changed struct ip_hdr to use struct in_addr for ip_src and ip_dst + instead of the ip_addr_t. This was done because we're consolidating headers + and using dnet for the packet header structs. This of course lead to a few + more changes in a few places of dnet. + +Index: include/dnet/ip.h +=================================================================== +--- include/dnet/ip.h (revision 4372) ++++ include/dnet/ip.h (working copy) +@@ -51,8 +51,8 @@ + uint8_t ip_ttl; /* time to live */ + uint8_t ip_p; /* protocol */ + uint16_t ip_sum; /* checksum */ +- ip_addr_t ip_src; /* source address */ +- ip_addr_t ip_dst; /* destination address */ ++ struct in_addr ip_src; /* source address */ ++ struct in_addr ip_dst; /* destination address */ + }; + + /* + +Index: src/ip.c +=================================================================== +--- src/ip.c (revision 4372) ++++ src/ip.c (working copy) +@@ -72,7 +72,7 @@ + sin.sin_len = sizeof(sin); + #endif + sin.sin_family = AF_INET; +- sin.sin_addr.s_addr = ip->ip_dst; ++ sin.sin_addr = ip->ip_dst; + + #ifdef HAVE_RAWIP_HOST_OFFLEN + ip->ip_len = ntohs(ip->ip_len); + +Index: src/ip-win32.c +=================================================================== +--- src/ip-win32.c (revision 4372) ++++ src/ip-win32.c (working copy) +@@ -58,7 +58,7 @@ + { + struct ip_hdr *hdr = (struct ip_hdr *)buf; + +- ip->sin.sin_addr.s_addr = hdr->ip_src; ++ ip->sin.sin_addr = hdr->ip_src; + + if ((len = sendto(ip->fd, (const char *)buf, (int) len, 0, + (struct sockaddr *)&ip->sin, sizeof(ip->sin))) != SOCKET_ERROR) + +Index: src/ip-cooked.c +=================================================================== +--- src/ip-cooked.c (revision 4372) ++++ src/ip-cooked.c (working copy) +@@ -153,13 +153,13 @@ + + iph = (struct ip_hdr *)buf; + +- if ((ipi = _lookup_ip_intf(ip, iph->ip_dst)) == NULL) { ++ if ((ipi = _lookup_ip_intf(ip, (ip_addr_t) iph->ip_dst.s_addr)) == NULL) { + errno = EHOSTUNREACH; + return (-1); + } + arpent.arp_pa.addr_type = ADDR_TYPE_IP; + arpent.arp_pa.addr_bits = IP_ADDR_BITS; +- arpent.arp_pa.addr_ip = iph->ip_dst; ++ arpent.arp_pa.addr_ip = (ip_addr_t) iph->ip_dst.s_addr; + memcpy(&rtent.route_dst, &arpent.arp_pa, sizeof(rtent.route_dst)); + + for (i = 0, usec = 10; i < 3; i++, usec *= 100) { +
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [Exp PATCH] Start standardizing on dnet headers Kris Katterjohn (Jan 21)
- [Exp PATCH] More standardizing on dnet headers Kris Katterjohn (Jan 21)
- [PATCHed] Using dnet headers for TCP and UDP Kris Katterjohn (Jan 22)
- Re: [PATCHed] Using dnet headers for TCP and UDP Peter O'Gorman (Jan 26)
- Re: [PATCHed] Using dnet headers for TCP and UDP Kris Katterjohn (Jan 24)
- Re: [PATCHed] Using dnet headers for TCP and UDP Kris Katterjohn (Jan 31)
- [PATCHed] Using dnet headers for TCP and UDP Kris Katterjohn (Jan 22)
- [Exp PATCH] More standardizing on dnet headers Kris Katterjohn (Jan 21)