From fa3ad468976c2c393355e0957a049ef686ed14fe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Jan 2018 18:46:58 -0600 Subject: [PATCH] net/udp: In sendto(), return EHOSTUNREACH if if the network is down. --- net/udp/udp_psock_sendto_buffered.c | 8 ++++++++ net/udp/udp_psock_sendto_unbuffered.c | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/net/udp/udp_psock_sendto_buffered.c b/net/udp/udp_psock_sendto_buffered.c index 3f5e5305b4..b9a8a89189 100644 --- a/net/udp/udp_psock_sendto_buffered.c +++ b/net/udp/udp_psock_sendto_buffered.c @@ -384,6 +384,14 @@ static int sendto_next_transfer(FAR struct socket *psock, return -ENETUNREACH; } + /* Make sure that the device is in the UP state */ + + if ((dev->d_flags & IFF_UP) == 0) + { + nwarn("WARNING: device is DOWN\n"); + return -EHOSTUNREACH; + } + /* If this is not the same device that we used in the last call to * udp_callback_alloc(), then we need to release and reallocate the old * callback instance. diff --git a/net/udp/udp_psock_sendto_unbuffered.c b/net/udp/udp_psock_sendto_unbuffered.c index 809ee2ce9e..7024d12baf 100644 --- a/net/udp/udp_psock_sendto_unbuffered.c +++ b/net/udp/udp_psock_sendto_unbuffered.c @@ -424,6 +424,15 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, goto errout_with_lock; } + /* Make sure that the device is in the UP state */ + + if ((dev->d_flags & IFF_UP) == 0) + { + nwarn("WARNING: device is DOWN\n"); + ret = -EHOSTUNREACH; + goto errout_with_lock; + } + /* Set up the callback in the connection */ state.st_cb = udp_callback_alloc(dev, conn);