"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/tuntap_freebsd.c" between
n2n-2.8.tar.gz and n2n-3.0.tar.gz

About: n2n is a layer-two peer-to-peer virtual private network (VPN) which allows bypassing intermediate firewalls.

tuntap_freebsd.c  (n2n-2.8):tuntap_freebsd.c  (n2n-3.0)
/** /**
* (C) 2007-20 - ntop.org and contributors * (C) 2007-21 - ntop.org and contributors
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not see see <http://www.gnu.org/licenses/> * along with this program; if not see see <http://www.gnu.org/licenses/>
* *
*/ */
#include "n2n.h" #include "n2n.h"
#ifdef __FreeBSD__ #ifdef __FreeBSD__
void tuntap_close(tuntap_dev *device); #define N2N_FREEBSD_TAPDEVICE_SIZE 32
/* ********************************** */ void tuntap_close (tuntap_dev *device);
#define N2N_FREEBSD_TAPDEVICE_SIZE 32 int tuntap_open (tuntap_dev *device /* ignored */,
int tuntap_open(tuntap_dev *device /* ignored */, char *dev,
char *dev, const char *address_mode, /* static or dhcp */
const char *address_mode, /* static or dhcp */ char *device_ip,
char *device_ip, char *device_mask,
char *device_mask, const char * device_mac,
const char * device_mac, int mtu) {
int mtu) {
int i; int i;
char tap_device[N2N_FREEBSD_TAPDEVICE_SIZE]; char tap_device[N2N_FREEBSD_TAPDEVICE_SIZE];
for (i = 0; i < 255; i++) { for(i = 0; i < 255; i++) {
snprintf(tap_device, sizeof(tap_device), "/dev/tap%d", i); snprintf(tap_device, sizeof(tap_device), "/dev/tap%d", i);
device->fd = open(tap_device, O_RDWR); device->fd = open(tap_device, O_RDWR);
if(device->fd > 0) { if(device->fd > 0) {
traceEvent(TRACE_NORMAL, "Succesfully open %s", tap_device); traceEvent(TRACE_NORMAL, "Succesfully open %s", tap_device);
break; break;
}
} }
}
if(device->fd < 0) { if(device->fd < 0) {
traceEvent(TRACE_ERROR, "Unable to open tap device"); traceEvent(TRACE_ERROR, "Unable to open tap device");
return(-1); return -1;
} else { } else {
char buf[256]; char buf[256];
FILE *fd; FILE *fd;
device->ip_addr = inet_addr(device_ip); device->ip_addr = inet_addr(device_ip);
if ( device_mac && device_mac[0] != '\0' ) if(device_mac && device_mac[0] != '\0') {
{ // FIXME - this is not tested, might be wrong syntax for OS X
/* FIXME - This is not tested. Might be wrong syntax for OS X */
// set the hw address before bringing the if up
/* Set the hw address before bringing the if up. */ snprintf(buf, sizeof(buf), "ifconfig tap%d ether %s", i, device_mac)
snprintf(buf, sizeof(buf), "ifconfig tap%d ether %s", ;
i, device_mac); system(buf);
}
snprintf(buf, sizeof(buf), "ifconfig tap%d %s netmask %s mtu %d up", i,
device_ip, device_mask, mtu);
system(buf); system(buf);
}
snprintf(buf, sizeof(buf), "ifconfig tap%d %s netmask %s mtu %d up", traceEvent(TRACE_NORMAL, "Interface tap%d up and running (%s/%s)", i, de
i, device_ip, device_mask, mtu); vice_ip, device_mask);
system(buf);
traceEvent(TRACE_NORMAL, "Interface tap%d up and running (%s/%s)",
i, device_ip, device_mask);
/* Read MAC address */
snprintf(buf, sizeof(buf), "ifconfig tap%d |grep ether|cut -c 8-24", i);
/* traceEvent(TRACE_INFO, "%s", buf); */
fd = popen(buf, "r");
if(fd < 0) {
tuntap_close(device);
return(-1);
} else {
int a, b, c, d, e, f;
buf[0] = 0; // read MAC address
fgets(buf, sizeof(buf), fd); snprintf(buf, sizeof(buf), "ifconfig tap%d |grep ether|cut -c 8-24", i);
pclose(fd); // traceEvent(TRACE_INFO, "%s", buf);
if(buf[0] == '\0') { fd = popen(buf, "r");
traceEvent(TRACE_ERROR, "Unable to read tap%d interface MAC address"); if(fd < 0) {
exit(0); tuntap_close(device);
} return -1;
} else {
traceEvent(TRACE_NORMAL, "Interface tap%d mac %s", i, buf); int a, b, c, d, e, f;
if(sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", &a, &b, &c, &d, &e, &f) ==
6) { buf[0] = 0;
device->mac_addr[0] = a, device->mac_addr[1] = b; fgets(buf, sizeof(buf), fd);
device->mac_addr[2] = c, device->mac_addr[3] = d; pclose(fd);
device->mac_addr[4] = e, device->mac_addr[5] = f;
} if(buf[0] == '\0') {
traceEvent(TRACE_ERROR, "Unable to read tap%d interface MAC addr
ess");
exit(0);
}
traceEvent(TRACE_NORMAL, "Interface tap%d mac %s", i, buf);
if(sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", &a, &b, &c, &d, &e,
&f) == 6) {
device->mac_addr[0] = a, device->mac_addr[1] = b;
device->mac_addr[2] = c, device->mac_addr[3] = d;
device->mac_addr[4] = e, device->mac_addr[5] = f;
}
}
} }
}
/* read_mac(dev, device->mac_addr); */ // read_mac(dev, device->mac_addr);
return(device->fd);
return device->fd;
} }
/* ********************************** */ int tuntap_read (struct tuntap_dev *tuntap, unsigned char *buf, int len) {
int tuntap_read(struct tuntap_dev *tuntap, unsigned char *buf, int len) { return read(tuntap->fd, buf, len);
return(read(tuntap->fd, buf, len));
} }
/* ********************************** */ int tuntap_write (struct tuntap_dev *tuntap, unsigned char *buf, int len) {
int tuntap_write(struct tuntap_dev *tuntap, unsigned char *buf, int len) { return write(tuntap->fd, buf, len);
return(write(tuntap->fd, buf, len));
} }
/* ********************************** */ void tuntap_close (struct tuntap_dev *tuntap) {
void tuntap_close(struct tuntap_dev *tuntap) { close(tuntap->fd);
close(tuntap->fd);
} }
/* Fill out the ip_addr value from the interface. Called to pick up dynamic // fill out the ip_addr value from the interface, called to pick up dynamic addr
* address changes. */ ess changes
void tuntap_get_address(struct tuntap_dev *tuntap) void tuntap_get_address (struct tuntap_dev *tuntap) {
{
// no action
} }
#endif /* #ifdef __FreeBSD__ */ #endif /* #ifdef __FreeBSD__ */
 End of changes. 18 change blocks. 
89 lines changed or deleted 87 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)