On 11/12/15 01:15, Samuel Thibault wrote: > From: Guillaume Subiron <maet...@subiron.org> > > This patch makes solookup() compatible with varying address families. Also, > this function was only compatible with TCP. Having the socket list in > argument, it is now compatible with UDP too. Finally, some optimization > code is factorized inside the function (the function look at the last > returned result before browsing the complete socket list). > > This also adds a sockaddr_equal() function to compare two > sockaddr_storage.
I'd maybe also split this patch into two - first introduce the sockaddr_equal() function, then do the other changes. If you do too much stuff in one patch, it gets more difficult to read. > Signed-off-by: Guillaume Subiron <maet...@subiron.org> > Signed-off-by: Samuel Thibault <samuel.thiba...@ens-lyon.org> > --- [...] > diff --git a/slirp/socket.h b/slirp/socket.h > index b27bbb2..644216c 100644 > --- a/slirp/socket.h > +++ b/slirp/socket.h > @@ -87,7 +87,28 @@ struct socket { > #define SS_HOSTFWD 0x1000 /* Socket describes host->guest > forwarding */ > #define SS_INCOMING 0x2000 /* Connection was initiated by a host > on the internet */ > > -struct socket * solookup(struct socket *, struct in_addr, u_int, struct > in_addr, u_int); > +static inline int sockaddr_equal(struct sockaddr_storage *a, > + struct sockaddr_storage *b) > +{ > + if (a->ss_family != b->ss_family) { > + return 0; > + } else { > + switch (a->ss_family) { > + case AF_INET: > + { > + struct sockaddr_in *a4 = (struct sockaddr_in *) a; > + struct sockaddr_in *b4 = (struct sockaddr_in *) b; > + return (a4->sin_addr.s_addr == b4->sin_addr.s_addr > + && a4->sin_port == b4->sin_port); > + } > + default: > + assert(0); > + } > + } > +} Since the first part of the if statement always returns, you could get rid of one level of indentation here by removing the "else". Thomas