print error message if user tried to run hcxdumptool on NETLINK interface
@@ -253,7 +253,7 @@ if(fp)
pidptr = fgets(pidline, 1024, fp);
if(pidptr != NULL)
{
- printf("warning: %s is running with pid %s", &unwantedname[6], pidline);
+ fprintf(stderr, "warning: %s is running with pid %s", &unwantedname[6], pidline);
}
pclose(fp);
}
@@ -4658,7 +4658,7 @@ fd_socket_gpsd = 0;
checkallunwanted();
if(checkmonitorinterface(interfacename) == true)
{
- printf("warning: %s is probably a monitor interface\n", interfacename);
+ fprintf(stderr, "warning: %s is probably a monitor interface\n", interfacename);
}
if((fd_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
@@ -4667,6 +4667,8 @@ if((fd_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
return false;
}
+
+
memset(&ifr_old, 0, sizeof(ifr));
strncpy(ifr_old.ifr_name, interfacename, IFNAMSIZ -1);
if(ioctl(fd_socket, SIOCGIFFLAGS, &ifr_old) < 0)
@@ -4811,6 +4813,35 @@ if((fd_socket_gpsd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return true;
}
/*===========================================================================*/
+static bool testinterface()
+{
+static struct ifaddrs *ifaddr = NULL;
+static struct ifaddrs *ifa = NULL;
+
+if(getifaddrs(&ifaddr) == -1)
+ {
+ perror("failed to get ifaddrs");
+ return false;
+ }
+else
+ {
+ for(ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
+ {
+ if(ifa->ifa_addr)
+ {
+ if(strncmp(ifa->ifa_name, interfacename, IFNAMSIZ) == 0)
+ {
+ if(ifa->ifa_addr->sa_family == AF_PACKET)
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+return false;
+}
+/*===========================================================================*/
static bool get_perm_addr(char *ifname, uint8_t *permaddr, char *drivername)
{
static int fd_info;
@@ -5431,6 +5462,12 @@ if(getuid() != 0)
exit(EXIT_FAILURE);
}
+if(testinterface() == false)
+ {
+ fprintf(stderr, "interface is not useable\n");
+ exit(EXIT_FAILURE);
+ }
+
printf("initialization...\n");
if(opensocket() == false)
{
