
Nmap Development mailing list archives
[Exp PATCH] Start standardizing on dnet headers
From: Kris Katterjohn <katterjohn () gmail com>
Date: Sun, 21 Jan 2007 12:03:36 -0600
The attached patch (/nmap-exp/kris SVN r4372) starts to standardize on the libdnet headers to remove some duplication. As usual, the SVN log all ready explains: ------------------------------------------------------------------------ r4372 | kris | 2007-01-21 11:57:14 -0600 (Sun, 21 Jan 2007) | 1 line Start standardizing on dnet headers. This only covers TCP and UDP stuff for right now because the dnet ICMP struct doesn't work for extra some things used in OS Scanning as is, and the IP struct just uses a stupid unsigned integer for the addresses instead of struct in_addr. So.. this removes netinet/tcp.h and netinet/udp.h references in tcpip.h and nmap.h, the udphdr_bsd struct stuff, the TH_ECE/TH_CWR #defines in tcpip.h. I just did a big sed -i 's///g' loop to convert the struct names (struct tcphdr -> struct tcp_hdr, and udphdr_bsd -> struct udp_hdr). dnet.h was allready included, and it #includes the tcp.h and udp.h for the packet structs. It all compiles and runs fine for me, and hopefully for everybody else too. ------------------------------------------------------------------------ So please test this and leave some feedback if you can. Thanks a lot, Kris Katterjohn
Index: targets.cc =================================================================== --- targets.cc (revision 4371) +++ targets.cc (revision 4372) @@ -397,8 +397,8 @@ unsigned short seq; } *ping = NULL, *ping2 = NULL; char response[16536]; - struct tcphdr *tcp; - udphdr_bsd *udp; + struct tcp_hdr *tcp; + struct udp_hdr *udp; struct ip *ip, *ip2; u32 hostnum = 0xFFFFFF; /* This ought to crash us if it is used uninitialized */ int tm; @@ -570,7 +570,7 @@ error("Got ICMP error referring to TCP msg which we did not send"); continue; } - tcp = (struct tcphdr *) (((char *) ip2) + 4 * ip2->ip_hl); + tcp = (struct tcp_hdr *) (((char *) ip2) + 4 * ip2->ip_hl); /* No need to check size here, the "+8" check a ways up takes care of it */ newport = ntohs(tcp->th_dport); @@ -673,7 +673,7 @@ error("TCP packet is only %d bytes, we can't get enough information from it\n", bytes); continue; } - tcp = (struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl); + tcp = (struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl); if (!(tcp->th_flags & TH_RST) && ((tcp->th_flags & (TH_SYN|TH_ACK)) != (TH_SYN|TH_ACK))) continue; newport = ntohs(tcp->th_sport); @@ -740,7 +740,7 @@ if (!ptech->rawudpscan) { continue; } - udp = (udphdr_bsd *) (((char *) ip) + 4 * ip->ip_hl); + udp = (struct udp_hdr *) (((char *) ip) + 4 * ip->ip_hl); newport = ntohs(udp->uh_sport); trynum = ntohs(udp->uh_dport) - sportbase; Index: nmap.h =================================================================== --- nmap.h (revision 4371) +++ nmap.h (revision 4372) @@ -159,8 +159,7 @@ #include <sys/param.h> /* Defines MAXHOSTNAMELEN on BSD*/ #endif -/* Linux uses these defines in netinet/ip.h and netinet/tcp.h to - use the correct struct ip and struct tcphdr */ +/* Linux uses these defines in netinet/ip.h to use the correct struct ip */ #ifndef __FAVOR_BSD #define __FAVOR_BSD #endif @@ -233,10 +232,6 @@ #ifndef __FAVOR_BSD #define __FAVOR_BSD #endif -#ifndef NETINET_TCP_H /* why does OpenBSD not do this? */ -#include <netinet/tcp.h> /*#include <netinet/ip_tcp.h>*/ -#define NETINET_TCP_H -#endif #if HAVE_SYS_RESOURCE_H #include <sys/resource.h> Index: osscan2.cc =================================================================== --- osscan2.cc (revision 4371) +++ osscan2.cc (revision 4372) @@ -466,8 +466,8 @@ void sendTIcmpProbe(HostOsScanStats *hss, int probeNo); /* Response process functions. */ bool processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyNo); - bool processTOpsResp(HostOsScanStats *hss, struct tcphdr *tcp, int replyNo); - bool processTWinResp(HostOsScanStats *hss, struct tcphdr *tcp, 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); @@ -477,7 +477,7 @@ void makeTOpsFP(HostOsScanStats *hss); void makeTWinFP(HostOsScanStats *hss); - bool get_tcpopt_string(struct tcphdr *tcp, int mss, char *result, int maxlen); + bool get_tcpopt_string(struct tcp_hdr *tcp, int mss, char *result, int maxlen); int rawsd; /* raw socket descriptor */ struct eth_nfo eth; @@ -1409,7 +1409,7 @@ bool HostOsScan::processResp(HostOsScanStats *hss, struct ip *ip, unsigned int len, struct timeval *rcvdtime) { struct ip *ip2; - struct tcphdr *tcp; + struct tcp_hdr *tcp; struct icmp *icmp; int testno; bool isPktUseful = false; @@ -1423,7 +1423,7 @@ if (ip->ip_p == IPPROTO_TCP) { if(len < 20) return false; - tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); if(len < (unsigned int)(4 * tcp->th_off)) return false; testno = ntohs(tcp->th_dport) - tcpPortBase; @@ -1973,7 +1973,7 @@ bool HostOsScan::processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyNo) { assert(replyNo>=0 && replyNo<NUM_SEQ_SAMPLES); - struct tcphdr *tcp; + struct tcp_hdr *tcp; int seq_response_num; /* response # for sequencing */ u32 timestamp = 0; /* TCP timestamp we receive back */ @@ -1983,7 +1983,7 @@ } hss->lastipid = ip->ip_id; - tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); if ((tcp->th_flags & TH_RST)) { if (hss->si.responses == 0) { @@ -2035,7 +2035,7 @@ return false; } -bool HostOsScan::processTOpsResp(HostOsScanStats *hss, struct tcphdr *tcp, int replyNo) { +bool HostOsScan::processTOpsResp(HostOsScanStats *hss, struct tcp_hdr *tcp, int replyNo) { assert(replyNo>=0 || replyNo<6); bool opsParseResult; @@ -2077,7 +2077,7 @@ return true; } -bool HostOsScan::processTWinResp(HostOsScanStats *hss, struct tcphdr *tcp, int replyNo) { +bool HostOsScan::processTWinResp(HostOsScanStats *hss, struct tcp_hdr *tcp, int replyNo) { assert(replyNo>=0 || replyNo<6); if (hss->FP_TWin || hss->TWin_AVs[replyNo]) return false; @@ -2116,7 +2116,7 @@ char *p; int numtests = 7; int current_testno = 0; - struct tcphdr *tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + struct tcp_hdr *tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); bool opsParseResult; if (hss->FP_TEcn) return false; @@ -2208,7 +2208,7 @@ assert(replyNo>=0 && replyNo<7); int numtests; - struct tcphdr *tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + struct tcp_hdr *tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); struct AVal *AVs; int current_testno = 0; @@ -2373,7 +2373,7 @@ int numtests; unsigned short checksum; unsigned short *checksumptr; - udphdr_bsd *udp; + struct udp_hdr *udp; struct AVal *AVs; int i; int current_testno = 0; @@ -2395,7 +2395,7 @@ assert(icmp->icmp_type == 3 && icmp->icmp_code == 3); ip2 = (struct ip*)((char *)icmp + 8); - udp = (udphdr_bsd *)((char *)ip2 + 4 * ip->ip_hl); + udp = (struct udp_hdr *)((char *)ip2 + 4 * ip->ip_hl); /* The ports should match. */ if (ntohs(udp->uh_sport) != hss->upi.sport || ntohs(udp->uh_dport) != hss->upi.dport) { @@ -2728,7 +2728,7 @@ return true; } -bool HostOsScan::get_tcpopt_string(struct tcphdr *tcp, int mss, char *result, int maxlen) { +bool HostOsScan::get_tcpopt_string(struct tcp_hdr *tcp, int mss, char *result, int maxlen) { char *p,*q; u16 tmpshort; u32 tmpword; @@ -2736,8 +2736,8 @@ int opcode; p = result; - length = (tcp->th_off * 4) - sizeof(struct tcphdr); - q = ((char *)tcp) + sizeof(struct tcphdr); + length = (tcp->th_off * 4) - sizeof(struct tcp_hdr); + q = ((char *)tcp) + sizeof(struct tcp_hdr); /* * Example parsed result: M5B4ST11NW2 @@ -3002,7 +3002,7 @@ static u16 id = 0x1042; u8 packet[328]; /* 20 IP hdr + 8 UDP hdr + 300 data */ struct ip *ip = (struct ip *) packet; - udphdr_bsd *udp = (udphdr_bsd *) (packet + sizeof(struct ip)); + struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); struct in_addr *source; int datalen = 300; unsigned char *data = packet + 28; @@ -3030,7 +3030,7 @@ for(decoy=0; decoy < o.numdecoys; decoy++) { source = &o.decoys[decoy]; - memset((char *) packet, 0, sizeof(struct ip) + sizeof(udphdr_bsd)); + memset((char *) packet, 0, sizeof(struct ip) + sizeof(struct udp_hdr)); udp->uh_sport = htons(sport); udp->uh_dport = htons(dport); @@ -3038,9 +3038,9 @@ /* OK, now we should be able to compute a valid checksum */ realcheck = magic_tcpudp_cksum(source, victim, IPPROTO_UDP, - sizeof(udphdr_bsd) + datalen, (char *) udp); + sizeof(struct udp_hdr) + datalen, (char *) udp); #if STUPID_SOLARIS_CHECKSUM_BUG - udp->uh_sum = sizeof(udphdr_bsd) + datalen; + udp->uh_sum = sizeof(struct udp_hdr) + datalen; #else udp->uh_sum = realcheck; #endif @@ -3048,7 +3048,7 @@ /* Now for the ip header */ ip->ip_v = 4; ip->ip_hl = 5; - ip->ip_len = htons(sizeof(struct ip) + sizeof(udphdr_bsd) + datalen); + ip->ip_len = htons(sizeof(struct ip) + sizeof(struct udp_hdr) + datalen); ip->ip_id = id; ip->ip_ttl = myttl; ip->ip_p = IPPROTO_UDP; Index: tcpip.cc =================================================================== --- tcpip.cc (revision 4371) +++ tcpip.cc (revision 4372) @@ -407,8 +407,8 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) { static char protoinfo[512]; struct ip *ip = (struct ip *) packet; - struct tcphdr *tcp; - udphdr_bsd *udp; + struct tcp_hdr *tcp; + struct udp_hdr *udp; char ipinfo[512]; char srchost[INET6_ADDRSTRLEN], dsthost[INET6_ADDRSTRLEN]; char *p; @@ -446,11 +446,11 @@ char buf[32]; char tcpoptinfo[256] = ""; - tcp = (struct tcphdr *) (packet + ip->ip_hl * 4); + tcp = (struct tcp_hdr *) (packet + ip->ip_hl * 4); if (frag_off > 8 || len < (u32) ip->ip_hl * 4 + 8) snprintf(protoinfo, sizeof(protoinfo), "TCP %s:?? > %s:?? ?? %s (incomplete)", srchost, dsthost, ipinfo); else if (frag_off == 8) {// at least we can get TCP flags and ACKn - tcp = (struct tcphdr *)((u8 *) tcp - frag_off); // ugly? + tcp = (struct tcp_hdr *)((u8 *) tcp - frag_off); // ugly? p = tflags; /* These are basically in tcpdump order */ if (tcp->th_flags & TH_SYN) *p++ = 'S'; @@ -467,14 +467,14 @@ if (tcp->th_flags & TH_CWR) *p++ = 'C'; /* rfc 2481/3168 */ *p++ = '\0'; - if((u32) tcp->th_off * 4 > sizeof(struct tcphdr)) { + if((u32) tcp->th_off * 4 > sizeof(struct tcp_hdr)) { // tcp options if(len < (u32) ip->ip_hl * 4 + (u32) tcp->th_off * 4 - frag_off) { snprintf(tcpoptinfo, sizeof(tcpoptinfo), "option incomplete"); } else { - tcppacketoptinfo((u8*) tcp + sizeof(struct tcphdr), - tcp->th_off*4 - sizeof(struct tcphdr), + tcppacketoptinfo((u8*) tcp + sizeof(struct tcp_hdr), + tcp->th_off*4 - sizeof(struct tcp_hdr), tcpoptinfo, sizeof(tcpoptinfo)); } } @@ -507,14 +507,14 @@ if (tcp->th_flags & TH_CWR) *p++ = 'C'; /* rfc 2481/3168 */ *p++ = '\0'; - if((u32) tcp->th_off * 4 > sizeof(struct tcphdr)) { + if((u32) tcp->th_off * 4 > sizeof(struct tcp_hdr)) { // tcp options if(len < (u32) ip->ip_hl * 4 + (u32) tcp->th_off * 4) { snprintf(tcpoptinfo, sizeof(tcpoptinfo), "option incomplete"); } else { - tcppacketoptinfo((u8*) tcp + sizeof(struct tcphdr), - tcp->th_off*4 - sizeof(struct tcphdr), + tcppacketoptinfo((u8*) tcp + sizeof(struct tcp_hdr), + tcp->th_off*4 - sizeof(struct tcp_hdr), tcpoptinfo, sizeof(tcpoptinfo)); } } @@ -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 = (udphdr_bsd *) (packet + sizeof(struct ip)); + udp = (struct udp_hdr *) (packet + sizeof(struct ip)); snprintf(protoinfo, sizeof(protoinfo), "UDP %s:%d > %s:%d %s", srchost, ntohs(udp->uh_sport), dsthost, ntohs(udp->uh_dport), @@ -1121,10 +1121,10 @@ char *data, u16 datalen, u32 *outpacketlen) { int packetlen = sizeof(struct ip) + ipoptlen + - sizeof(struct tcphdr) + tcpoptlen + datalen; + sizeof(struct tcp_hdr) + tcpoptlen + datalen; u8 *packet = (u8 *) safe_malloc(packetlen); struct ip *ip = (struct ip *) packet; -struct tcphdr *tcp = (struct tcphdr *) ((u8*)ip + sizeof(struct ip) + ipoptlen); +struct tcp_hdr *tcp = (struct tcp_hdr *) ((u8*)ip + sizeof(struct ip) + ipoptlen); static int myttl = 0; assert(victim); @@ -1143,7 +1143,7 @@ } /* Fill tcp header */ -memset(tcp, 0, sizeof(struct tcphdr)); +memset(tcp, 0, sizeof(struct tcp_hdr)); tcp->th_sport = htons(sport); tcp->th_dport = htons(dport); if (seq) { @@ -1172,16 +1172,16 @@ /* And the options */ if (tcpoptlen) - memcpy((u8*)tcp + sizeof(struct tcphdr), tcpopt, tcpoptlen); + memcpy((u8*)tcp + sizeof(struct tcp_hdr), tcpopt, tcpoptlen); /* We should probably copy the data over too */ if (data && datalen) - memcpy((u8*)tcp + sizeof(struct tcphdr) + tcpoptlen, data, datalen); + memcpy((u8*)tcp + sizeof(struct tcp_hdr) + tcpoptlen, data, datalen); #if STUPID_SOLARIS_CHECKSUM_BUG -tcp->th_sum = sizeof(struct tcphdr) + tcpoptlen + datalen; +tcp->th_sum = sizeof(struct tcp_hdr) + tcpoptlen + datalen; #else tcp->th_sum = magic_tcpudp_cksum(source, victim, IPPROTO_TCP, - sizeof(struct tcphdr) + tcpoptlen + datalen, + sizeof(struct tcp_hdr) + tcpoptlen + datalen, (char *) tcp); #endif @@ -1318,8 +1318,8 @@ struct sockaddr_in sock; int res; struct ip *ip = (struct ip *) packet; - struct tcphdr *tcp = NULL; - udphdr_bsd *udp; + struct tcp_hdr *tcp = NULL; + struct udp_hdr *udp; u8 *eth_frame = NULL; eth_t *ethsd; bool ethsd_opened = false; @@ -1359,10 +1359,10 @@ if (packetlen >= 20) { sock.sin_addr.s_addr = ip->ip_dst.s_addr; if (ip->ip_p == IPPROTO_TCP && packetlen >= (unsigned int) ip->ip_hl * 4 + 20) { - tcp = (struct tcphdr *) ((u8 *) ip + ip->ip_hl * 4); + tcp = (struct tcp_hdr *) ((u8 *) ip + ip->ip_hl * 4); sock.sin_port = tcp->th_dport; } else if (ip->ip_p == IPPROTO_UDP && packetlen >= (unsigned int) ip->ip_hl * 4 + 8) { - udp = (udphdr_bsd *) ((u8 *) ip + ip->ip_hl * 4); + udp = (struct udp_hdr *) ((u8 *) ip + ip->ip_hl * 4); sock.sin_port = udp->uh_dport; } } @@ -1513,8 +1513,8 @@ int readtcppacket(const u8 *packet, int readdata) { struct ip *ip = (struct ip *) packet; -struct tcphdr *tcp = (struct tcphdr *) (packet + sizeof(struct ip)); -const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct tcphdr); +struct tcp_hdr *tcp = (struct tcp_hdr *) (packet + sizeof(struct ip)); +const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct tcp_hdr); int tot_len; struct in_addr bullshit, bullshit2; char sourcehost[16]; @@ -1573,8 +1573,8 @@ int readudppacket(const u8 *packet, int readdata) { struct ip *ip = (struct ip *) packet; -udphdr_bsd *udp = (udphdr_bsd *) (packet + sizeof(struct ip)); -const unsigned char *data = packet + sizeof(struct ip) + sizeof(udphdr_bsd); +struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); +const unsigned char *data = packet + sizeof(struct ip) + sizeof(struct udp_hdr); int tot_len; struct in_addr bullshit, bullshit2; char sourcehost[16]; @@ -1644,10 +1644,10 @@ u16 sport, u16 dport, char *data, u16 datalen, u32 *outpacketlen) { - int packetlen = sizeof(struct ip) + ipoptlen + sizeof(udphdr_bsd) + datalen; + int packetlen = sizeof(struct ip) + ipoptlen + sizeof(struct udp_hdr) + datalen; u8 *packet = (u8 *) safe_malloc(packetlen); struct ip *ip = (struct ip *) packet; - udphdr_bsd *udp = (udphdr_bsd *) ((u8*)ip + sizeof(struct ip) + ipoptlen); + struct udp_hdr *udp = (struct udp_hdr *) ((u8*)ip + sizeof(struct ip) + ipoptlen); static int myttl = 0; /* check that required fields are there and not too silly */ @@ -1665,18 +1665,18 @@ udp->uh_sport = htons(sport); udp->uh_dport = htons(dport); udp->uh_sum = 0; - udp->uh_ulen = htons(sizeof(udphdr_bsd) + datalen); + udp->uh_ulen = htons(sizeof(struct udp_hdr) + datalen); /* We should probably copy the data over too */ if (data) - memcpy((u8*)udp + sizeof(udphdr_bsd), data, datalen); + memcpy((u8*)udp + sizeof(struct udp_hdr), data, datalen); /* OK, now we should be able to compute a valid checksum */ #if STUPID_SOLARIS_CHECKSUM_BUG - udp->uh_sum = sizeof(udphdr_bsd) + datalen; + udp->uh_sum = sizeof(struct udp_hdr) + datalen; #else udp->uh_sum = magic_tcpudp_cksum(source, victim, IPPROTO_UDP, - sizeof(udphdr_bsd) + datalen, (char *) udp); + sizeof(struct udp_hdr) + datalen, (char *) udp); #endif if ( o.badsum ) @@ -3264,7 +3264,7 @@ parameters (if non-null) are filled with 0. Remember that the correct way to check for errors is to look at the return value since a zero ts or echots could possibly be valid. */ -int gettcpopt_ts(struct tcphdr *tcp, u32 *timestamp, u32 *echots) { +int gettcpopt_ts(struct tcp_hdr *tcp, u32 *timestamp, u32 *echots) { unsigned char *p; int len = 0; Index: tcpip.h =================================================================== --- tcpip.h (revision 4371) +++ tcpip.h (revision 4372) @@ -142,8 +142,7 @@ #include <sys/param.h> /* Defines MAXHOSTNAMELEN on BSD*/ #endif -/* Linux uses these defines in netinet/ip.h and netinet/tcp.h to - use the correct struct ip and struct tcphdr */ +/* Linux uses these defines in netinet/ip.h to use the correct struct ip */ #ifndef __FAVOR_BSD #define __FAVOR_BSD 1 #endif @@ -183,14 +182,6 @@ #include <netinet/ip.h> #define NETINET_IP_H #endif -#ifndef NETINET_TCP_H /* why the HELL does OpenBSD not do this? */ -#include <netinet/tcp.h> /*#include <netinet/ip_tcp.h>*/ -#define NETINET_TCP_H -#endif -#ifndef NETINET_UDP_H -#include <netinet/udp.h> -#define NETINET_UDP_H -#endif #if HAVE_UNISTD_H #include <unistd.h> #endif @@ -237,14 +228,6 @@ #include "nmap.h" #include "global_structures.h" -/* Explicit Congestion Notification (rfc 2481/3168) */ -#ifndef TH_ECE -#define TH_ECE 0x40 -#endif -#ifndef TH_CWR -#define TH_CWR 0x80 -#endif - #ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 #endif @@ -375,18 +358,6 @@ #endif /* HAVE_STRUCT_IP */ -#ifdef LINUX -typedef struct udphdr_bsd { - unsigned short uh_sport; /* source port */ - unsigned short uh_dport; /* destination port */ - unsigned short uh_ulen; /* udp length */ - unsigned short uh_sum; /* udp checksum */ -} udphdr_bsd; -#else - typedef struct udphdr udphdr_bsd; -#endif - - #ifndef HAVE_STRUCT_ICMP #define HAVE_STRUCT_ICMP /* From Linux /usr/include/netinet/ip_icmp.h GLIBC */ @@ -759,7 +730,7 @@ parameters (if non-null) are filled with 0. Remember that the correct way to check for errors is to look at the return value since a zero ts or echots could possibly be valid. */ -int gettcpopt_ts(struct tcphdr *tcp, u32 *timestamp, u32 *echots); +int gettcpopt_ts(struct tcp_hdr *tcp, u32 *timestamp, u32 *echots); /* Maximize the receive buffer of a socket descriptor (up to 500K) */ void max_rcvbuf(int sd); Index: idle_scan.cc =================================================================== --- idle_scan.cc (revision 4371) +++ idle_scan.cc (revision 4372) @@ -168,7 +168,7 @@ int timedout = 0; int base_port; struct ip *ip; - struct tcphdr *tcp; + struct tcp_hdr *tcp; static u32 seq_base = 0; static u32 ack = 0; static int packet_send_count = 0; /* Total # of probes sent by this program -- to ensure that our sequence # always changes */ @@ -212,7 +212,7 @@ if (ip->ip_p == IPPROTO_TCP) { - tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); if (ntohs(tcp->th_dport) < base_port || ntohs(tcp->th_dport) - base_port >= tries || ntohs(tcp->th_sport) != proxy->probe_port || ((tcp->th_flags & TH_RST) == 0)) { if (ntohs(tcp->th_dport) > o.magic_port && ntohs(tcp->th_dport) < (o.magic_port + 260)) { if (o.debugging) { @@ -301,7 +301,7 @@ struct timeval probe_send_times[NUM_IPID_PROBES], tmptv, rcvdtime; u16 lastipid = 0; struct ip *ip; - struct tcphdr *tcp; + struct tcp_hdr *tcp; int distance; u16 ipids[NUM_IPID_PROBES]; u8 probe_returned[NUM_IPID_PROBES]; @@ -458,7 +458,7 @@ continue; if (ip->ip_p == IPPROTO_TCP) { - tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); if (ntohs(tcp->th_dport) < (o.magic_port+1) || ntohs(tcp->th_dport) - o.magic_port > NUM_IPID_PROBES || ntohs(tcp->th_sport) != proxy->probe_port || ((tcp->th_flags & TH_RST) == 0)) { if (o.debugging > 1) error("Received unexpected response packet from %s during initial ipid zombie testing", inet_ntoa(ip->ip_src)); continue; Index: osscan.cc =================================================================== --- osscan.cc (revision 4371) +++ osscan.cc (revision 4372) @@ -132,7 +132,7 @@ static u16 id = 0; u8 packet[328]; /* 20 IP hdr + 8 UDP hdr + 300 data */ struct ip *ip = (struct ip *) packet; -udphdr_bsd *udp = (udphdr_bsd *) (packet + sizeof(struct ip)); +struct udp_hdr *udp = (struct udp_hdr *) (packet + sizeof(struct ip)); 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(udphdr_bsd)); + memset((char *) packet, 0, sizeof(struct ip) + sizeof(struct udp_hdr)); udp->uh_sport = htons(sport); udp->uh_dport = htons(dport); @@ -164,9 +164,9 @@ /* OK, now we should be able to compute a valid checksum */ realcheck = magic_tcpudp_cksum(source, victim, IPPROTO_UDP, - sizeof(udphdr_bsd) + datalen, (char *) udp); + sizeof(struct udp_hdr) + datalen, (char *) udp); #if STUPID_SOLARIS_CHECKSUM_BUG - udp->uh_sum = sizeof(udphdr_bsd) + datalen; + udp->uh_sum = sizeof(struct udp_hdr) + datalen; #else udp->uh_sum = realcheck; #endif @@ -177,7 +177,7 @@ /* Now for the ip header */ ip->ip_v = 4; ip->ip_hl = 5; - ip->ip_len = htons(sizeof(struct ip) + sizeof(udphdr_bsd) + datalen); + ip->ip_len = htons(sizeof(struct ip) + sizeof(struct udp_hdr) + datalen); ip->ip_id = id; ip->ip_ttl = myttl; ip->ip_p = IPPROTO_UDP; @@ -218,7 +218,7 @@ int opcode; u16 tmpshort; char *p,*q; - struct tcphdr *tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + struct tcp_hdr *tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); AVs = (struct AVal *) malloc(6 * sizeof(struct AVal)); @@ -282,8 +282,8 @@ AVs[5].attribute = "Ops"; p = AVs[5].value; /* Partly swiped from /usr/src/linux/net/ipv4/tcp_input.c in Linux kernel */ - length = (tcp->th_off * 4) - sizeof(struct tcphdr); - q = ((char *)tcp) + sizeof(struct tcphdr); + length = (tcp->th_off * 4) - sizeof(struct tcp_hdr); + q = ((char *)tcp) + sizeof(struct tcp_hdr); while(length > 0 && ((p - AVs[5].value) < (int) (sizeof(AVs[5].value) - 3))) { @@ -323,7 +323,7 @@ int numtests = 10; unsigned short checksum; unsigned short *checksumptr; - udphdr_bsd *udp; + struct udp_hdr *udp; struct AVal *AVs; int i; int current_testno = 0; @@ -344,7 +344,7 @@ return NULL; /* Not a port unreachable */ ip2 = (struct ip*) ((char *)icmp + 8); - udp = (udphdr_bsd *) ((char *)ip2 + 20); + udp = (struct udp_hdr *) ((char *)ip2 + 20); /* The ports better match as well ... */ if (ntohs(udp->uh_sport) != upi->sport || ntohs(udp->uh_dport) != upi->dport) { @@ -474,7 +474,7 @@ int last; u32 timestamp = 0; /* TCP timestamp we receive back */ struct ip *ip; - struct tcphdr *tcp; + struct tcp_hdr *tcp; struct icmp *icmp; struct timeval t1,t2; int i; @@ -677,7 +677,7 @@ continue; setTargetMACIfAvailable(target, &linkhdr, ip, 0); if (ip->ip_p == IPPROTO_TCP) { - tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); testno = ntohs(tcp->th_dport) - current_port + 1; if (testno <= 0 || testno > 7) continue; @@ -777,7 +777,7 @@ setTargetMACIfAvailable(target, &linkhdr, ip, 0); if (ip->ip_p == IPPROTO_TCP) { /* readtcppacket((char *) ip, ntohs(ip->ip_len)); */ - tcp = ((struct tcphdr *) (((char *) ip) + 4 * ip->ip_hl)); + tcp = ((struct tcp_hdr *) (((char *) ip) + 4 * ip->ip_hl)); if (ntohs(tcp->th_dport) < o.magic_port || ntohs(tcp->th_dport) - o.magic_port > NUM_SEQ_SAMPLES || ntohs(tcp->th_sport) != openport) { Index: scan_engine.cc =================================================================== --- scan_engine.cc (revision 4371) +++ scan_engine.cc (revision 4372) @@ -671,8 +671,8 @@ 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 tcphdr *tcp = NULL; - udphdr_bsd *udp = NULL; + struct tcp_hdr *tcp = NULL; + struct udp_hdr *udp = NULL; type = UP_IP; if (ipv4->ip_v != 4) @@ -683,12 +683,12 @@ probes.IP.ipid = ntohs(ipv4->ip_id); if (ipv4->ip_p == IPPROTO_TCP) { assert (iplen >= (unsigned) ipv4->ip_hl * 4 + 20); - tcp = (struct tcphdr *) ((u8 *) ipv4 + ipv4->ip_hl * 4); + tcp = (struct tcp_hdr *) ((u8 *) ipv4 + ipv4->ip_hl * 4); probes.IP.pd.tcp.sport = ntohs(tcp->th_sport); probes.IP.pd.tcp.seq = ntohl(tcp->th_seq); } else if (ipv4->ip_p == IPPROTO_UDP) { assert(iplen >= (unsigned) ipv4->ip_hl * 4 + 8); - udp = (udphdr_bsd *) ((u8 *) ipv4 + ipv4->ip_hl * 4); + udp = (struct udp_hdr *) ((u8 *) ipv4 + ipv4->ip_hl * 4); probes.IP.pd.udp.sport = ntohs(udp->uh_sport); } @@ -2801,9 +2801,9 @@ bool timedout = false; struct timeval rcvdtime; struct ip *ip = NULL, *ip2 = NULL; - struct tcphdr *tcp = NULL; + struct tcp_hdr *tcp = NULL; struct icmp *icmp = NULL; - udphdr_bsd *udp = NULL; + struct udp_hdr *udp = NULL; struct link_header linkhdr; unsigned int bytes; long to_usec; @@ -2881,7 +2881,7 @@ if (ip->ip_p == IPPROTO_TCP && !USI->prot_scan) { if ((unsigned) ip->ip_hl * 4 + 20 > bytes) continue; - tcp = (struct tcphdr *) ((u8 *) ip + ip->ip_hl * 4); + tcp = (struct tcp_hdr *) ((u8 *) ip + ip->ip_hl * 4); /* Now ensure this host is even in the incomplete list */ memset(&sin, 0, sizeof(sin)); sin.sin_addr.s_addr = ip->ip_src.s_addr; @@ -3028,7 +3028,7 @@ continue; if (ip2->ip_p == IPPROTO_TCP && !USI->prot_scan) { - tcp = (struct tcphdr *) ((u8 *) ip2 + ip2->ip_hl * 4); + tcp = (struct tcp_hdr *) ((u8 *) ip2 + ip2->ip_hl * 4); if (probe->protocol() != IPPROTO_TCP || ntohs(tcp->th_sport) != probe->sport() || ntohs(tcp->th_dport) != probe->dport() || @@ -3036,7 +3036,7 @@ continue; } else if (ip2->ip_p == IPPROTO_UDP && !USI->prot_scan) { /* TODO: IPID verification */ - udp = (udphdr_bsd *) ((u8 *) ip2 + ip->ip_hl * 4); + udp = (struct udp_hdr *) ((u8 *) ip2 + ip->ip_hl * 4); if (probe->protocol() != IPPROTO_UDP || ntohs(udp->uh_sport) != probe->sport() || ntohs(udp->uh_dport) != probe->dport()) @@ -3095,7 +3095,7 @@ } else if (ip->ip_p == IPPROTO_UDP && !USI->prot_scan) { if ((unsigned) ip->ip_hl * 4 + 8 > bytes) continue; - udp = (udphdr_bsd *) ((u8 *) ip + ip->ip_hl * 4); + udp = (struct udp_hdr *) ((u8 *) ip + ip->ip_hl * 4); /* Search for this host on the incomplete list */ memset(&sin, 0, sizeof(sin)); sin.sin_addr.s_addr = ip->ip_src.s_addr;
_______________________________________________ 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)