netdev-bsd: Fix sign extension bug in ifr_flags on FreeBSD.
[cascardo/ovs.git] / lib / netdev-bsd.c
index 8291182..671de37 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013 Gaetano Catalli.
+ * Copyright (c) 2011, 2013, 2014 Gaetano Catalli.
  * Copyright (c) 2013, 2014 YAMAMOTO Takashi.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -714,7 +714,7 @@ netdev_bsd_send(struct netdev *netdev_, struct ofpbuf *pkt, bool may_steal)
                 }
             }
         } else if (retval != size) {
-            VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%"PRIuSIZE"d bytes of "
+            VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%"PRIuSIZE" bytes of "
                          "%"PRIuSIZE") on %s", retval, size, name);
             error = EMSGSIZE;
         } else {
@@ -996,7 +996,7 @@ netdev_bsd_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
                         netdev_get_name(netdev_), ovs_strerror(errno));
             return errno;
         } else if (!strcmp(ifmd.ifmd_name, netdev_get_name(netdev_))) {
-            convert_stats(netdev, stats, &ifdr.ifdr_data);
+            convert_stats(netdev_, stats, &ifmd.ifmd_data);
             break;
         }
     }
@@ -1771,7 +1771,7 @@ static int
 ifr_get_flags(const struct ifreq *ifr)
 {
 #ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
-    return (ifr->ifr_flagshigh << 16) | ifr->ifr_flags;
+    return (ifr->ifr_flagshigh << 16) | (ifr->ifr_flags & 0xffff);
 #else
     return ifr->ifr_flags;
 #endif
@@ -1780,12 +1780,15 @@ ifr_get_flags(const struct ifreq *ifr)
 static void
 ifr_set_flags(struct ifreq *ifr, int flags)
 {
-    ifr->ifr_flags = flags;
 #ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
+    ifr->ifr_flags = flags & 0xffff;
     ifr->ifr_flagshigh = flags >> 16;
+#else
+    ifr->ifr_flags = flags;
 #endif
 }
 
+#if defined(__NetBSD__)
 /* Calls ioctl() on an AF_LINK sock, passing the specified 'command' and
  * 'arg'.  Returns 0 if successful, otherwise a positive errno value. */
 int
@@ -1807,3 +1810,4 @@ af_link_ioctl(unsigned long command, const void *arg)
             : ioctl(sock, command, arg) == -1 ? errno
             : 0);
 }
+#endif