summaryrefslogtreecommitdiff
path: root/nuttx/net/netdev_findbyaddr.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-03-20 17:27:59 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-03-20 17:27:59 -0600
commitfb240b8d5d01ea6587eb7355c33c9a96aa18942f (patch)
treef18d3cf6407bee0bf9947de69616b10c75762443 /nuttx/net/netdev_findbyaddr.c
parent66f2da8de179bf8be875830ffaaba09232bd7421 (diff)
downloadnuttx-fb240b8d5d01ea6587eb7355c33c9a96aa18942f.tar.gz
nuttx-fb240b8d5d01ea6587eb7355c33c9a96aa18942f.tar.bz2
nuttx-fb240b8d5d01ea6587eb7355c33c9a96aa18942f.zip
net/netdev_findbyaddr.c: Skip network devices that are in the down state. They have no meaning address
Diffstat (limited to 'nuttx/net/netdev_findbyaddr.c')
-rw-r--r--nuttx/net/netdev_findbyaddr.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/nuttx/net/netdev_findbyaddr.c b/nuttx/net/netdev_findbyaddr.c
index 8ca1ae3b2..dbfea28cc 100644
--- a/nuttx/net/netdev_findbyaddr.c
+++ b/nuttx/net/netdev_findbyaddr.c
@@ -1,7 +1,7 @@
/****************************************************************************
* net/netdev_findbyaddr.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -55,7 +55,7 @@
****************************************************************************/
/****************************************************************************
- * Priviate Types
+ * Private Types
****************************************************************************/
/****************************************************************************
@@ -79,7 +79,8 @@
*
* Description:
* Find a previously registered network device by matching a local address
- * with the subnet served by the device
+ * with the subnet served by the device. Only "up" devices are considered
+ * (since a "down" device has no meaningful address).
*
* Parameters:
* addr - Pointer to the remote address of a connection
@@ -95,17 +96,36 @@
static FAR struct uip_driver_s *netdev_finddevice(const uip_ipaddr_t addr)
{
struct uip_driver_s *dev;
+ uint8_t iff;
+
+ /* Examine each registered network device */
netdev_semtake();
for (dev = g_netdevices; dev; dev = dev->flink)
{
- if (uip_ipaddr_maskcmp(dev->d_ipaddr, addr, dev->d_netmask))
+ /* Get the interface flags */
+
+ if (uip_getifstatus(dev->d_ifname, &iff) == OK)
{
- netdev_semgive();
- return dev;
+ /* Is the interface in the "up" state? */
+
+ if ((iff & IFF_UP) != 0)
+ {
+ /* Yes.. check for an address match (under the netmask) */
+
+ if (uip_ipaddr_maskcmp(dev->d_ipaddr, addr, dev->d_netmask))
+ {
+ /* Its a match */
+
+ netdev_semgive();
+ return dev;
+ }
+ }
}
}
+ /* No device with the matching address found */
+
netdev_semgive();
return NULL;
}