diff --git a/configure.ac b/configure.ac index 45ab22b..b7e6793 100644 --- a/configure.ac +++ b/configure.ac @@ -112,6 +112,12 @@ AC_EGREP_HEADER(rt_msghdr, net/route.h, AC_DEFINE([HAVE_RT_MSGHDR])], AC_MSG_RESULT(no)) +AC_MSG_CHECKING(whether struct iphdr exists) +AH_TEMPLATE(HAVE_IPHDR) +AC_EGREP_HEADER(struct iphdr, netinet/ip.h, +[AC_MSG_RESULT(yes) + AC_DEFINE([HAVE_IPHDR])], + AC_MSG_RESULT(no)) # Checks for library functions. AC_PROG_GCC_TRADITIONAL diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 0d0e569..4fb2066 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include #include @@ -221,13 +223,13 @@ int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len) { struct ippoolm_t *ipm; struct in46_addr dst; - struct tun_packet_t *iph = (struct tun_packet_t *)pack; + struct iphdr *iph = (struct iphdr *)pack; - if (iph->ver == 4) { + if (iph->version == 4) { if (len < sizeof(*iph) || len < 4*iph->ihl) return -1; dst.len = 4; - dst.v4.s_addr = iph->dst; + dst.v4.s_addr = iph->daddr; } else { LOGP(DGGSN, LOGL_NOTICE, "non-IPv4 packet received from tun\n"); return -1; diff --git a/lib/tun.h b/lib/tun.h index ce7b91c..c50bdf9 100644 --- a/lib/tun.h +++ b/lib/tun.h @@ -17,21 +17,31 @@ #define TUN_ADDRSIZE 128 #define TUN_NLBUFSIZE 1024 -struct tun_packet_t { - unsigned int ver:4; - unsigned int ihl:4; - unsigned int dscp:6; - unsigned int ecn:2; - unsigned int length:16; - unsigned int id:16; - unsigned int flags:3; - unsigned int fragment:13; - unsigned int ttl:8; - unsigned int protocol:8; - unsigned int check:16; - unsigned int src:32; - unsigned int dst:32; -}; +#include "config.h" +#ifndef HAVE_IPHDR +struct iphdr + { +#if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int ihl:4; + unsigned int version:4; +#elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int version:4; + unsigned int ihl:4; +#else +# error "Please fix " +#endif + u_int8_t tos; + u_int16_t tot_len; + u_int16_t id; + u_int16_t frag_off; + u_int8_t ttl; + u_int8_t protocol; + u_int16_t check; + u_int32_t saddr; + u_int32_t daddr; + /*The options start here. */ + }; +#endif /* !HAVE_IPHDR */ /* *********************************************************** * Information storage for each tun instance diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c index 90a6200..af8f9fa 100644 --- a/sgsnemu/sgsnemu.c +++ b/sgsnemu/sgsnemu.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1281,10 +1282,10 @@ int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len) { struct iphash_t *ipm; struct in46_addr src; - struct tun_packet_t *iph = (struct tun_packet_t *)pack; + struct iphdr *iph = (struct iphdr *)pack; src.len = 4; - src.v4.s_addr = iph->src; + src.v4.s_addr = iph->saddr; if (ipget(&ipm, &src)) { printf("Dropping packet from invalid source address: %s\n",