qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 06/18] slirp: Factorizing and cleaning solookup(


From: Thomas Huth
Subject: Re: [Qemu-devel] [PATCH 06/18] slirp: Factorizing and cleaning solookup()
Date: Fri, 11 Dec 2015 16:06:22 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 11/12/15 01:15, Samuel Thibault wrote:
> From: Guillaume Subiron <address@hidden>
> 
> 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 <address@hidden>
> Signed-off-by: Samuel Thibault <address@hidden>
> ---
[...]
> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]