[ovs-dev] [PATCH 14/14] Add sockaddr_nl back to netlink-protocol.h

Ben Pfaff blp at nicira.com
Tue Jul 15 16:53:42 UTC 2014


On Fri, Jul 11, 2014 at 01:08:48AM +0000, Alin Serdean wrote:
> Add the structure sockaddr_nl to netlink-protocol.h for MSVC. Also remove
> some warnings in netlink-socket.c when using MSVC.
> 
> Signed-off-by: Alin Gabriel Serdean <aserdean at cloudbasesolutions.com>

I think that nl_sock always uses 'fd' as a HANDLE on Windows and as an
file descriptor elsewhere.  It would avoid casts to declare it as a
HANDLE on Windows rather than an int (and possible rename it to
'handle' or similar there).

I think that only netlink-socket.c uses sockaddr_nl, so it might make
sense to define it there.

> ---
>  lib/netlink-protocol.h | 10 ++++++++++
>  lib/netlink-socket.c   |  4 ++--
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/netlink-protocol.h b/lib/netlink-protocol.h
> index ea1b872..2a35e6b 100644
> --- a/lib/netlink-protocol.h
> +++ b/lib/netlink-protocol.h
> @@ -40,6 +40,16 @@
>  #else
>  #define NETLINK_GENERIC         16
>  
> +#ifdef _WIN32
> +struct sockaddr_nl {
> +    sa_family_t nl_family;
> +    unsigned short int nl_pad;
> +    uint32_t nl_pid;
> +    uint32_t nl_groups;
> +};
> +BUILD_ASSERT_DECL(sizeof(struct sockaddr_nl) == 12);
> +#endif
> +
>  /* nlmsg_flags bits. */
>  #define NLM_F_REQUEST           0x001
>  #define NLM_F_MULTI             0x002
> diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c
> index a320895..156fe89 100644
> --- a/lib/netlink-socket.c
> +++ b/lib/netlink-socket.c
> @@ -150,7 +150,7 @@ nl_sock_create(int protocol, struct nl_sock **sockp)
>                                 FILE_SHARE_READ | FILE_SHARE_WRITE,
>                                 NULL, OPEN_EXISTING,
>                                 FILE_ATTRIBUTE_NORMAL, NULL);
> -    sock->fd = hConn;
> +    sock->fd = (int)hConn;
>  #else
>      sock->fd = socket(AF_NETLINK, SOCK_RAW, protocol);
>      if (sock->fd < 0) {
> @@ -190,7 +190,7 @@ nl_sock_create(int protocol, struct nl_sock **sockp)
>      remote.nl_pid = 0;
>      if (connect(sock->fd, (struct sockaddr *) &remote, sizeof remote) < 0) {
>  #else
> -    if (sock->fd == INVALID_HANDLE_VALUE) {
> +    if (((HANDLE)sock->fd) == INVALID_HANDLE_VALUE) {
>  #endif
>          VLOG_ERR("connect(0): %s", ovs_strerror(errno));
>          goto error;
> -- 
> 1.9.0.msysgit.0
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev



More information about the dev mailing list