From: Ian Jackson Date: Sat, 27 Sep 2014 14:01:05 +0000 (+0100) Subject: udp: Introduce some `us' convenience variables, etc. X-Git-Tag: proposed.polypath.v1~8 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=3662bc5f8734c05b258e8b9a0ef3ff0148b25cc7;p=secnet.git udp: Introduce some `us' convenience variables, etc. * Introduce appropriate `struct udpsock *us' in a few places, and use them as appropriate. We are going to make a few more places where these are used and this avoids some repetition. * Introduce an `af' variable for the intended destination address family at one point. We are going to want to reuse this. * Add a comment on a line `} else {' distant from its `if (..) {'. No functional change. Signed-off-by: Ian Jackson --- diff --git a/udp.c b/udp.c index 14ba078..352756c 100644 --- a/udp.c +++ b/udp.c @@ -73,10 +73,11 @@ static void udp_socks_afterpoll(void *state, struct pollfd *fds, int nfds) struct commcommon *cc=&uc->cc; for (i=0; in_socks; i++) { + struct udpsock *us=&socks->socks[i]; if (i>=nfds) continue; if (!(fds[i].revents & POLLIN)) continue; - assert(fds[i].fd == socks->socks[i].fd); - int fd=socks->socks[i].fd; + assert(fds[i].fd == us->fd); + int fd=us->fd; do { FILLZERO(from); fromlen=sizeof(from); @@ -125,7 +126,7 @@ static void udp_socks_afterpoll(void *state, struct pollfd *fds, int nfds) BUF_FREE(cc->rbuf); } BUF_ASSERT_FREE(cc->rbuf); - } else { + } else { /* rv<=0 */ BUF_FREE(cc->rbuf); } } while (rv>=0); @@ -141,6 +142,7 @@ static bool_t udp_sendmsg(void *commst, struct buffer_if *buf, uint8_t *sa; if (uc->use_proxy) { + struct udpsock *us=&socks->socks[0]; sa=buf_prepend(buf,8); if (dest->ia.sa.sa_family != AF_INET) { Message(M_INFO, @@ -151,17 +153,19 @@ static bool_t udp_sendmsg(void *commst, struct buffer_if *buf, memcpy(sa,&dest->ia.sin.sin_addr,4); memset(sa+4,0,4); memcpy(sa+6,&dest->ia.sin.sin_port,2); - sendto(socks->socks[0].fd,sa,buf->size+8,0,(struct sockaddr *)&uc->proxy, + sendto(us->fd,sa,buf->size+8,0,(struct sockaddr *)&uc->proxy, sizeof(uc->proxy)); buf_unprepend(buf,8); } else { int i,r; bool_t allunsupported=True; + int af=dest->ia.sa.sa_family; for (i=0; in_socks; i++) { - if (dest->ia.sa.sa_family != socks->socks[i].addr.sa.sa_family) + struct udpsock *us=&socks->socks[i]; + if (us->addr.sa.sa_family != af) /* no point even trying */ continue; - r=sendto(socks->socks[i].fd, buf->start, buf->size, 0, + r=sendto(us->fd, buf->start, buf->size, 0, &dest->ia.sa, iaddr_socklen(&dest->ia)); if (!r) return True; if (!(errno==EAFNOSUPPORT || errno==ENETUNREACH))