diff options
Diffstat (limited to 'cbits')
-rw-r--r-- | cbits/tun-linux.c | 5 | ||||
-rw-r--r-- | cbits/tun-macos.c | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/cbits/tun-linux.c b/cbits/tun-linux.c index adbd7c2..202e60d 100644 --- a/cbits/tun-linux.c +++ b/cbits/tun-linux.c @@ -1,5 +1,6 @@ #include <string.h> +#include <errno.h> #include <fcntl.h> #include <linux/if_tun.h> #include <net/if.h> @@ -12,8 +13,10 @@ int tun_alloc(const char *dev_name, int threads, int *fds) { struct ifreq ifr; int fd, i; - if (!dev_name) + if (!dev_name) { + errno = EINVAL; return -1; + } memset(&ifr, 0, sizeof(ifr)); diff --git a/cbits/tun-macos.c b/cbits/tun-macos.c index 7d57350..839ffe9 100644 --- a/cbits/tun-macos.c +++ b/cbits/tun-macos.c @@ -21,6 +21,7 @@ #include <string.h> #include <sys/types.h> +#include <errno.h> #include <net/if_utun.h> #include <netinet/ip.h> #include <sys/ioctl.h> @@ -36,14 +37,17 @@ int tun_alloc(const char *dev_name, int threads, int *fds) { struct sockaddr_ctl sc; int fd, utun_num; - if (!dev_name || sscanf(dev_name, "utun%d", &utun_num) != 1) + if (!dev_name || sscanf(dev_name, "utun%d", &utun_num) != 1) { + errno = EINVAL; return -1; + } memset(&ctlInfo, 0, sizeof(ctlInfo)); if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_name)) >= sizeof(ctlInfo.ctl_name)) { + errno = EINVAL; return -1; } |