--- gvpe/src/device.h 2003/04/08 02:00:54 1.5 +++ gvpe/src/device.h 2005/03/23 21:55:39 1.19 @@ -1,7 +1,10 @@ /* device.h -- generic header for device.c + Copyright (C) 2003-2005 Marc Lehmann - This program is free software; you can redistribute it and/or modify + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -12,23 +15,25 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with gvpe; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef VPE_DEVICE_H__ -#define VPE_DEVICE_H__ +#ifndef GVPE_DEVICE_H__ +#define GVPE_DEVICE_H__ -#include +#include "config.h" -#include "gettext.h" +#define IFNAMESIZE 256 // be conservative #include "global.h" +#include "util.h" struct net_packet { u32 len; // actually u16, but padding... u8 &operator[] (u16 offset) const; + u8 *at (u16 offset) const; void unshift_hdr (u16 hdrsize) { @@ -48,7 +53,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 @@ -70,7 +91,11 @@ return ((data_packet *)this)->data_[offset]; } -typedef u8 mac[6]; +inline +u8 *net_packet::at (u16 offset) const +{ + return &((*this)[offset]); +} struct tap_packet : net_packet { mac dst; @@ -81,20 +106,26 @@ struct tap_device { int fd; - // linux tuntap - char ifrname[IFNAMSIZ + 1]; + // network interface name or identifier + char ifrname[IFNAMESIZE + 1]; char *device; tap_device (); ~tap_device (); + //bool open (); + //void close (); + const char *interface () { return ifrname; } - const char *info () { return _("Linux tun/tap device"); } + const char *info (); + const char *if_up (); tap_packet *recv (); void send (tap_packet *pkt); }; +//extern tap_device *tap_device (); + #endif