36 |
|
|
37 |
#include <linux/if_tun.h> |
#include <linux/if_tun.h> |
38 |
|
|
39 |
|
#include "gettext.h" |
40 |
#include "tun/tun.h" |
#include "tun/tun.h" |
41 |
#include "options.h" |
#include "options.h" |
42 |
#include "log.h" |
#include "log.h" |
64 |
if ((tun_fd = open (tunname, O_RDWR)) > 0) |
if ((tun_fd = open (tunname, O_RDWR)) > 0) |
65 |
{ |
{ |
66 |
sprintf (PARAM_INTERFACE_NAME, "tun%d", i); |
sprintf (PARAM_INTERFACE_NAME, "tun%d", i); |
67 |
break; |
break; |
68 |
} |
} |
69 |
} |
} |
70 |
|
|
71 |
if(!tun_ready ()) |
if (!tun_ready ()) |
72 |
{ |
{ |
73 |
if (PARAM_INTERFACE_NAME) |
if (PARAM_INTERFACE_NAME) |
74 |
{ |
{ |
75 |
log(LOG_ERR, "Unable to open tun device /dev/%s (using 2.2 kernel " |
log (LOG_ERR, gettext ("Unable to open tun device /dev/%s (using 2.2 kernel " |
76 |
"method): %s(%d).\n", PARAM_INTERFACE_NAME, strerror(errno), |
"method): %s(%d).\n"), |
77 |
errno); |
PARAM_INTERFACE_NAME, strerror (errno), |
78 |
|
errno); |
79 |
} |
} |
80 |
else |
else |
81 |
{ |
{ |
82 |
log(LOG_ERR, "Unable to open a valid tun device (using 2.2 kernel " |
log (LOG_ERR, gettext ("Unable to open a valid tun device (using 2.2 kernel " |
83 |
"method).\n"); |
"method).\n")); |
84 |
} |
} |
85 |
return 0; |
return 0; |
86 |
} |
} |
105 |
|
|
106 |
if ((tun_fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0) |
if ((tun_fd = open ("/dev/net/tun", O_RDWR | O_NONBLOCK)) < 0) |
107 |
{ |
{ |
108 |
log(LOG_WARNING, "Unable to open /dev/net/tun: %s(%d).\n", |
log (LOG_WARNING, gettext ("Unable to open /dev/net/tun: %s(%d).\n"), |
109 |
strerror(errno), errno); |
strerror (errno), errno); |
110 |
log(LOG_WARNING, "Assuming 2.2 kernel method.\n"); |
log (LOG_WARNING, gettext ("Assuming 2.2 kernel method.\n")); |
111 |
return tun_open_old (); |
return tun_open_old (); |
112 |
} |
} |
113 |
|
|
123 |
/* Try old ioctl */ |
/* Try old ioctl */ |
124 |
if (ioctl (tun_fd, OTUNSETIFF, (void *) &ifr) < 0) |
if (ioctl (tun_fd, OTUNSETIFF, (void *) &ifr) < 0) |
125 |
{ |
{ |
126 |
log(LOG_ERR, "Unable to open a valid tun device (using pre " |
log (LOG_ERR, gettext ("Unable to open a valid tun device (using pre " |
127 |
"2.4.6 kernel method): %s(%d).\n", strerror(errno), errno); |
"2.4.6 kernel method): %s(%d).\n"), strerror (errno), |
128 |
|
errno); |
129 |
tun_close (); |
tun_close (); |
130 |
return 0; |
return 0; |
131 |
} |
} |
132 |
} |
} |
133 |
else |
else |
134 |
{ |
{ |
135 |
log(LOG_ERR, "Unable to open a valid tun device (using post " |
log (LOG_ERR, gettext ("Unable to open a valid tun device (using post " |
136 |
"2.4.6 kernel method): %s(%d).\n", strerror(errno), errno); |
"2.4.6 kernel method): %s(%d).\n"), strerror (errno), errno); |
137 |
tun_close (); |
tun_close (); |
138 |
return 0; |
return 0; |
139 |
} |
} |
184 |
if (buffer->used < sizeof (struct iphdr)) |
if (buffer->used < sizeof (struct iphdr)) |
185 |
return 0; |
return 0; |
186 |
if (buffer->used < ntohs (ip->tot_len)) |
if (buffer->used < ntohs (ip->tot_len)) |
187 |
return 0; |
return 0; |
188 |
|
|
189 |
*data = (char *) ip; |
*data = (char *) ip; |
190 |
*data_size = ntohs (ip->tot_len); |
*data_size = ntohs (ip->tot_len); |