diff --git a/CMakeLists.txt b/CMakeLists.txt index 104a402..ac8f57d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,7 @@ IF(WIN32) SET(LIBTINS_OS_LIBS Ws2_32.lib Iphlpapi.lib) # Add the NOMINMAX macro to avoid Windows' min and max macros. - # While compiling on windows, for some reason, WIN32 is not defined, - # maybe we could fix this later, but it's OK for now. - ADD_DEFINITIONS(-DNOMINMAX -DWIN32) + ADD_DEFINITIONS(-DNOMINMAX) ENDIF(WIN32) # ******************* diff --git a/include/tins/dot11/dot11_base.h b/include/tins/dot11/dot11_base.h index 93723df..f4c4f7b 100644 --- a/include/tins/dot11/dot11_base.h +++ b/include/tins/dot11/dot11_base.h @@ -382,12 +382,12 @@ public: */ uint32_t header_size() const; - #ifndef WIN32 + #ifndef _WIN32 /** * \sa PDU::send() */ void send(PacketSender &sender, const NetworkInterface &iface); - #endif // WIN32 + #endif // _WIN32 /** * \brief Adds a new option to this Dot11 PDU. diff --git a/include/tins/dot3.h b/include/tins/dot3.h index 4d4fa11..7f0493e 100644 --- a/include/tins/dot3.h +++ b/include/tins/dot3.h @@ -138,12 +138,12 @@ namespace Tins { */ uint32_t header_size() const; - #if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) + #if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) /** * \sa PDU::send() */ void send(PacketSender &sender, const NetworkInterface &iface); - #endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET + #endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET /** * \brief Check wether ptr points to a valid response for this PDU. @@ -154,12 +154,12 @@ namespace Tins { */ bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; - #ifndef WIN32 + #ifndef _WIN32 /** * \sa PDU::recv_response */ PDU *recv_response(PacketSender &sender, const NetworkInterface &iface); - #endif // WIN32 + #endif // _WIN32 /** * \brief Getter for the PDU's type. diff --git a/include/tins/endianness.h b/include/tins/endianness.h index 579c163..16f6359 100644 --- a/include/tins/endianness.h +++ b/include/tins/endianness.h @@ -41,7 +41,7 @@ #include #define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) #define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN) -#elif defined(WIN32) +#elif defined(_WIN32) // Assume windows == little endian. fixme later #define TINS_IS_LITTLE_ENDIAN 1 #define TINS_IS_BIG_ENDIAN 0 diff --git a/include/tins/ethernetII.h b/include/tins/ethernetII.h index cebded6..74855ec 100644 --- a/include/tins/ethernetII.h +++ b/include/tins/ethernetII.h @@ -160,14 +160,14 @@ namespace Tins { */ bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; - #ifndef WIN32 + #ifndef _WIN32 /** * \brief Receives a matching response for this packet. * * \sa PDU::recv_response */ PDU *recv_response(PacketSender &sender, const NetworkInterface &iface); - #endif // WIN32 + #endif // _WIN32 /** * \brief Getter for the PDU's type. diff --git a/include/tins/icmp.h b/include/tins/icmp.h index cc91255..69808b2 100644 --- a/include/tins/icmp.h +++ b/include/tins/icmp.h @@ -32,7 +32,7 @@ // Windows likes to define macros with not-so-common-names, which break // this code -#ifdef WIN32 +#ifdef _WIN32 #ifdef TIMESTAMP_REQUEST #undef TIMESTAMP_REQUEST #endif // TIMESTAMP_REQUEST @@ -40,7 +40,7 @@ #ifdef TIMESTAMP_REPLY #undef TIMESTAMP_REPLY #endif // TIMESTAMP_REPLY -#endif // WIN32 +#endif // _WIN32 #include "macros.h" #include "pdu.h" diff --git a/include/tins/packet_sender.h b/include/tins/packet_sender.h index 8689f23..d3d8ed0 100644 --- a/include/tins/packet_sender.h +++ b/include/tins/packet_sender.h @@ -159,7 +159,7 @@ namespace Tins { PacketSender& operator=(PacketSender &&rhs) TINS_NOEXCEPT { _sockets = std::move(rhs._sockets); rhs._sockets = std::vector(SOCKETS_END, INVALID_RAW_SOCKET); - #ifndef WIN32 + #ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) _ether_socket = std::move(rhs._ether_socket); #else @@ -182,14 +182,14 @@ namespace Tins { */ ~PacketSender(); - #if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) + #if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) /** * \brief Opens a layer 2 socket. * * If this operation fails, then a socket_open_error will be thrown. */ void open_l2_socket(const NetworkInterface& iface = NetworkInterface()); - #endif // !WIN32 || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) + #endif // !_WIN32 || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) /** * \brief Opens a layer 3 socket, using the corresponding protocol @@ -302,7 +302,7 @@ namespace Tins { */ PDU *send_recv(PDU &pdu, const NetworkInterface &iface); - #ifndef WIN32 + #ifndef _WIN32 /** * \brief Receives a layer 2 PDU response to a previously sent PDU. * @@ -320,9 +320,9 @@ namespace Tins { PDU *recv_l2(PDU &pdu, struct sockaddr *link_addr, uint32_t len_addr, const NetworkInterface &iface = NetworkInterface()); - #endif // WIN32 + #endif // _WIN32 - #if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) + #if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) /** * \brief Sends a level 2 PDU. * @@ -340,7 +340,7 @@ namespace Tins { */ void send_l2(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, const NetworkInterface &iface = NetworkInterface()); - #endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET + #endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET /** * \brief Receives a layer 3 PDU response to a previously sent PDU. @@ -383,7 +383,7 @@ namespace Tins { PacketSender& operator=(const PacketSender&); int find_type(SocketType type); int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y); - #ifndef WIN32 + #ifndef _WIN32 bool ether_socket_initialized(const NetworkInterface& iface = NetworkInterface()) const; int get_ether_socket(const NetworkInterface& iface = NetworkInterface()); #endif @@ -399,7 +399,7 @@ namespace Tins { uint32_t addrlen); std::vector _sockets; - #ifndef WIN32 + #ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) typedef std::map BSDEtherSockets; BSDEtherSockets _ether_socket; diff --git a/include/tins/radiotap.h b/include/tins/radiotap.h index caf9ccd..be1811b 100644 --- a/include/tins/radiotap.h +++ b/include/tins/radiotap.h @@ -141,7 +141,7 @@ namespace Tins { /* Setters */ - #ifndef WIN32 + #ifndef _WIN32 /** * \sa PDU::send() */ diff --git a/include/tins/timestamp.h b/include/tins/timestamp.h index 6911767..4227bc1 100644 --- a/include/tins/timestamp.h +++ b/include/tins/timestamp.h @@ -30,7 +30,7 @@ #ifndef TINS_TIMESTAMP_H #define TINS_TIMESTAMP_H -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -46,7 +46,7 @@ namespace Tins { */ class Timestamp { public: - #ifdef WIN32 + #ifdef _WIN32 typedef long seconds_type; typedef long microseconds_type; #else @@ -58,7 +58,7 @@ public: * \brief Constructs a Timestamp which will hold the current time. */ static Timestamp current_time() { - #ifdef WIN32 + #ifdef _WIN32 //fixme return Timestamp(); #else diff --git a/include/tins/utils.h b/include/tins/utils.h index e6d45f7..6b67903 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -30,7 +30,7 @@ #ifndef TINS_UTILS_H #define TINS_UTILS_H -#ifndef WIN32 +#ifndef _WIN32 #include #else #include @@ -248,7 +248,7 @@ namespace Tins { * the object to collect data from them. * \param functor An instance of an class which implements operator(struct ifaddrs*). */ - #ifndef WIN32 + #ifndef _WIN32 template void generic_iface_loop(Functor &functor) { struct ifaddrs *ifaddrs = 0; @@ -261,7 +261,7 @@ namespace Tins { if(ifaddrs) freeifaddrs(ifaddrs); } - #else // WIN32 + #else // _WIN32 template void generic_iface_loop(Functor &functor) { ULONG size; @@ -276,7 +276,7 @@ namespace Tins { } } } - #endif // WIN32 + #endif // _WIN32 template struct is_pdu { @@ -376,7 +376,7 @@ void Tins::Utils::route_entries(ForwardIterator output) { next += rtm->rtm_msglen; } } -#elif defined(WIN32) +#elif defined(_WIN32) template void Tins::Utils::route_entries(ForwardIterator output) { MIB_IPFORWARDTABLE *table; diff --git a/src/dot11/dot11_base.cpp b/src/dot11/dot11_base.cpp index feb2816..3de49de 100644 --- a/src/dot11/dot11_base.cpp +++ b/src/dot11/dot11_base.cpp @@ -39,7 +39,7 @@ #include "macros.h" #include "exceptions.h" -#ifndef WIN32 +#ifndef _WIN32 #if defined(__FreeBSD_kernel__) || defined(BSD) || defined(__APPLE__) #include #include @@ -171,7 +171,7 @@ uint32_t Dot11::header_size() const { return sz; } -#ifndef WIN32 +#ifndef _WIN32 void Dot11::send(PacketSender &sender, const NetworkInterface &iface) { if(!iface) throw invalid_interface(); @@ -191,7 +191,7 @@ void Dot11::send(PacketSender &sender, const NetworkInterface &iface) { sender.send_l2(*this, 0, 0, iface); #endif } -#endif // WIN32 +#endif // _WIN32 void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { #ifdef TINS_DEBUG diff --git a/src/dot3.cpp b/src/dot3.cpp index bc5e1e8..36f54e5 100644 --- a/src/dot3.cpp +++ b/src/dot3.cpp @@ -34,7 +34,7 @@ #include #include #include "macros.h" -#ifndef WIN32 +#ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) #include #else @@ -87,7 +87,7 @@ uint32_t Dot3::header_size() const { return sizeof(ethhdr); } -#if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) +#if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) void Dot3::send(PacketSender &sender, const NetworkInterface &iface) { if(!iface) throw invalid_interface(); @@ -108,7 +108,7 @@ void Dot3::send(PacketSender &sender, const NetworkInterface &iface) { sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr)); #endif } -#endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET +#endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET bool Dot3::matches_response(const uint8_t *ptr, uint32_t total_sz) const { if(total_sz < sizeof(ethhdr)) @@ -135,7 +135,7 @@ void Dot3::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *pa memcpy(buffer, &_eth, sizeof(ethhdr)); } -#ifndef WIN32 +#ifndef _WIN32 PDU *Dot3::recv_response(PacketSender &sender, const NetworkInterface &iface) { if(!iface) throw invalid_interface(); @@ -154,5 +154,5 @@ PDU *Dot3::recv_response(PacketSender &sender, const NetworkInterface &iface) { return sender.recv_l2(*this, 0, 0, iface); #endif } -#endif // WIN32 +#endif // _WIN32 } diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index dfd430d..99721ab 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -34,7 +34,7 @@ #include #include #include "macros.h" -#ifndef WIN32 +#ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) #include #else @@ -118,7 +118,7 @@ void EthernetII::send(PacketSender &sender, const NetworkInterface &iface) { #if defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) || defined(BSD) || defined(__FreeBSD_kernel__) // Sending using pcap_sendpacket/BSD bpf packet mode is the same here sender.send_l2(*this, 0, 0, iface); - #elif defined(WIN32) + #elif defined(_WIN32) // On Windows we can only send l2 PDUs using pcap_sendpacket throw std::runtime_error("LIBTINS_USE_PCAP_SENDPACKET is not enabled"); #else @@ -174,7 +174,7 @@ void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const P } -#ifndef WIN32 +#ifndef _WIN32 PDU *EthernetII::recv_response(PacketSender &sender, const NetworkInterface &iface) { #if !defined(BSD) && !defined(__FreeBSD_kernel__) struct sockaddr_ll addr; @@ -191,5 +191,5 @@ PDU *EthernetII::recv_response(PacketSender &sender, const NetworkInterface &ifa return sender.recv_l2(*this, 0, 0, iface); #endif } -#endif // WIN32 +#endif // _WIN32 } diff --git a/src/icmp.cpp b/src/icmp.cpp index dfb4ea5..43145ec 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -32,7 +32,7 @@ #ifdef TINS_DEBUG #include #endif -#ifndef WIN32 +#ifndef _WIN32 #include #endif #include "rawpdu.h" diff --git a/src/ip.cpp b/src/ip.cpp index f1d6bfc..dc377b9 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -33,7 +33,7 @@ #include #endif #include -#ifndef WIN32 +#ifndef _WIN32 #include #include #include diff --git a/src/ip_address.cpp b/src/ip_address.cpp index f05f6dd..ce3e06e 100644 --- a/src/ip_address.cpp +++ b/src/ip_address.cpp @@ -27,12 +27,12 @@ * */ -#ifdef WIN32 +#ifdef _WIN32 #include -#else // WIN32 +#else // _WIN32 #include #include -#endif // WIN32 +#endif // _WIN32 #include #include #include "ip_address.h" @@ -78,7 +78,7 @@ std::string IPv4Address::to_string() const { } uint32_t IPv4Address::ip_to_int(const char* ip) { - #ifdef WIN32 + #ifdef _WIN32 in_addr addr; if(InetPtonA(AF_INET, ip, &addr)) { return Endian::be_to_host(addr.s_addr); @@ -86,7 +86,7 @@ uint32_t IPv4Address::ip_to_int(const char* ip) { else { throw std::runtime_error("Invalid ip address"); } - #else // WIN32 + #else // _WIN32 in_addr addr; if(inet_pton(AF_INET, ip, &addr) == 1) { return Endian::be_to_host(addr.s_addr); @@ -94,7 +94,7 @@ uint32_t IPv4Address::ip_to_int(const char* ip) { else { throw std::runtime_error("Invalid ip address"); } - #endif // WIN32 + #endif // _WIN32 } std::ostream &operator<<(std::ostream &output, const IPv4Address &addr) { diff --git a/src/ipv6.cpp b/src/ipv6.cpp index 4404964..bcf02a5 100644 --- a/src/ipv6.cpp +++ b/src/ipv6.cpp @@ -31,7 +31,7 @@ #ifdef TINS_DEBUG #include #endif -#ifndef WIN32 +#ifndef _WIN32 #include #include #else diff --git a/src/ipv6_address.cpp b/src/ipv6_address.cpp index b63915e..44b9ac0 100644 --- a/src/ipv6_address.cpp +++ b/src/ipv6_address.cpp @@ -29,7 +29,7 @@ #include #include "macros.h" -#ifndef WIN32 +#ifndef _WIN32 #include #ifdef BSD #include @@ -64,7 +64,7 @@ IPv6Address::IPv6Address(const std::string &addr) { } void IPv6Address::init(const char *addr) { - #ifdef WIN32 + #ifdef _WIN32 // mingw on linux somehow doesn't have InetPton #ifdef _MSC_VER if(InetPtonA(AF_INET6, addr, address) != 1) @@ -84,7 +84,7 @@ void IPv6Address::init(const char *addr) { std::string IPv6Address::to_string() const { char buffer[INET6_ADDRSTRLEN]; - #ifdef WIN32 + #ifdef _WIN32 // mingw on linux somehow doesn't have InetNtop #ifdef _MSC_VER if(InetNtopA(AF_INET6, (PVOID)address, buffer, sizeof(buffer)) == 0) diff --git a/src/loopback.cpp b/src/loopback.cpp index 4ae2532..ff52373 100644 --- a/src/loopback.cpp +++ b/src/loopback.cpp @@ -27,7 +27,7 @@ * */ -#ifndef WIN32 +#ifndef _WIN32 #include #ifdef BSD #include @@ -68,7 +68,7 @@ Loopback::Loopback(const uint8_t *buffer, uint32_t total_sz) _family = *reinterpret_cast(buffer); buffer += sizeof(uint32_t); total_sz -= sizeof(uint32_t); - #ifndef WIN32 + #ifndef _WIN32 if(total_sz) { switch(_family) { case PF_INET: @@ -82,7 +82,7 @@ Loopback::Loopback(const uint8_t *buffer, uint32_t total_sz) break; }; } - #endif // WIN32 + #endif // _WIN32 } void Loopback::family(uint32_t family_id) { @@ -97,13 +97,13 @@ void Loopback::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU #ifdef TINS_DEBUG assert(total_sz >= sizeof(_family)); #endif - #ifndef WIN32 + #ifndef _WIN32 if(tins_cast(inner_pdu())) _family = PF_INET; else if(tins_cast(inner_pdu())) _family = PF_LLC; *reinterpret_cast(buffer) = _family; - #endif // WIN32 + #endif // _WIN32 } bool Loopback::matches_response(const uint8_t *ptr, uint32_t total_sz) const { @@ -125,5 +125,5 @@ void Loopback::send(PacketSender &sender, const NetworkInterface &iface) { sender.send_l2(*this, 0, 0, iface); } -#endif // WIN32 +#endif // _WIN32 } diff --git a/src/network_interface.cpp b/src/network_interface.cpp index 844d0ae..d616b99 100644 --- a/src/network_interface.cpp +++ b/src/network_interface.cpp @@ -31,7 +31,7 @@ #include #include #include "macros.h" -#ifndef WIN32 +#ifndef _WIN32 #include #if defined(BSD) || defined(__FreeBSD_kernel__) #include @@ -65,7 +65,7 @@ struct InterfaceInfoCollector { InterfaceInfoCollector(info_type *res, int id, const char* if_name) : info(res), iface_id(id), iface_name(if_name), found_hw(false), found_ip(false) { } - #ifndef WIN32 + #ifndef _WIN32 bool operator() (const struct ifaddrs *addr) { using Tins::Endian::host_to_be; using Tins::IPv4Address; @@ -107,7 +107,7 @@ struct InterfaceInfoCollector { return found_ip && found_hw; } - #else // WIN32 + #else // _WIN32 bool operator() (const IP_ADAPTER_ADDRESSES *iface) { using Tins::IPv4Address; using Tins::Endian::host_to_be; @@ -124,7 +124,7 @@ struct InterfaceInfoCollector { } return found_ip && found_hw; } - #endif // WIN32 + #endif // _WIN32 }; /** \endcond */ @@ -189,12 +189,12 @@ NetworkInterface::NetworkInterface(IPv4Address ip) : iface_id(0) { } std::string NetworkInterface::name() const { - #ifndef WIN32 + #ifndef _WIN32 char iface_name[IF_NAMESIZE]; if(!if_indextoname(iface_id, iface_name)) throw std::runtime_error("Error fetching this interface's name"); return iface_name; - #else // WIN32 + #else // _WIN32 ULONG size; ::GetAdaptersAddresses(AF_INET, 0, 0, 0, &size); std::vector buffer(size); @@ -208,7 +208,7 @@ std::string NetworkInterface::name() const { } } throw std::runtime_error("Failed to find interface name"); - #endif // WIN32 + #endif // _WIN32 } NetworkInterface::Info NetworkInterface::addresses() const { @@ -228,7 +228,7 @@ bool NetworkInterface::is_loopback() const { } NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) { - #ifndef WIN32 + #ifndef _WIN32 id_type id = if_nametoindex(name); if(!id) throw std::runtime_error("Invalid interface"); diff --git a/src/packet_sender.cpp b/src/packet_sender.cpp index 5710689..4704f2b 100644 --- a/src/packet_sender.cpp +++ b/src/packet_sender.cpp @@ -28,7 +28,7 @@ */ #include "packet_sender.h" -#ifndef WIN32 +#ifndef _WIN32 #include #include #include @@ -73,7 +73,7 @@ namespace Tins { const int PacketSender::INVALID_RAW_SOCKET = -1; const uint32_t PacketSender::DEFAULT_TIMEOUT = 2; -#ifndef WIN32 +#ifndef _WIN32 const char *make_error_string() { return strerror(errno); } @@ -87,7 +87,7 @@ const uint32_t PacketSender::DEFAULT_TIMEOUT = 2; PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout, uint32_t usec) : _sockets(SOCKETS_END, INVALID_RAW_SOCKET), -#if !defined(BSD) && !defined(WIN32) && !defined(__FreeBSD_kernel__) +#if !defined(BSD) && !defined(_WIN32) && !defined(__FreeBSD_kernel__) _ether_socket(INVALID_RAW_SOCKET), #endif _timeout(recv_timeout), _timeout_usec(usec), default_iface(iface) @@ -102,7 +102,7 @@ PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout, PacketSender::~PacketSender() { for(unsigned i(0); i < _sockets.size(); ++i) { if(_sockets[i] != INVALID_RAW_SOCKET) - #ifndef WIN32 + #ifndef _WIN32 ::close(_sockets[i]); #else ::closesocket(_sockets[i]); @@ -111,7 +111,7 @@ PacketSender::~PacketSender() { #if defined(BSD) || defined(__FreeBSD_kernel__) for(BSDEtherSockets::iterator it = _ether_socket.begin(); it != _ether_socket.end(); ++it) ::close(it->second); - #elif !defined(WIN32) + #elif !defined(_WIN32) if(_ether_socket != INVALID_RAW_SOCKET) ::close(_ether_socket); #endif @@ -132,9 +132,9 @@ const NetworkInterface& PacketSender::default_interface() const { return default_iface; } -#if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) +#if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) -#ifndef WIN32 +#ifndef _WIN32 bool PacketSender::ether_socket_initialized(const NetworkInterface& iface) const { #if defined(BSD) || defined(__FreeBSD_kernel__) return _ether_socket.count(iface.id()); @@ -152,16 +152,16 @@ int PacketSender::get_ether_socket(const NetworkInterface& iface) { return _ether_socket; #endif } -#endif // WIN32 +#endif // _WIN32 #ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET pcap_t* PacketSender::make_pcap_handle(const NetworkInterface& iface) const { - #ifdef WIN32 + #ifdef _WIN32 #define TINS_PREFIX_INTERFACE(x) ("\\Device\\NPF_" + x) - #else // WIN32 + #else // _WIN32 #define TINS_PREFIX_INTERFACE(x) (x) - #endif // WIN32 + #endif // _WIN32 char error[PCAP_ERRBUF_SIZE]; pcap_t* handle = pcap_create(TINS_PREFIX_INTERFACE(iface.name()).c_str(), error); @@ -219,7 +219,7 @@ void PacketSender::open_l2_socket(const NetworkInterface& iface) { } #endif } -#endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET +#endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET void PacketSender::open_l3_socket(SocketType type) { int socktype = find_type(type); @@ -232,7 +232,7 @@ void PacketSender::open_l3_socket(SocketType type) { throw socket_open_error(make_error_string()); const int on = 1; - #ifndef WIN32 + #ifndef _WIN32 typedef const void* option_ptr; #else typedef const char* option_ptr; @@ -252,7 +252,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface &iface) if(::close(it->second) == -1) throw socket_close_error(make_error_string()); _ether_socket.erase(it); - #elif !defined(WIN32) + #elif !defined(_WIN32) if(_ether_socket == INVALID_RAW_SOCKET) throw invalid_socket_type(); if(::close(_ether_socket) == -1) @@ -263,7 +263,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface &iface) else { if(type >= SOCKETS_END || _sockets[type] == INVALID_RAW_SOCKET) throw invalid_socket_type(); - #ifndef WIN32 + #ifndef _WIN32 if(close(_sockets[type]) == -1) throw socket_close_error(make_error_string()); #else @@ -305,7 +305,7 @@ PDU *PacketSender::send_recv(PDU &pdu, const NetworkInterface &iface) { return pdu.recv_response(*this, iface); } -#if !defined(WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) +#if !defined(_WIN32) || defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, const NetworkInterface &iface) { @@ -330,9 +330,9 @@ void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr, #endif // HAVE_PACKET_SENDER_PCAP_SENDPACKET } -#endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET +#endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET -#ifndef WIN32 +#ifndef _WIN32 PDU *PacketSender::recv_l2(PDU &pdu, struct sockaddr *link_addr, uint32_t len_addr, const NetworkInterface &iface) { @@ -340,7 +340,7 @@ PDU *PacketSender::recv_l2(PDU &pdu, struct sockaddr *link_addr, std::vector sockets(1, sock); return recv_match_loop(sockets, pdu, link_addr, len_addr); } -#endif // WIN32 +#endif // _WIN32 PDU *PacketSender::recv_l3(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, SocketType type) { open_l3_socket(type); @@ -364,7 +364,7 @@ void PacketSender::send_l3(PDU &pdu, struct sockaddr* link_addr, uint32_t len_ad } PDU *PacketSender::recv_match_loop(const std::vector& sockets, PDU &pdu, struct sockaddr* link_addr, uint32_t addrlen) { - #ifdef WIN32 + #ifdef _WIN32 typedef int socket_len_type; typedef int recvfrom_ret_type; #else @@ -422,11 +422,11 @@ PDU *PacketSender::recv_match_loop(const std::vector& sockets, PDU &pdu, st } } struct timeval this_time, diff; - #ifdef WIN32 + #ifdef _WIN32 // fixme #else gettimeofday(&this_time, 0); - #endif // WIN32 + #endif // _WIN32 if(timeval_subtract(&diff, &end_time, &this_time)) return 0; timeout.tv_sec = diff.tv_sec; diff --git a/src/packet_writer.cpp b/src/packet_writer.cpp index 19df0cd..032165c 100644 --- a/src/packet_writer.cpp +++ b/src/packet_writer.cpp @@ -27,7 +27,7 @@ * */ -#ifndef WIN32 +#ifndef _WIN32 #include #endif #include @@ -49,7 +49,7 @@ PacketWriter::~PacketWriter() { void PacketWriter::write(PDU &pdu) { PDU::serialization_type buffer = pdu.serialize(); timeval tm; - #ifndef WIN32 + #ifndef _WIN32 gettimeofday(&tm, 0); #else // fixme diff --git a/src/radiotap.cpp b/src/radiotap.cpp index f7210ed..800c605 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -37,7 +37,7 @@ #endif #include #include "macros.h" -#ifndef WIN32 +#ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) #include #else @@ -430,7 +430,7 @@ uint8_t RadioTap::data_retries() const { return _data_retries; } -#ifndef WIN32 +#ifndef _WIN32 void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) { if(!iface) throw invalid_interface(); diff --git a/src/snap.cpp b/src/snap.cpp index 47af2e2..bce9470 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -32,7 +32,7 @@ #include #endif #include -#ifndef WIN32 +#ifndef _WIN32 #include #include #endif diff --git a/src/sniffer.cpp b/src/sniffer.cpp index e8668fa..cbfdb8b 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -27,11 +27,11 @@ * */ -#ifdef WIN32 +#ifdef _WIN32 #define TINS_PREFIX_INTERFACE(x) ("\\Device\\NPF_" + x) -#else // WIN32 +#else // _WIN32 #define TINS_PREFIX_INTERFACE(x) (x) -#endif // WIN32 +#endif // _WIN32 #include #include @@ -191,11 +191,11 @@ void BaseSniffer::stop_sniff() { } int BaseSniffer::get_fd() { - #ifndef WIN32 + #ifndef _WIN32 return pcap_get_selectable_fd(handle); #else throw std::runtime_error("Method not supported in Windows platform"); - #endif // WIN32 + #endif // _WIN32 } int BaseSniffer::link_type() const { @@ -343,7 +343,7 @@ void Sniffer::set_promisc_mode(bool promisc_enabled) void Sniffer::set_rfmon(bool rfmon_enabled) { - #ifndef WIN32 + #ifndef _WIN32 if (pcap_can_set_rfmon(get_pcap_handle()) == 1) { if (pcap_set_rfmon(get_pcap_handle(), rfmon_enabled)) { throw runtime_error(pcap_geterr(get_pcap_handle())); diff --git a/src/utils.cpp b/src/utils.cpp index 8b8ff66..e7cc468 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -33,7 +33,7 @@ #include #include #include "utils.h" -#ifndef WIN32 +#ifndef _WIN32 #if defined(BSD) || defined(__FreeBSD_kernel__) #include #include @@ -61,7 +61,7 @@ using namespace std; struct InterfaceCollector { set ifaces; - #ifdef WIN32 + #ifdef _WIN32 bool operator() (PIP_ADAPTER_ADDRESSES addr) { ifaces.insert(addr->AdapterName); return false; diff --git a/tests/src/loopback.cpp b/tests/src/loopback.cpp index 85c8eb5..2c9f29f 100644 --- a/tests/src/loopback.cpp +++ b/tests/src/loopback.cpp @@ -3,7 +3,7 @@ #include #include #include "macros.h" -#ifndef WIN32 +#ifndef _WIN32 #include #ifdef BSD #include @@ -23,7 +23,7 @@ public: }; -#ifndef WIN32 +#ifndef _WIN32 TEST_F(LoopbackTest, MatchesResponse) { Loopback loop1 = Loopback() / IP("192.168.0.1", "192.168.0.2") / TCP(22, 21); loop1.family(PF_INET); @@ -32,4 +32,4 @@ TEST_F(LoopbackTest, MatchesResponse) { PDU::serialization_type buffer = loop2.serialize(); EXPECT_TRUE(loop1.matches_response(&buffer[0], buffer.size())); } -#endif // WIN32 +#endif // _WIN32 diff --git a/tests/src/network_interface.cpp b/tests/src/network_interface.cpp index ef48820..e00dfcc 100644 --- a/tests/src/network_interface.cpp +++ b/tests/src/network_interface.cpp @@ -21,7 +21,7 @@ const string NetworkInterfaceTest::iface_name("lo"), NetworkInterfaceTest::iface_addr(""); #endif -#ifndef WIN32 +#ifndef _WIN32 TEST_F(NetworkInterfaceTest, ConstructorFromString) { // just test this doesn't throw NetworkInterface iface(iface_name); @@ -62,7 +62,7 @@ TEST_F(NetworkInterfaceTest, DistinctOperator) { NetworkInterface iface1(iface_name), iface2; EXPECT_NE(iface1, iface2); } -#endif // WIN32 +#endif // _WIN32 // This is a more generic test that can be run on all platforms. // The above ones won't run on windows since there's no name for the loopback interface.