1
0
mirror of https://github.com/cmand/yarrp.git synced 2024-05-11 05:55:06 +00:00

Fixes for FreeBSD version >=11:

ip(4): "Before FreeBSD 11.0 packets received on raw IP sockets had the ip_len and
     ip_off fields converted to	host byte order.  Packets written to raw IP
     sockets were expected to have ip_len and ip_off in	host byte order."
This commit is contained in:
Robert Beverly
2020-06-27 09:30:41 -07:00
parent 0ae0268bf9
commit bcf5f33f6d
4 changed files with 17 additions and 6 deletions

View File

@ -2,6 +2,7 @@ yarrp-0.7
---------
* Add IPv6 EH support
* Add ICMP MPLS extension support
* FreeBSD verison >=11 fixes
yarrp-0.6
---------

View File

@ -28,6 +28,13 @@ case $host_os in
*linux*)
AC_DEFINE(OS,"LINUX",[Operating System String])
AC_DEFINE(_LINUX,1,[Define to 1 if a Linux operating system]);;
*freebsd*)
AC_DEFINE(OS,"FBSD",[Operating System String])
AC_DEFINE(_BSD,1,[Define to 1 if a BSD-like operating system])
freebsd_version=$(uname -K)
AX_COMPARE_VERSION($freebsd_version,[lt],[1100000],
AC_DEFINE(_OLD_BSD,1,[Define to 1 if Freebsd<11]),
AC_DEFINE(_NEW_FBSD,1,[Define to 1 if Freebsd>=11]));;
*bsd*)
AC_DEFINE(OS,"BSD",[Operating System String])
AC_DEFINE(_BSD,1,[Define to 1 if a BSD-like operating system]);;

View File

@ -21,7 +21,7 @@ ICMP4::ICMP4(struct ip *ip, struct icmp *icmp, uint32_t elapsed, bool _coarse):
code = (uint8_t) icmp->icmp_code;
ip_src = ip->ip_src;
#ifdef _BSD
#if defined(_BSD) && !defined(_NEW_FBSD)
replysize = ip->ip_len;
#else
replysize = ntohs(ip->ip_len);
@ -37,7 +37,7 @@ ICMP4::ICMP4(struct ip *ip, struct icmp *icmp, uint32_t elapsed, bool _coarse):
ptr = (unsigned char *) icmp;
quote = (struct ip *) (ptr + 8);
quote_p = quote->ip_p;
#ifdef _BSD
#if defined(_BSD) && !defined(_NEW_FBSD)
probesize = quote->ip_len;
#else
probesize = ntohs(quote->ip_len);

View File

@ -110,7 +110,7 @@ Traceroute4::probeUDP(struct sockaddr_in *target, int ttl) {
packlen = sizeof(struct ip) + sizeof(struct udphdr) + payloadlen;
outip->ip_p = IPPROTO_UDP;
#ifdef _BSD
#if defined(_BSD) && !defined(_NEW_FBSD)
outip->ip_len = packlen;
outip->ip_off = IP_DF;
#else
@ -154,10 +154,11 @@ Traceroute4::probeTCP(struct sockaddr_in *target, int ttl) {
packlen = sizeof(struct ip) + sizeof(struct tcphdr) + payloadlen;
outip->ip_p = IPPROTO_TCP;
outip->ip_len = htons(packlen);
#ifdef _BSD
#if defined(_BSD) && !defined(_NEW_FBSD)
outip->ip_len = packlen;
outip->ip_off = 0; //IP_DF;
#else
outip->ip_len = htons(packlen);
#endif
/* encode destination IPv4 address as cksum(ipdst) */
uint16_t dport = in_cksum((unsigned short *)&(outip->ip_dst), 4);
@ -208,9 +209,11 @@ Traceroute4::probeICMP(struct sockaddr_in *target, int ttl) {
packlen = sizeof(struct ip) + ICMP_MINLEN + payloadlen;
outip->ip_p = IPPROTO_ICMP;
outip->ip_len = htons(packlen);
#ifdef _BSD
#if defined(_BSD) && !defined(_NEW_FBSD)
outip->ip_len = packlen;
outip->ip_off = 0; //IP_DF;
#else
outip->ip_len = htons(packlen);
#endif
/* encode send time into icmp id and seq as elapsed milli/micro seconds */
uint32_t diff = elapsed();