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/tun-macos.c | |
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/tun-macos.c')
-rw-r--r-- | cbits/tun-macos.c | 6 |
1 files changed, 5 insertions, 1 deletions
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; } |