replaced err with warn and proper returns

This commit is contained in:
Bjorn Andersson 2006-06-05 14:02:42 +00:00
parent d4ecde9188
commit 5ff6d2228c
1 changed files with 19 additions and 10 deletions

29
tun.c
View File

@ -48,8 +48,10 @@ open_tun()
if (tun_device == NULL) if (tun_device == NULL)
tun_device = "/dev/net/tun"; tun_device = "/dev/net/tun";
if ((tun_fd = open(tun_device, O_RDWR)) < 0) if ((tun_fd = open(tun_device, O_RDWR)) < 0) {
err(1, "open_tun: %s: %s", tun_device, strerror(errno)); warn("open_tun: %s: %s", tun_device, strerror(errno));
return 1;
}
bzero(&ifreq, sizeof(ifreq)); bzero(&ifreq, sizeof(ifreq));
@ -63,11 +65,13 @@ open_tun()
return 0; return 0;
} }
if (errno != EBUSY) if (errno != EBUSY) {
err(1, "open_tun: ioctl[TUNSETIFF]: %s", strerror(errno)); warn("open_tun: ioctl[TUNSETIFF]: %s", strerror(errno));
return 1;
}
} }
err(1, "open_tun: Couldn't set interface name.\n"); warn("open_tun: Couldn't set interface name.\n");
return 1; return 1;
} }
@ -78,8 +82,10 @@ int
open_tun() open_tun()
{ {
if (tun_device != NULL) { if (tun_device != NULL) {
if ((tun_fd = open(tun_device, O_RDWR)) < 0) if ((tun_fd = open(tun_device, O_RDWR)) < 0) {
err(1, "open_tun: %s: %s", tun_device, strerror(errno)); warn("open_tun: %s: %s", tun_device, strerror(errno));
return 1;
}
} else { } else {
char tun_name[50]; char tun_name[50];
int i; int i;
@ -96,7 +102,8 @@ open_tun()
break; break;
} }
err(1, "open_tun: Failed to open tunneling device."); warn("open_tun: Failed to open tunneling device.");
return 1;
} }
return 0; return 0;
@ -114,8 +121,10 @@ close_tun()
int int
write_tun(uint8_t *buf, int len) write_tun(uint8_t *buf, int len)
{ {
if (write(tun_fd, buf, len) != len) if (write(tun_fd, buf, len) != len) {
err(1, "write_tun: %s", strerror(errno)); warn("write_tun: %s", strerror(errno));
return 1;
}
return 0; return 0;
} }