From 732b02c54457bfaccaac77c9431fb8aee13233f0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 12 Jul 2016 13:24:59 +0300 Subject: [PATCH] Change some headers and structs for BSD compatibility --- main.c | 61 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/main.c b/main.c index 1b12385..38624d0 100644 --- a/main.c +++ b/main.c @@ -6,22 +6,23 @@ Distributed under the GPL #include #include -#include +#include +#include +#include #include #include #include +#include +#include +#include +#include +#include +#include #include +#include #include -#include -#include #include -#include -#include -#include -#include #include -#include -#include typedef unsigned long long Time; @@ -275,30 +276,30 @@ void monitor_check(Monitor *monitor, Time timestamp) void capture_handler(uint8_t *user, const struct pcap_pkthdr *header, const uint8_t *data) { Monitor *monitor = (Monitor *)user; - const struct ethhdr *eth = (const struct ethhdr *)(data); + const struct ether_header *eth = (const struct ether_header *)(data); int src_scope = 0; int dst_scope = 0; - int proto = ntohs(eth->h_proto); - if(proto==ETH_P_IP) + int proto = ntohs(eth->ether_type); + if(proto==ETHERTYPE_IP) { - const struct iphdr *ip = (const struct iphdr *)(eth+1); - if(ntohl(ip->daddr)>>28==14) + const struct ip *ip = (const struct ip *)(eth+1); + if(ntohl(ip->ip_dst.s_addr)>>28==14) dst_scope = 3; for(unsigned i=0; in_addresses; ++i) if(monitor->addresses[i].address.ss_family==AF_INET) { - int s = get_inet_scope(ip->saddr, &monitor->addresses[i]); + int s = get_inet_scope(ip->ip_src.s_addr, &monitor->addresses[i]); if(s>src_scope) src_scope = s; - s = get_inet_scope(ip->daddr, &monitor->addresses[i]); + s = get_inet_scope(ip->ip_dst.s_addr, &monitor->addresses[i]); if(s>dst_scope) dst_scope = s; } } - else if(proto==ETH_P_IPV6) + else if(proto==ETHERTYPE_IPV6) { const struct ip6_hdr *ip6 = (const struct ip6_hdr *)(eth+1); for(unsigned i=0; in_addresses; ++i) @@ -415,11 +416,11 @@ void pinger_check(Pinger *pinger, Time time) fprintf(stderr, "recvfrom error: %s\n", strerror(errno)); else { - struct iphdr *ip = (struct iphdr *)data; - if(ip->protocol==IPPROTO_ICMP) + struct ip *ip = (struct ip *)data; + if(ip->ip_p==IPPROTO_ICMP) { - struct icmphdr *icmp = (struct icmphdr *)(ip+1); - if(icmp->type==ICMP_ECHOREPLY && icmp->un.echo.id==pinger->id) + struct icmp *icmp = (struct icmp *)(ip+1); + if(icmp->icmp_type==ICMP_ECHOREPLY && icmp->icmp_id==pinger->id) { /* It's an ICMP echo reply and ours, process it */ if(verbose) @@ -429,10 +430,10 @@ void pinger_check(Pinger *pinger, Time time) printf("Ping reply from %s\n", buf); } - if(icmp->un.echo.sequence==pinger->pending) + if(icmp->icmp_seq==pinger->pending) pinger->pending = 0; else if(verbose) - printf("Sequence %d, expected %d\n", icmp->un.echo.sequence, pinger->pending); + printf("Sequence %d, expected %d\n", icmp->icmp_seq, pinger->pending); } } } @@ -469,13 +470,13 @@ void send_ping(Pinger *pinger) for(unsigned i=0; itype = ICMP_ECHO; - hdr->code = 0; - hdr->checksum = 0; - hdr->un.echo.id = pinger->id; - hdr->un.echo.sequence = pinger->seq; - hdr->checksum = checksum(data, sizeof(data)); + struct icmp *hdr = (struct icmp *)data; + hdr->icmp_type = ICMP_ECHO; + hdr->icmp_code = 0; + hdr->icmp_cksum = 0; + hdr->icmp_id = pinger->id; + hdr->icmp_seq = pinger->seq; + hdr->icmp_cksum = checksum(data, sizeof(data)); if(sendto(pinger->socket, data, sizeof(data), 0, (struct sockaddr *)&pinger->target_addr, sizeof(struct sockaddr_in))==-1) fprintf(stderr, "sendto error: %s\n", strerror(errno)); -- 2.43.0