Fix indent and device name on bsd

This commit is contained in:
Erik Ekman 2006-06-25 11:15:18 +00:00
parent c46c2c99ff
commit c7191d27e7

27
tun.c
View file

@ -57,18 +57,18 @@ open_tun(const char *tun_device)
ifreq.ifr_flags = IFF_TUN; ifreq.ifr_flags = IFF_TUN;
if (tun_device != NULL) { if (tun_device != NULL) {
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ); strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
strncpy(if_name, tun_device, sizeof(if_name)); strncpy(if_name, tun_device, sizeof(if_name));
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) { if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
printf("Opened %s\n", ifreq.ifr_name); printf("Opened %s\n", ifreq.ifr_name);
return tun_fd; return tun_fd;
} }
if (errno != EBUSY) { if (errno != EBUSY) {
warn("open_tun: ioctl[TUNSETIFF]: %s", strerror(errno)); warn("open_tun: ioctl[TUNSETIFF]: %s", strerror(errno));
return -1; return -1;
} }
} else { } else {
for (i = 0; i < TUN_MAX_TRY; i++) { for (i = 0; i < TUN_MAX_TRY; i++) {
snprintf(ifreq.ifr_name, IFNAMSIZ, "dns%d", i); snprintf(ifreq.ifr_name, IFNAMSIZ, "dns%d", i);
@ -100,8 +100,11 @@ open_tun(const char *tun_device)
char tun_name[50]; char tun_name[50];
if (tun_device != NULL) { if (tun_device != NULL) {
if ((tun_fd = open(tun_device, O_RDWR)) < 0) { snprintf(tun_name, sizeof(tun_name), "/dev/%s", tun_device);
warn("open_tun: %s: %s", tun_device, strerror(errno)); strncpy(if_name, tun_device, sizeof(if_name));
if ((tun_fd = open(tun_name, O_RDWR)) < 0) {
warn("open_tun: %s: %s", tun_name, strerror(errno));
return -1; return -1;
} }
} else { } else {