commit dece4a841bcbda6b10b5ec0ab944a88c79b89e9e
parent 50f2f564028ce0f1e114a1ec7fc592c77c3f3f45
Author: sin <sin@2f30.org>
Date: Thu, 24 Mar 2016 10:25:18 +0000
unify error handling for tun tap
we are not supposed to fail reading/writing from/to these devices
Diffstat:
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/stun.c b/stun.c
@@ -254,8 +254,12 @@ writedev(int fd, unsigned char *buf, int len)
uint32_t type = htonl(AF_INET);
int n;
- if (devtype == TAPDEV)
- return write(fd, buf, len);
+ if (devtype == TAPDEV) {
+ n = write(fd, buf, len);
+ if (n < 0)
+ logerr("write failed");
+ return n;
+ }
iov[0].iov_base = &type;
iov[0].iov_len = sizeof(type);
@@ -276,8 +280,12 @@ readdev(int fd, unsigned char *buf, int len)
uint32_t type;
int n;
- if (devtype == TAPDEV)
- return read(fd, buf, len);
+ if (devtype == TAPDEV) {
+ n = read(fd, buf, len);
+ if (n < 0)
+ logerr("read failed");
+ return n;
+ }
iov[0].iov_base = &type;
iov[0].iov_len = sizeof(type);