wifi: Add wifi pointer NULL checks
[framework/connectivity/connman.git] / tools / tap-test.c
index 357d41e..1074c9c 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -23,6 +23,7 @@
 #include <config.h>
 #endif
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -43,7 +44,7 @@ static int inet_ifup(const char *ifname)
        struct ifreq ifr;
        int sk, err;
 
-       sk = socket(PF_INET, SOCK_DGRAM, 0);
+       sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
        if (sk < 0)
                return -errno;
 
@@ -80,7 +81,7 @@ static int create_tap(const char *ifname)
        struct ifreq ifr;
        int fd, val;
 
-       fd = open("/dev/net/tun", O_RDWR);
+       fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
        if (fd < 0) {
                perror("Failed to open TUN/TAP device");
                return -1;