… | |
… | |
28 | #include <fcntl.h> |
28 | #include <fcntl.h> |
29 | #include <net/if.h> |
29 | #include <net/if.h> |
30 | #include <unistd.h> |
30 | #include <unistd.h> |
31 | #include <sys/ioctl.h> |
31 | #include <sys/ioctl.h> |
32 | |
32 | |
|
|
33 | #include <net/if.h> |
|
|
34 | |
33 | #ifdef LINUX_IF_TUN_H |
35 | #ifdef LINUX_IF_TUN_H |
34 | #include LINUX_IF_TUN_H |
36 | # include LINUX_IF_TUN_H |
35 | #else |
37 | #else |
36 | #include <linux/if_tun.h> |
38 | #include <linux/if_tun.h> |
37 | #endif |
39 | #endif |
38 | #define DEFAULT_DEVICE "/dev/net/tun" |
40 | #define DEFAULT_DEVICE "/dev/net/tun" |
39 | |
41 | |
40 | #include "gettext.h" |
42 | #include "gettext.h" |
41 | |
43 | |
42 | #include "conf.h" |
44 | #include "conf.h" |
|
|
45 | |
|
|
46 | const char * |
|
|
47 | tap_device::info () |
|
|
48 | { |
|
|
49 | return _("Linux tun/tap device"); |
|
|
50 | } |
43 | |
51 | |
44 | tap_device::tap_device () |
52 | tap_device::tap_device () |
45 | { |
53 | { |
46 | struct ifreq ifr; |
54 | struct ifreq ifr; |
47 | |
55 | |
… | |
… | |
72 | { |
80 | { |
73 | slog (L_CRIT, _("unable to configure tun/tap interface: %s"), strerror (errno)); |
81 | slog (L_CRIT, _("unable to configure tun/tap interface: %s"), strerror (errno)); |
74 | exit (1); |
82 | exit (1); |
75 | } |
83 | } |
76 | |
84 | |
77 | if (conf.ifpersist) |
|
|
78 | if (ioctl (fd, TUNSETPERSIST, 1)) |
85 | if (ioctl (fd, TUNSETPERSIST, conf.ifpersist ? 1 : 0)) |
79 | slog (L_WARN, _("cannot set persistent mode for device %s: %s"), ifrname, strerror (errno)); |
86 | slog (L_WARN, _("cannot set persistency mode for device %s: %s"), ifrname, strerror (errno)); |
80 | |
87 | |
81 | slog (L_DEBUG, _("%s is a %s"), device, info ()); |
88 | slog (L_DEBUG, _("%s is a %s"), device, info ()); |
82 | } |
89 | } |
83 | |
90 | |
84 | tap_device::~tap_device () |
91 | tap_device::~tap_device () |
… | |
… | |
93 | |
100 | |
94 | pkt->len = read (fd, &((*pkt)[0]), MAX_MTU); |
101 | pkt->len = read (fd, &((*pkt)[0]), MAX_MTU); |
95 | |
102 | |
96 | if (pkt->len <= 0) |
103 | if (pkt->len <= 0) |
97 | { |
104 | { |
|
|
105 | delete pkt; |
98 | slog (L_ERR, _("error while reading from %s %s: %s"), |
106 | slog (L_ERR, _("error while reading from %s %s: %s"), |
99 | info (), DEFAULT_DEVICE, strerror (errno)); |
107 | info (), DEFAULT_DEVICE, strerror (errno)); |
100 | free (pkt); |
|
|
101 | return 0; |
108 | return 0; |
102 | } |
109 | } |
103 | |
110 | |
104 | return pkt; |
111 | return pkt; |
105 | } |
112 | } |