1 | /* |
1 | /* |
2 | device.c -- Interaction with Solaris tun device |
2 | device.c -- Interaction with Solaris tun device |
3 | Copyright (C) 2001-2003 Ivo Timmermans <ivo@o2w.nl>, |
3 | Copyright (C) 2001-2004 Ivo Timmermans <ivo@tinc-vpn.org>, |
4 | 2001-2003 Guus Sliepen <guus@sliepen.eu.org> |
4 | 2001-2004 Guus Sliepen <guus@tinc-vpn.org> |
5 | |
5 | |
6 | This program is free software; you can redistribute it and/or modify |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
9 | (at your option) any later version. |
… | |
… | |
15 | |
15 | |
16 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | |
19 | |
20 | $Id: device.c,v 1.1 2003/10/14 03:22:09 pcg Exp $ |
20 | $Id: device.c,v 1.2 2005/03/17 23:59:38 pcg Exp $ |
21 | */ |
21 | */ |
22 | |
22 | |
23 | |
23 | |
|
|
24 | #include "system.h" |
24 | |
25 | |
25 | #include <sys/stropts.h> |
26 | #include <sys/stropts.h> |
26 | #include <sys/sockio.h> |
27 | #include <sys/sockio.h> |
27 | #include <net/if_tun.h> |
28 | #include <net/if_tun.h> |
28 | |
|
|
29 | |
29 | |
30 | #define DEFAULT_DEVICE "/dev/tun" |
30 | #define DEFAULT_DEVICE "/dev/tun" |
31 | |
31 | |
32 | int device_fd = -1; |
32 | int device_fd = -1; |
33 | char *device = NULL; |
33 | char *device = NULL; |
34 | char *iface = NULL; |
34 | char *iface = NULL; |
35 | char ifrname[IFNAMSIZ]; |
|
|
36 | char *device_info = NULL; |
35 | char *device_info = NULL; |
37 | |
36 | |
38 | int device_total_in = 0; |
37 | static int device_total_in = 0; |
39 | int device_total_out = 0; |
38 | static int device_total_out = 0; |
40 | |
39 | |
41 | bool setup_device(void) |
40 | bool setup_device(void) |
42 | { |
41 | { |
43 | int ip_fd = -1, if_fd = -1; |
42 | int ip_fd = -1, if_fd = -1; |
44 | int ppa; |
43 | int ppa; |
… | |
… | |
121 | logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info, |
120 | logger(LOG_ERR, _("Error while reading from %s %s: %s"), device_info, |
122 | device, strerror(errno)); |
121 | device, strerror(errno)); |
123 | return false; |
122 | return false; |
124 | } |
123 | } |
125 | |
124 | |
|
|
125 | switch(packet->data[14] >> 4) { |
|
|
126 | case 4: |
126 | packet->data[12] = 0x08; |
127 | packet->data[12] = 0x08; |
127 | packet->data[13] = 0x00; |
128 | packet->data[13] = 0x00; |
|
|
129 | break; |
|
|
130 | case 6: |
|
|
131 | packet->data[12] = 0x86; |
|
|
132 | packet->data[13] = 0xDD; |
|
|
133 | break; |
|
|
134 | default: |
|
|
135 | ifdebug(TRAFFIC) logger(LOG_ERR, |
|
|
136 | _ ("Unknown IP version %d while reading packet from %s %s"), |
|
|
137 | packet->data[14] >> 4, device_info, device); |
|
|
138 | return false; |
|
|
139 | } |
128 | |
140 | |
129 | packet->len = lenin + 14; |
141 | packet->len = lenin + 14; |
130 | |
142 | |
131 | device_total_in += packet->len; |
143 | device_total_in += packet->len; |
132 | |
144 | |