stun

simple point to point tunnel
git clone git://git.2f30.org/stun
Log | Files | Refs | README

commit b0a8fd65be5ea2d7c1024d06587c513cb952dfe7
parent 8f63d8c81b156b241cc104fe15caae35a97a35c9
Author: sin <sin@2f30.org>
Date:   Thu, 31 Mar 2016 11:12:33 +0100

sync

Diffstat:
Mstun.c | 17+++++------------
1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/stun.c b/stun.c @@ -79,12 +79,13 @@ #define NOPRIVUSER "nobody" #define CHALLENGETIMEO 1 /* in seconds */ #define RECONNECTTIMEO 60 /* in seconds */ +#define MTU 1412 #define HDRLEN 2 #define IVLEN 12 #define TAGLEN 16 +#define MAXPKTLEN (MTU + AES_BLOCK_SIZE + HDRLEN + IVLEN + TAGLEN) #define PKTLENMASK 0xfff #define BADPKT 0x8000 -#define MTU 1412 enum { TUNDEV, @@ -198,12 +199,8 @@ writeall(int fd, void *buf, int len) while (len > 0) { n = write(fd, p + total, len); - if (n < 0) { - logwarn("write failed"); - break; - } else if (n == 0) { + if (n <= 0) break; - } total += n; len -= n; } @@ -218,12 +215,8 @@ readall(int fd, void *buf, int len) while (len > 0) { n = read(fd, p + total, len); - if (n < 0) { - logwarn("read failed"); - break; - } else if (n == 0) { + if (n <= 0) break; - } total += n; len -= n; } @@ -486,7 +479,7 @@ writenet(int fd, unsigned char *pt, int len) { unsigned char payload[MTU + AES_BLOCK_SIZE]; unsigned char hdr[HDRLEN], iv[IVLEN], tag[TAGLEN]; - unsigned char pkt[MTU + AES_BLOCK_SIZE + HDRLEN + IVLEN + TAGLEN]; + unsigned char pkt[MAXPKTLEN]; arc4random_buf(iv, IVLEN); len = aesenc(&ectx, payload, pt, len, aeskey, iv, tag, TAGLEN);