stun

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

commit c2534b1060fe2c141dee3aa4bda7c7df91baa97d
parent 3f1e4aa56e270874e4e353889bb60f0e329669f1
Author: sin <sin@2f30.org>
Date:   Thu, 31 Mar 2016 16:48:44 +0100

get rid of setrcvtimeo()

Diffstat:
Mstun.c | 21++++++---------------
1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/stun.c b/stun.c @@ -229,19 +229,6 @@ ms2tv(struct timeval *tv, long ms) tv->tv_usec = (ms % 1000) * 1000; } -int -setrcvtimeo(int fd, long ms) -{ - struct timeval tv; - int ret; - - ms2tv(&tv, ms); - ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) - logwarn("failed to set timeout on socket"); - return ret; -} - void revokeprivs(void) { @@ -631,6 +618,7 @@ serversetup(int devfd) { struct addrinfo hints, *ai, *p; struct sockaddr_in remote; + struct timeval tv; int ret, netfd, listenfd; memset(&hints, 0, sizeof(hints)); @@ -673,7 +661,8 @@ serversetup(int devfd) logdbg("remote peer connected: %s", inet_ntoa(remote.sin_addr)); - setrcvtimeo(netfd, RCVTIMEO); + ms2tv(&tv, RCVTIMEO); + setsockopt(netfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); setsockopt(netfd, IPPROTO_TCP, TCP_NODELAY, (int []){1}, sizeof(int)); ret = challenge(netfd); @@ -701,6 +690,7 @@ int clientsetup(int devfd) { struct addrinfo hints, *ai, *p; + struct timeval tv; int ret, netfd; memset(&hints, 0, sizeof(hints)); @@ -728,7 +718,8 @@ clientsetup(int devfd) return -1; } - setrcvtimeo(netfd, RCVTIMEO); + ms2tv(&tv, RCVTIMEO); + setsockopt(netfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); setsockopt(netfd, IPPROTO_TCP, TCP_NODELAY, (int []){1}, sizeof(int)); if (debug)