mirror of
https://github.com/ntop/n2n.git
synced 2024-04-21 16:31:34 +00:00
Simplify tuntap_open by using one function prototype for all OS
This commit is contained in:
@@ -58,10 +58,8 @@ int main() {
|
||||
"10.0.0.1", // Set ip address
|
||||
"255.255.255.0", // Netmask to use
|
||||
"DE:AD:BE:EF:01:10", // Set mac address
|
||||
DEFAULT_MTU // MTU to use
|
||||
#ifdef _WIN32
|
||||
, 0
|
||||
#endif
|
||||
DEFAULT_MTU, // MTU to use
|
||||
0 // Metric - unused in n2n on most OS
|
||||
) < 0)
|
||||
{
|
||||
return -1;
|
||||
|
||||
+1
-5
@@ -127,11 +127,7 @@ void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...)
|
||||
|
||||
/* Tuntap API */
|
||||
int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
|
||||
char *device_mask, const char * device_mac, int mtu
|
||||
#ifdef _WIN32
|
||||
, int metric
|
||||
#endif
|
||||
);
|
||||
char *device_mask, const char * device_mac, int mtu, int metric);
|
||||
int tuntap_read (struct tuntap_dev *tuntap, unsigned char *buf, int len);
|
||||
int tuntap_write (struct tuntap_dev *tuntap, unsigned char *buf, int len);
|
||||
void tuntap_close (struct tuntap_dev *tuntap);
|
||||
|
||||
+2
-5
@@ -1246,11 +1246,8 @@ int main (int argc, char* argv[]) {
|
||||
if(runlevel == 4) { /* configure the TUNTAP device, including routes */
|
||||
if(tuntap_open(&tuntap, eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode,
|
||||
eee->tuntap_priv_conf.ip_addr, eee->tuntap_priv_conf.netmask,
|
||||
eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu
|
||||
#ifdef _WIN32
|
||||
, eee->tuntap_priv_conf.metric
|
||||
#endif
|
||||
) < 0)
|
||||
eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu,
|
||||
eee->tuntap_priv_conf.metric) < 0)
|
||||
exit(1);
|
||||
memcpy(&eee->device, &tuntap, sizeof(tuntap));
|
||||
traceEvent(TRACE_NORMAL, "created local tap device IP: %s, Mask: %s, MAC: %s",
|
||||
|
||||
+4
-9
@@ -2182,10 +2182,8 @@ void edge_read_from_tap (n2n_edge_t * eee) {
|
||||
sleep(3);
|
||||
tuntap_close(&(eee->device));
|
||||
tuntap_open(&(eee->device), eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, eee->tuntap_priv_conf.ip_addr,
|
||||
eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu
|
||||
#ifdef _WIN32
|
||||
,eee->tuntap_priv_conf.metric
|
||||
#endif
|
||||
eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu,
|
||||
eee->tuntap_priv_conf.metric
|
||||
);
|
||||
} else {
|
||||
const uint8_t * mac = eth_pkt;
|
||||
@@ -3295,11 +3293,8 @@ int quick_edge_init (char *device_name, char *community_name,
|
||||
/* Open the tuntap device */
|
||||
if(tuntap_open(&tuntap, device_name, "static",
|
||||
local_ip_address, "255.255.255.0",
|
||||
device_mac, DEFAULT_MTU
|
||||
#ifdef _WIN32
|
||||
, 0
|
||||
#endif
|
||||
) < 0)
|
||||
device_mac, DEFAULT_MTU,
|
||||
0) < 0)
|
||||
return(-2);
|
||||
|
||||
/* Init edge */
|
||||
|
||||
@@ -36,7 +36,8 @@ int tuntap_open (tuntap_dev *device /* ignored */,
|
||||
char *device_ip,
|
||||
char *device_mask,
|
||||
const char * device_mac,
|
||||
int mtu) {
|
||||
int mtu,
|
||||
int ignored) {
|
||||
|
||||
int i;
|
||||
char tap_device[N2N_FREEBSD_TAPDEVICE_SIZE];
|
||||
|
||||
+2
-1
@@ -120,7 +120,8 @@ int tuntap_open (tuntap_dev *device,
|
||||
char *device_ip,
|
||||
char *device_mask,
|
||||
const char * device_mac,
|
||||
int mtu) {
|
||||
int mtu,
|
||||
int ignored) {
|
||||
|
||||
char *tuntap_device = "/dev/net/tun";
|
||||
int ioctl_fd;
|
||||
|
||||
+2
-1
@@ -40,7 +40,8 @@ int tuntap_open (tuntap_dev *device /* ignored */,
|
||||
char *device_ip,
|
||||
char *device_mask,
|
||||
const char * device_mac,
|
||||
int mtu) {
|
||||
int mtu,
|
||||
int ignored) {
|
||||
|
||||
char tap_device[N2N_NETBSD_TAPDEVICE_SIZE];
|
||||
struct ifreq req;
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@ int tuntap_open (tuntap_dev *device /* ignored */,
|
||||
char *device_ip,
|
||||
char *device_mask,
|
||||
const char * device_mac,
|
||||
int mtu) {
|
||||
int mtu,
|
||||
int ignored) {
|
||||
|
||||
int i;
|
||||
char tap_device[N2N_OSX_TAPDEVICE_SIZE];
|
||||
|
||||
Reference in New Issue
Block a user