From 09c689ea15745df08492f9faaa89e3e1af9e2d58 Mon Sep 17 00:00:00 2001 From: dongjianli Date: Sun, 26 Aug 2018 15:37:03 -0600 Subject: [PATCH] net/icmp and icmpv6: Fix failure to poll ICMP socket issue. --- net/icmp/icmp_netpoll.c | 14 ++++++++++---- net/icmpv6/icmpv6_netpoll.c | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/net/icmp/icmp_netpoll.c b/net/icmp/icmp_netpoll.c index 0bd874109a..477f0b826c 100644 --- a/net/icmp/icmp_netpoll.c +++ b/net/icmp/icmp_netpoll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/icmp/icmp_netpoll.c * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2017-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include "netdev/netdev.h" #include "icmp/icmp.h" #ifdef CONFIG_MM_IOB @@ -182,7 +183,7 @@ int icmp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) FAR struct devif_callback_s *cb; int ret; - DEBUGASSERT(conn != NULL && fds != NULL && conn->dev != NULL); + DEBUGASSERT(conn != NULL && fds != NULL); /* Allocate a container to hold the poll information */ @@ -201,6 +202,11 @@ int icmp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) * dev value will be zero and there will be no NETDEV_DOWN notifications. */ + if (conn->dev == NULL) + { + conn->dev = netdev_default(); + } + /* Allocate a ICMP callback structure */ cb = icmp_callback_alloc(conn->dev); @@ -227,12 +233,12 @@ int icmp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) if ((info->fds->events & POLLOUT) != 0) { - cb->flags |= UDP_POLL; + cb->flags |= ICMP_POLL; } if ((info->fds->events & POLLIN) != 0) { - cb->flags |= UDP_NEWDATA; + cb->flags |= ICMP_NEWDATA; } if ((info->fds->events & (POLLHUP | POLLERR)) != 0) diff --git a/net/icmpv6/icmpv6_netpoll.c b/net/icmpv6/icmpv6_netpoll.c index 75dcf428f1..3ec551a61c 100644 --- a/net/icmpv6/icmpv6_netpoll.c +++ b/net/icmpv6/icmpv6_netpoll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/icmpv6/icmpv6_netpoll.c * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2017-2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include "netdev/netdev.h" #include "icmpv6/icmpv6.h" #ifdef CONFIG_MM_IOB @@ -182,7 +183,7 @@ int icmpv6_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) FAR struct devif_callback_s *cb; int ret; - DEBUGASSERT(conn != NULL && fds != NULL && conn->dev != NULL); + DEBUGASSERT(conn != NULL && fds != NULL); /* Allocate a container to hold the poll information */ @@ -203,6 +204,11 @@ int icmpv6_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) /* Allocate a ICMP callback structure */ + if (conn->dev == NULL) + { + conn->dev = netdev_default(); + } + cb = icmpv6_callback_alloc(conn->dev); if (cb == NULL) { @@ -227,12 +233,12 @@ int icmpv6_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) if ((info->fds->events & POLLOUT) != 0) { - cb->flags |= UDP_POLL; + cb->flags |= ICMPv6_POLL; } if ((info->fds->events & POLLIN) != 0) { - cb->flags |= UDP_NEWDATA; + cb->flags |= ICMPv6_NEWDATA; } if ((info->fds->events & (POLLHUP | POLLERR)) != 0)