mirror of
https://github.com/markqvist/tncattach.git
synced 2025-02-03 09:44:09 -05:00
Fixed inadvertently setting interface flags when setting MTU
This commit is contained in:
parent
0159926312
commit
764746cc4c
73
TAP.c
73
TAP.c
@ -65,52 +65,59 @@ int open_tap(void) {
|
||||
}
|
||||
|
||||
if (!noup) {
|
||||
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
|
||||
if (ioctl(inet, SIOCSIFFLAGS, &ifr) < 0) {
|
||||
perror("Could not bring up interface");
|
||||
if (ioctl(inet, SIOCGIFFLAGS, &ifr) < 0) {
|
||||
perror("Could not get interface flags from kernel");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
if (set_ipv4) {
|
||||
struct ifreq a_ifr;
|
||||
struct sockaddr_in addr, snm;
|
||||
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
|
||||
if (ioctl(inet, SIOCSIFFLAGS, &ifr) < 0) {
|
||||
perror("Could not bring up interface");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
if (set_ipv4) {
|
||||
struct ifreq a_ifr;
|
||||
struct sockaddr_in addr, snm;
|
||||
|
||||
memset(&a_ifr, 0, sizeof(a_ifr));
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
memset(&snm, 0, sizeof(addr));
|
||||
strncpy(a_ifr.ifr_name, ifr.ifr_name, IFNAMSIZ);
|
||||
addr.sin_family = AF_INET;
|
||||
snm.sin_family = AF_INET;
|
||||
memset(&a_ifr, 0, sizeof(a_ifr));
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
memset(&snm, 0, sizeof(addr));
|
||||
strncpy(a_ifr.ifr_name, ifr.ifr_name, IFNAMSIZ);
|
||||
addr.sin_family = AF_INET;
|
||||
snm.sin_family = AF_INET;
|
||||
|
||||
int addr_conversion = inet_pton(AF_INET, ipv4_addr, &(addr.sin_addr));
|
||||
if (addr_conversion != 1) {
|
||||
printf("Error: Invalid IPv4 address specified\r\n");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
a_ifr.ifr_addr = *(struct sockaddr*)&addr;
|
||||
if (ioctl(inet, SIOCSIFADDR, &a_ifr) < 0) {
|
||||
perror("Could not set IP-address");
|
||||
int addr_conversion = inet_pton(AF_INET, ipv4_addr, &(addr.sin_addr));
|
||||
if (addr_conversion != 1) {
|
||||
printf("Error: Invalid IPv4 address specified\r\n");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
if (set_netmask) {
|
||||
int snm_conversion = inet_pton(AF_INET, netmask, &(snm.sin_addr));
|
||||
if (snm_conversion != 1) {
|
||||
printf("Error: Invalid subnet mask specified\r\n");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
a_ifr.ifr_addr = *(struct sockaddr*)&snm;
|
||||
if (ioctl(inet, SIOCSIFNETMASK, &a_ifr) < 0) {
|
||||
perror("Could not set subnet mask");
|
||||
a_ifr.ifr_addr = *(struct sockaddr*)&addr;
|
||||
if (ioctl(inet, SIOCSIFADDR, &a_ifr) < 0) {
|
||||
perror("Could not set IP-address");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
if (set_netmask) {
|
||||
int snm_conversion = inet_pton(AF_INET, netmask, &(snm.sin_addr));
|
||||
if (snm_conversion != 1) {
|
||||
printf("Error: Invalid subnet mask specified\r\n");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
} else {
|
||||
a_ifr.ifr_addr = *(struct sockaddr*)&snm;
|
||||
if (ioctl(inet, SIOCSIFNETMASK, &a_ifr) < 0) {
|
||||
perror("Could not set subnet mask");
|
||||
close(inet);
|
||||
cleanup();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ void read_loop(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const char *argp_program_version = "tncattach 0.1.3";
|
||||
const char *argp_program_version = "tncattach 0.1.4";
|
||||
const char *argp_program_bug_address = "<mark@unsigned.io>";
|
||||
static char doc[] = "\r\nAttach TNC devices as system network interfaces\vTo attach the TNC connected to /dev/ttyUSB0 as an ethernet device with an MTU of 512 bytes and assign an IPv4 address, while filtering IPv6 traffic, use:\r\n\r\n\ttncattach /dev/ttyUSB0 115200 -m 512 -e --noipv6 --ipv4 10.0.0.1/24\r\n\r\nStation identification can be performed automatically. Use the --id and --idinterval options. Identification beacons will be transmitted if the amount of time since the last identification is greater than the configured interval and there is any data to send. Channel capacity will therefore not be wasted on IDs for stations that are not actively transmitting.";
|
||||
static char args_doc[] = "port baudrate";
|
||||
|
Loading…
Reference in New Issue
Block a user