1 | /* |
1 | /* |
2 | device.h -- generic header for device.c |
2 | device.h -- generic header for device.c |
3 | Copyright (C) 2003 Marc Lehmann <pcg@goof.com> |
3 | Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
29 | |
29 | |
30 | struct net_packet { |
30 | struct net_packet { |
31 | u32 len; // actually u16, but padding... |
31 | u32 len; // actually u16, but padding... |
32 | |
32 | |
33 | u8 &operator[] (u16 offset) const; |
33 | u8 &operator[] (u16 offset) const; |
|
|
34 | u8 *at (u16 offset) const; |
34 | |
35 | |
35 | void unshift_hdr (u16 hdrsize) |
36 | void unshift_hdr (u16 hdrsize) |
36 | { |
37 | { |
37 | memmove ((void *)&(*this)[hdrsize], (void *)&(*this)[0], len); |
38 | memmove ((void *)&(*this)[hdrsize], (void *)&(*this)[0], len); |
38 | len += hdrsize; |
39 | len += hdrsize; |
… | |
… | |
86 | u8 &net_packet::operator[] (u16 offset) const |
87 | u8 &net_packet::operator[] (u16 offset) const |
87 | { |
88 | { |
88 | return ((data_packet *)this)->data_[offset]; |
89 | return ((data_packet *)this)->data_[offset]; |
89 | } |
90 | } |
90 | |
91 | |
|
|
92 | inline |
|
|
93 | u8 *net_packet::at (u16 offset) const |
|
|
94 | { |
|
|
95 | return &((*this)[offset]); |
|
|
96 | } |
|
|
97 | |
91 | struct tap_packet : net_packet { |
98 | struct tap_packet : net_packet { |
92 | mac dst; |
99 | mac dst; |
93 | mac src; |
100 | mac src; |
94 | u8 data[MAXSIZE - 12]; |
101 | u8 data[MAXSIZE - 12]; |
95 | }; |
102 | }; |
… | |
… | |
97 | struct tap_device { |
104 | struct tap_device { |
98 | int fd; |
105 | int fd; |
99 | |
106 | |
100 | // network interface name or identifier |
107 | // network interface name or identifier |
101 | char ifrname[IFNAMESIZE + 1]; |
108 | char ifrname[IFNAMESIZE + 1]; |
|
|
109 | |
|
|
110 | char *device; |
102 | |
111 | |
103 | tap_device (); |
112 | tap_device (); |
104 | ~tap_device (); |
113 | ~tap_device (); |
105 | |
114 | |
106 | //bool open (); |
115 | //bool open (); |