ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device.h
Revision: 1.2
Committed: Fri Mar 28 04:05:10 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +6 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 device.h -- generic header for device.c
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifndef VPE_DEVICE_H__
20 #define VPE_DEVICE_H__
21
22 #include "config.h"
23
24 #include <cstdlib>
25 #include <cstring>
26
27 #include <net/if.h>
28
29 #include "gettext.h"
30
31 #include "global.h"
32
33 struct net_packet {
34 u32 len; // actually u16, but padding...
35
36 u8 &operator[] (u16 offset);
37
38 void skip_hdr (u16 hdrsize)
39 {
40 memmove ((void *)&(*this)[0], (void *)&(*this)[hdrsize], len -= hdrsize);
41 }
42
43 bool is_arp ()
44 {
45 return (*this)[12] == 0x08 && (*this)[13] == 0x06 // 0806 protocol
46 && (*this)[14] == 0x00 && (*this)[15] == 0x01 // 0001 hw_format
47 && (*this)[16] == 0x08 && (*this)[17] == 0x00 // 0800 prot_format
48 && (*this)[18] == 0x06 && (*this)[19] == 0x04; // 06 hw_len 04 prot_len
49 }
50
51 void *operator new (size_t s);
52 void operator delete (void *p);
53 };
54
55 struct data_packet : net_packet {
56 u8 data_[MAXSIZE];
57 };
58
59 inline
60 u8 &net_packet::operator[] (u16 offset)
61 {
62 return ((data_packet *)this)->data_[offset];
63 }
64
65 typedef u8 mac[6];
66
67 struct tap_packet : net_packet {
68 mac dst;
69 mac src;
70 u8 data[MAXSIZE - 12];
71 };
72
73 struct tap_device {
74 int fd;
75
76 // linux tuntap
77 char ifrname[IFNAMSIZ + 1];
78
79 char *device;
80
81 tap_device ();
82 ~tap_device ();
83
84 const char *interface () { return ifrname; }
85 const char *info () { return _("Linux tun/tap device"); }
86
87 tap_packet *recv ();
88 void send (tap_packet *pkt);
89 };
90
91 #endif
92