stun

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

commit fc6e63001ac35a01eb4854e68068582a36224175
parent 280abdc491b629e2d774c843d34aeae5eeac536b
Author: sin <sin@2f30.org>
Date:   Thu, 17 Mar 2016 23:07:10 +0000

Make payload length 2 octets instead of 4

Diffstat:
Mstun.c | 18++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/stun.c b/stun.c @@ -25,7 +25,7 @@ #include "arg.h" -#define HDRLEN 4 +#define HDRLEN 2 #define MTU 1440 EVP_CIPHER_CTX enc, dec; @@ -136,18 +136,16 @@ readtun(int fd, unsigned char *buf, int len) } void -packint(unsigned char *buf, int n) +pack16(unsigned char *buf, int n) { - buf[0] = n >> 24 & 0xff; - buf[1] = n >> 16 & 0xff; - buf[2] = n >> 8 & 0xff; - buf[3] = n & 0xff; + buf[0] = n >> 8 & 0xff; + buf[1] = n & 0xff; } int -unpackint(unsigned char *buf) +unpack16(unsigned char *buf) { - return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + return (buf[0] << 8) | buf[1]; } /* handles partial writes */ @@ -180,7 +178,7 @@ writenet(int fd, unsigned char *buf, int len) int pktlen; pktlen = aesenc(&enc, &encbuf[HDRLEN], buf, len); - packint(encbuf, pktlen); + pack16(encbuf, pktlen); pktlen += HDRLEN; return writeall(fd, encbuf, pktlen); } @@ -218,7 +216,7 @@ readnet(int fd, unsigned char *buf, int len) n = readall(fd, hdr, sizeof(hdr)); if (n <= 0) return n; - pktlen = unpackint(hdr); + pktlen = unpack16(hdr); if (pktlen < 0 || pktlen > MTU + AES_BLOCK_SIZE) { warnx("bogus payload length: %d", pktlen); return -1;