--- gvpe/src/device.h 2003/10/14 16:59:34 1.7 +++ gvpe/src/device.h 2003/10/16 02:41:21 1.11 @@ -1,5 +1,6 @@ /* device.h -- generic header for device.c + Copyright (C) 2003 Marc Lehmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,7 +49,23 @@ memcpy (&((*this)[0]), &(pkt[0]), len); } - bool is_arp () + bool is_ipv4 () const + { + return (*this)[12] == 0x08 && (*this)[13] == 0x00 // IP + && ((*this)[14] & 0xf0) == 0x40; // IPv4 + } + + u32 &ipv4_src () const + { + return *(u32 *)&(*this)[26]; + } + + u32 &ipv4_dst () const + { + return *(u32 *)&(*this)[30]; + } + + bool is_arp () const { return (*this)[12] == 0x08 && (*this)[13] == 0x06 // 0806 protocol && (*this)[14] == 0x00 && (*this)[15] == 0x01 // 0001 hw_format @@ -78,7 +95,7 @@ u8 data[MAXSIZE - 12]; }; -struct tap_device_base { +struct tap_device { int fd; // network interface name or identifier @@ -86,8 +103,11 @@ char *device; - bool open (); - void close (); + tap_device (); + ~tap_device (); + + //bool open (); + //void close (); const char *interface () { return ifrname; } const char *info (); @@ -96,9 +116,7 @@ void send (tap_packet *pkt); }; -struct tap_device; - -extern tap_device tap; +//extern tap_device *tap_device (); #endif