summaryrefslogtreecommitdiff
path: root/nuttx/arch/sim/src/up_tapdev.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-01-23 17:40:10 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-01-23 17:40:10 +0000
commit5541ec017e6dbdf6ca9c81ab58401579f94b01ec (patch)
tree559dbf5ee5030a970fbffb50af3a125a6b21071f /nuttx/arch/sim/src/up_tapdev.c
parent34ac2896338a1c4f3e953cdf13c2583c4ccf218c (diff)
downloadpx4-nuttx-5541ec017e6dbdf6ca9c81ab58401579f94b01ec.tar.gz
px4-nuttx-5541ec017e6dbdf6ca9c81ab58401579f94b01ec.tar.bz2
px4-nuttx-5541ec017e6dbdf6ca9c81ab58401579f94b01ec.zip
Incorporate uIP patches
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3274 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/sim/src/up_tapdev.c')
-rw-r--r--nuttx/arch/sim/src/up_tapdev.c78
1 files changed, 38 insertions, 40 deletions
diff --git a/nuttx/arch/sim/src/up_tapdev.c b/nuttx/arch/sim/src/up_tapdev.c
index 2c9d5c646..fd85a973e 100644
--- a/nuttx/arch/sim/src/up_tapdev.c
+++ b/nuttx/arch/sim/src/up_tapdev.c
@@ -1,8 +1,7 @@
-
/****************************************************************************
* up_tapdev.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Based on code from uIP which also has a BSD-like license:
@@ -39,7 +38,7 @@
*
****************************************************************************/
-#ifdef linux
+#ifndef CYGWIN
/****************************************************************************
* Included Files
@@ -63,6 +62,7 @@
#include <linux/net.h>
extern int lib_rawprintf(const char *format, ...);
+extern int uipdriver_setmacaddr(unsigned char *macaddr);
/****************************************************************************
* Private Definitions
@@ -133,17 +133,42 @@ static inline void dump_ethhdr(const char *msg, unsigned char *buf, int buflen)
# define dump_ethhdr(m,b,l)
#endif
+static int up_setmacaddr(void)
+{
+ unsigned char macaddr[6];
+ int ret = -1;
+ if (macaddr)
+ {
+ /* Get a socket (only so that we get access to the INET subsystem) */
+
+ int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sockfd >= 0)
+ {
+ struct ifreq req;
+ memset(&req, 0, sizeof(struct ifreq));
+
+ /* Put the driver name into the request */
+
+ strncpy(req.ifr_name, "tap0", IFNAMSIZ);
+
+ /* Perform the ioctl to get the MAC address */
+
+ ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req);
+ if (!ret)
+ {
+ /* Set the MAC address */
+
+ ret = uipdriver_setmacaddr(&req.ifr_hwaddr.sa_data);
+ }
+ }
+ }
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
-unsigned long up_getwalltime( void )
-{
- struct timeval tm;
- (void)gettimeofday(&tm, NULL);
- return tm.tv_sec*1000 + tm.tv_usec/1000;
-}
-
void tapdev_init(void)
{
struct ifreq ifr;
@@ -175,37 +200,10 @@ void tapdev_init(void)
snprintf(buf, sizeof(buf), "/sbin/ifconfig tap0 inet %d.%d.%d.%d\n",
UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3);
system(buf);
-}
-
-int tapdev_getmacaddr(unsigned char *macaddr)
-{
- int ret = -1;
- if (macaddr)
- {
- /* Get a socket (only so that we get access to the INET subsystem) */
-
- int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
- if (sockfd >= 0)
- {
- struct ifreq req;
- memset (&req, 0, sizeof(struct ifreq));
-
- /* Put the driver name into the request */
-
- strncpy(req.ifr_name, "tap0", IFNAMSIZ);
-
- /* Perform the ioctl to get the MAC address */
- ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req);
- if (!ret)
- {
- /* Return the MAC address */
+ /* Set the MAC address */
- memcpy(macaddr, &req.ifr_hwaddr.sa_data, IFHWADDRLEN);
- }
- }
- }
- return ret;
+ up_setmacaddr();
}
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
@@ -269,6 +267,6 @@ void tapdev_send(unsigned char *buf, unsigned int buflen)
dump_ethhdr("write", buf, buflen);
}
-#endif /* linux */
+#endif /* !CYGWIN */