On Thu, Feb 2, 2017 at 6:37 AM, Vadim Kochan <vadi...@gmail.com> wrote: > tun interface does not have Ethernet header so lets push Ethernet > header only if device supports this. > > Signed-off-by: Vadim Kochan <vadi...@gmail.com> > --- > dev.c | 18 ++++++++++++++++++ > dev.h | 4 ++++ > trafgen_l3.c | 15 ++++++++++++--- > trafgen_proto.c | 5 +++++ > trafgen_proto.h | 2 ++ > 5 files changed, 41 insertions(+), 3 deletions(-) > > diff --git a/dev.c b/dev.c > index 2960976..8442c5e 100644 > --- a/dev.c > +++ b/dev.c > @@ -430,3 +430,21 @@ const char *device_addr2str(const unsigned char *addr, > int alen, int type, > > return buf; > } > + > +bool device_is_ether(const char *ifname) > +{ > + switch (device_type(ifname)) { > + case ARPHRD_TUNNEL: > + case ARPHRD_TUNNEL6: > + case ARPHRD_LOOPBACK: > + case ARPHRD_SIT: > + case ARPHRD_IPDDP: > + case ARPHRD_IPGRE: > + case ARPHRD_IP6GRE: > + case ARPHRD_ETHER: > + return true; > + > + default: > + return false; > + } > +} > diff --git a/dev.h b/dev.h > index 06e51d2..6b56fe0 100644 > --- a/dev.h > +++ b/dev.h > @@ -1,6 +1,7 @@ > #ifndef DEV_H > #define DEV_H > > +#include <stdbool.h> > #include <sys/socket.h> > #include "built_in.h" > > @@ -19,4 +20,7 @@ extern void device_leave_promiscuous_mode(const char > *ifname, short oldflags); > extern const char *device_type2str(uint16_t type); > extern const char *device_addr2str(const unsigned char *addr, int alen, int > type, > char *buf, int blen); > + > +extern bool device_is_ether(const char *ifname); > + > #endif /* DEV_H */ > diff --git a/trafgen_l3.c b/trafgen_l3.c > index 70aefb9..62a7708 100644 > --- a/trafgen_l3.c > +++ b/trafgen_l3.c > @@ -3,9 +3,10 @@ > * Subject to the GPL, version 2. > */ > > -#include <linux/if_ether.h> > +#include <net/if_arp.h> > > #include "die.h" > +#include "dev.h" > #include "csum.h" > #include "built_in.h" > #include "trafgen_l2.h" > @@ -34,7 +35,11 @@ static struct proto_field ipv4_fields[] = { > > static void ipv4_header_init(struct proto_hdr *hdr) > { > - proto_lower_default_add(hdr, PROTO_ETH); > + const char *dev = proto_dev_get(); > + > + /* In case of tun interface we do not need to create Ethernet header > */ > + if (dev && device_mtu(dev) && device_is_ether(dev)) > + proto_lower_default_add(hdr, PROTO_ETH); >
But may be it is better to just check if device_type(dev) != ARPHRD_NONE ? -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to netsniff-ng+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.