stun

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

commit 7b1a80054e6943011c526a34e01bb8e7946be4dd
parent e062a5479f020a21d8a8b81dab1d1266a4d07e7e
Author: sin <sin@2f30.org>
Date:   Thu, 17 Mar 2016 19:38:15 +0000

Fix signed/unsigned stuff

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

diff --git a/stun.c b/stun.c @@ -98,12 +98,12 @@ opentun(char *tundev) return fd; } -ssize_t -writetun(int fd, unsigned char *buf, size_t len) +int +writetun(int fd, unsigned char *buf, int len) { struct iovec iov[2]; uint32_t type = htonl(AF_INET); - ssize_t n; + int n; iov[0].iov_base = &type; iov[0].iov_len = sizeof(type); @@ -117,12 +117,12 @@ writetun(int fd, unsigned char *buf, size_t len) return n; } -ssize_t -readtun(int fd, unsigned char *buf, size_t len) +int +readtun(int fd, unsigned char *buf, int len) { struct iovec iov[2]; uint32_t type; - ssize_t n; + int n; iov[0].iov_base = &type; iov[0].iov_len = sizeof(type); @@ -153,13 +153,13 @@ unpackint(unsigned char *buf) /* handles partial writes */ int -writeall(int fd, void *buf, int count) +writeall(int fd, void *buf, int len) { unsigned char *p = buf; int n, total = 0; - while (count > 0) { - n = write(fd, p + total, count); + while (len > 0) { + n = write(fd, p + total, len); if (n < 0) { warn("write"); total = -1; @@ -168,19 +168,19 @@ writeall(int fd, void *buf, int count) break; } total += n; - count -= n; + len -= n; } return total; } /* encrypt a packet and send it to the remote peer */ int -writenet(int fd, unsigned char *buf, int buflen) +writenet(int fd, unsigned char *buf, int len) { unsigned char encbuf[MTU + AES_BLOCK_SIZE + HDRLEN]; int pktlen; - pktlen = aesenc(&enc, &encbuf[HDRLEN], buf, buflen); + pktlen = aesenc(&enc, &encbuf[HDRLEN], buf, len); packint(encbuf, pktlen); pktlen += HDRLEN; return writeall(fd, encbuf, pktlen); @@ -188,13 +188,13 @@ writenet(int fd, unsigned char *buf, int buflen) /* handles partial reads */ int -readall(int fd, void *buf, int count) +readall(int fd, void *buf, int len) { unsigned char *p = buf; int n, total = 0; - while (count > 0) { - n = read(fd, p + total, count); + while (len > 0) { + n = read(fd, p + total, len); if (n < 0) { warn("read"); total = -1; @@ -203,14 +203,14 @@ readall(int fd, void *buf, int count) break; } total += n; - count -= n; + len -= n; } return total; } /* read a packet from the remote peer, decrypt it and pass it back through buf */ int -readnet(int fd, unsigned char *buf, int count) +readnet(int fd, unsigned char *buf, int len) { unsigned char decbuf[MTU + AES_BLOCK_SIZE + HDRLEN]; unsigned char hdr[HDRLEN];