diff options
author | Bin Jin <bjin@ctrl-d.org> | 2017-03-17 00:41:13 +0800 |
---|---|---|
committer | Bin Jin <bjin@ctrl-d.org> | 2017-03-17 00:41:13 +0800 |
commit | 1006b2f7417939380bde54bcd82c38b996f1e0b7 (patch) | |
tree | 133f914c83e604e2e0a180042c8b91a07dd93837 /cbits | |
parent | add flag for static build (diff) | |
download | wireguard-hs-1006b2f7417939380bde54bcd82c38b996f1e0b7.tar.xz wireguard-hs-1006b2f7417939380bde54bcd82c38b996f1e0b7.zip |
handle exception in openTun
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; } |