Files
vwifi/src/tools.cc
T
Guy Resheff 92df7a383a Upstream vwifi v7.0 (Raizo62/vwifi @ 4a9842e)
Unmodified upstream source from https://github.com/Raizo62/vwifi
Commit: 4a9842e "CMakeLists.txt : VERSION = 7.0"

Simulator of WiFi (802.11) interfaces to communicate between
several Virtual Machines via mac80211_hwsim + TCP relay.

License: Apache-2.0
2026-03-08 08:19:45 -07:00

72 lines
1.1 KiB
C++

#include <cstddef> // NULL
#include <arpa/inet.h> // struct sockaddr_in & inet_ntoa & ntohs
#include "tools.h"
#include <assert.h> // assert
bool HashUsesPort=false;
unsigned long hash_ipaddr(struct sockaddr_in* addr)
{
unsigned long res;
assert( addr != NULL );
res = (((addr->sin_addr.s_addr >> 24) & 0xff) * 256) +
(((addr->sin_addr.s_addr >> 16) & 0xff) * 256) +
(((addr->sin_addr.s_addr >> 8) & 0xff)* 256) +
(addr->sin_addr.s_addr & 0xff);
if( HashUsesPort )
res += addr->sin_port;
return res;
}
bool isInt(const char *str) {
if( *str == '-' || *str == '+' )
str++;
while (*str) {
if( *str < '0' || *str > '9' )
return false;
str++;
}
return true;
}
bool isPositiveInt(const char *str)
{
if( *str == '-' )
return false;
return isInt(str);
}
bool isIntOrFloat(const char *str) {
bool seeDot=false;
bool seeDigit=false;
if (*str == '-' || *str == '+')
str++;
while (*str) {
if( *str == '.' )
{
if( seeDot )
return false;
seeDot=true;
}
else
{
if( *str < '0' || *str > '9' )
return false;
seeDigit=true;
}
str++;
}
return seeDigit;
}