diff --git a/idle_scan.cc b/idle_scan.cc index a2590ec41..46850ca00 100644 --- a/idle_scan.cc +++ b/idle_scan.cc @@ -168,7 +168,7 @@ static int ipid_proxy_probe(struct idle_proxy_info *proxy, int *probes_sent, 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 @@ static int ipid_proxy_probe(struct idle_proxy_info *proxy, int *probes_sent, 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 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, 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 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, 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; diff --git a/nmap.h b/nmap.h index a900ac94c..7672842a9 100644 --- a/nmap.h +++ b/nmap.h @@ -159,8 +159,7 @@ void *realloc(); #include /* 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 @@ -230,10 +229,6 @@ void *realloc(); #include #include -#ifndef NETINET_TCP_H /* why does OpenBSD not do this? */ -#include /*#include */ -#define NETINET_TCP_H -#endif #if HAVE_SYS_RESOURCE_H #include diff --git a/osscan.cc b/osscan.cc index 34df24a17..130ea104d 100644 --- a/osscan.cc +++ b/osscan.cc @@ -132,7 +132,7 @@ 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; -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 @@ if (!myttl) myttl = (time(NULL) % 14) + 51; 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 @@ for(decoy=0; decoy < o.numdecoys; decoy++) { /* 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 @@ -179,7 +179,7 @@ for(decoy=0; decoy < o.numdecoys; decoy++) { /* 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; @@ -220,7 +220,7 @@ static struct AVal *fingerprint_iptcppacket(struct ip *ip, int mss, u32 syn) { 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)); @@ -284,8 +284,8 @@ static struct AVal *fingerprint_iptcppacket(struct ip *ip, int mss, u32 syn) { 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))) { @@ -325,7 +325,7 @@ static struct AVal *fingerprint_portunreach(struct ip *ip, struct udpprobeinfo * 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; @@ -346,7 +346,7 @@ static struct AVal *fingerprint_portunreach(struct ip *ip, struct udpprobeinfo * 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) { @@ -476,7 +476,7 @@ static FingerPrint *get_fingerprint(Target *target, struct seq_info *si) { 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; @@ -679,7 +679,7 @@ static FingerPrint *get_fingerprint(Target *target, struct seq_info *si) { 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; @@ -779,7 +779,7 @@ static FingerPrint *get_fingerprint(Target *target, struct seq_info *si) { 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) { diff --git a/osscan2.cc b/osscan2.cc index 13eeba1ce..41afe127e 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -466,8 +466,8 @@ private: 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 @@ private: 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 @@ void HostOsScan::sendTUdpProbe(HostOsScanStats *hss, int probeNo) { 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 @@ bool HostOsScan::processResp(HostOsScanStats *hss, struct ip *ip, unsigned int l 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 @@ void HostOsScan::makeTWinFP(HostOsScanStats *hss) { bool HostOsScan::processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyNo) { assert(replyNo>=0 && replyNolastipid = 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 @@ bool HostOsScan::processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyN 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 @@ bool HostOsScan::processTOpsResp(HostOsScanStats *hss, struct tcphdr *tcp, int r 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 @@ bool HostOsScan::processTEcnResp(HostOsScanStats *hss, struct ip *ip) { 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 @@ bool HostOsScan::processT1_7Resp(HostOsScanStats *hss, struct ip *ip, int replyN 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 @@ bool HostOsScan::processTUdpResp(HostOsScanStats *hss, struct ip *ip) { 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 @@ bool HostOsScan::processTUdpResp(HostOsScanStats *hss, struct ip *ip) { 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 @@ bool HostOsScan::processTIcmpResp(HostOsScanStats *hss, struct ip *ip, int reply 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 @@ bool HostOsScan::get_tcpopt_string(struct tcphdr *tcp, int mss, char *result, in 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 @@ int send_closedudp_probe_2(struct udpprobeinfo &upi, int sd, 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 @@ int send_closedudp_probe_2(struct udpprobeinfo &upi, int sd, 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 @@ int send_closedudp_probe_2(struct udpprobeinfo &upi, int sd, /* 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 @@ int send_closedudp_probe_2(struct udpprobeinfo &upi, int sd, /* 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; diff --git a/scan_engine.cc b/scan_engine.cc index 22b3839a2..22d11d5a2 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -671,8 +671,8 @@ void UltraProbe::setARP(u8 *arppkt, u32 arplen) { 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 @@ void UltraProbe::setIP(u8 *ippacket, u32 iplen, const probespec *pspec) { 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 @@ static bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) { 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 @@ static bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) { 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 @@ static bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) { 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 @@ static bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) { 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 @@ static bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) { } 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; diff --git a/targets.cc b/targets.cc index f0c9ef9fb..85c0f3f10 100644 --- a/targets.cc +++ b/targets.cc @@ -397,8 +397,8 @@ static int get_ping_results(int sd, pcap_t *pd, Target *hostbatch[], 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 @@ static int get_ping_results(int sd, pcap_t *pd, Target *hostbatch[], 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 @@ static int get_ping_results(int sd, pcap_t *pd, Target *hostbatch[], 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 @@ static int get_ping_results(int sd, pcap_t *pd, Target *hostbatch[], 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; diff --git a/tcpip.cc b/tcpip.cc index 5c2e02bae..1c938dc0d 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -407,8 +407,8 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) { 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 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) { 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 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) { 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 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) { 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 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) { } 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 @@ u8 *build_tcp_raw(const struct in_addr *source, const struct in_addr *victim, 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 @@ if (ttl == -1) { } /* 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 @@ if (urp) /* 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 @@ int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetl 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 @@ int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetl 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 @@ u8 *build_igmp_raw(const struct in_addr *source, const struct in_addr *victim, 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 @@ return 0; 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 @@ u8 *build_udp_raw(struct in_addr *source, const struct in_addr *victim, 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 @@ u8 *build_udp_raw(struct in_addr *source, const struct in_addr *victim, 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 ) { @@ -3218,7 +3218,7 @@ int recvtime(int sd, char *buf, int len, int seconds, int *timedout) { 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; diff --git a/tcpip.h b/tcpip.h index 232f44cde..e4db8c48f 100644 --- a/tcpip.h +++ b/tcpip.h @@ -142,8 +142,7 @@ void *realloc(); #include /* 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 @@ void *realloc(); #include #define NETINET_IP_H #endif -#ifndef NETINET_TCP_H /* why the HELL does OpenBSD not do this? */ -#include /*#include */ -#define NETINET_TCP_H -#endif -#ifndef NETINET_UDP_H -#include -#define NETINET_UDP_H -#endif #if HAVE_UNISTD_H #include #endif @@ -237,14 +228,6 @@ typedef enum { devt_ethernet, devt_loopback, devt_p2p, devt_other } devtype; #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 @@ struct ip #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 @@ int read_arp_reply_pcap(pcap_t *pd, u8 *sendermac, struct in_addr *senderIP, 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);