1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Replace WIN32 macro with _WIN32.

This commit is contained in:
Matias Fontanini
2015-05-02 16:25:59 -07:00
parent a7a63483df
commit a607ab380c
28 changed files with 108 additions and 110 deletions

View File

@@ -53,9 +53,7 @@ IF(WIN32)
SET(LIBTINS_OS_LIBS Ws2_32.lib Iphlpapi.lib) SET(LIBTINS_OS_LIBS Ws2_32.lib Iphlpapi.lib)
# Add the NOMINMAX macro to avoid Windows' min and max macros. # Add the NOMINMAX macro to avoid Windows' min and max macros.
# While compiling on windows, for some reason, WIN32 is not defined, ADD_DEFINITIONS(-DNOMINMAX)
# maybe we could fix this later, but it's OK for now.
ADD_DEFINITIONS(-DNOMINMAX -DWIN32)
ENDIF(WIN32) ENDIF(WIN32)
# ******************* # *******************

View File

@@ -382,12 +382,12 @@ public:
*/ */
uint32_t header_size() const; uint32_t header_size() const;
#ifndef WIN32 #ifndef _WIN32
/** /**
* \sa PDU::send() * \sa PDU::send()
*/ */
void send(PacketSender &sender, const NetworkInterface &iface); void send(PacketSender &sender, const NetworkInterface &iface);
#endif // WIN32 #endif // _WIN32
/** /**
* \brief Adds a new option to this Dot11 PDU. * \brief Adds a new option to this Dot11 PDU.

View File

@@ -138,12 +138,12 @@ namespace Tins {
*/ */
uint32_t header_size() const; 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() * \sa PDU::send()
*/ */
void send(PacketSender &sender, const NetworkInterface &iface); 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. * \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; bool matches_response(const uint8_t *ptr, uint32_t total_sz) const;
#ifndef WIN32 #ifndef _WIN32
/** /**
* \sa PDU::recv_response * \sa PDU::recv_response
*/ */
PDU *recv_response(PacketSender &sender, const NetworkInterface &iface); PDU *recv_response(PacketSender &sender, const NetworkInterface &iface);
#endif // WIN32 #endif // _WIN32
/** /**
* \brief Getter for the PDU's type. * \brief Getter for the PDU's type.

View File

@@ -41,7 +41,7 @@
#include <sys/endian.h> #include <sys/endian.h>
#define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) #define TINS_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
#define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN) #define TINS_IS_BIG_ENDIAN (_BYTE_ORDER == _BIG_ENDIAN)
#elif defined(WIN32) #elif defined(_WIN32)
// Assume windows == little endian. fixme later // Assume windows == little endian. fixme later
#define TINS_IS_LITTLE_ENDIAN 1 #define TINS_IS_LITTLE_ENDIAN 1
#define TINS_IS_BIG_ENDIAN 0 #define TINS_IS_BIG_ENDIAN 0

View File

@@ -160,14 +160,14 @@ namespace Tins {
*/ */
bool matches_response(const uint8_t *ptr, uint32_t total_sz) const; bool matches_response(const uint8_t *ptr, uint32_t total_sz) const;
#ifndef WIN32 #ifndef _WIN32
/** /**
* \brief Receives a matching response for this packet. * \brief Receives a matching response for this packet.
* *
* \sa PDU::recv_response * \sa PDU::recv_response
*/ */
PDU *recv_response(PacketSender &sender, const NetworkInterface &iface); PDU *recv_response(PacketSender &sender, const NetworkInterface &iface);
#endif // WIN32 #endif // _WIN32
/** /**
* \brief Getter for the PDU's type. * \brief Getter for the PDU's type.

View File

@@ -32,7 +32,7 @@
// Windows likes to define macros with not-so-common-names, which break // Windows likes to define macros with not-so-common-names, which break
// this code // this code
#ifdef WIN32 #ifdef _WIN32
#ifdef TIMESTAMP_REQUEST #ifdef TIMESTAMP_REQUEST
#undef TIMESTAMP_REQUEST #undef TIMESTAMP_REQUEST
#endif // TIMESTAMP_REQUEST #endif // TIMESTAMP_REQUEST
@@ -40,7 +40,7 @@
#ifdef TIMESTAMP_REPLY #ifdef TIMESTAMP_REPLY
#undef TIMESTAMP_REPLY #undef TIMESTAMP_REPLY
#endif // TIMESTAMP_REPLY #endif // TIMESTAMP_REPLY
#endif // WIN32 #endif // _WIN32
#include "macros.h" #include "macros.h"
#include "pdu.h" #include "pdu.h"

View File

@@ -159,7 +159,7 @@ namespace Tins {
PacketSender& operator=(PacketSender &&rhs) TINS_NOEXCEPT { PacketSender& operator=(PacketSender &&rhs) TINS_NOEXCEPT {
_sockets = std::move(rhs._sockets); _sockets = std::move(rhs._sockets);
rhs._sockets = std::vector<int>(SOCKETS_END, INVALID_RAW_SOCKET); rhs._sockets = std::vector<int>(SOCKETS_END, INVALID_RAW_SOCKET);
#ifndef WIN32 #ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
_ether_socket = std::move(rhs._ether_socket); _ether_socket = std::move(rhs._ether_socket);
#else #else
@@ -182,14 +182,14 @@ namespace Tins {
*/ */
~PacketSender(); ~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. * \brief Opens a layer 2 socket.
* *
* If this operation fails, then a socket_open_error will be thrown. * If this operation fails, then a socket_open_error will be thrown.
*/ */
void open_l2_socket(const NetworkInterface& iface = NetworkInterface()); 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 * \brief Opens a layer 3 socket, using the corresponding protocol
@@ -302,7 +302,7 @@ namespace Tins {
*/ */
PDU *send_recv(PDU &pdu, const NetworkInterface &iface); PDU *send_recv(PDU &pdu, const NetworkInterface &iface);
#ifndef WIN32 #ifndef _WIN32
/** /**
* \brief Receives a layer 2 PDU response to a previously sent PDU. * \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, PDU *recv_l2(PDU &pdu, struct sockaddr *link_addr, uint32_t len_addr,
const NetworkInterface &iface = NetworkInterface()); 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. * \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, void send_l2(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr,
const NetworkInterface &iface = NetworkInterface()); 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. * \brief Receives a layer 3 PDU response to a previously sent PDU.
@@ -383,7 +383,7 @@ namespace Tins {
PacketSender& operator=(const PacketSender&); PacketSender& operator=(const PacketSender&);
int find_type(SocketType type); int find_type(SocketType type);
int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y); 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; bool ether_socket_initialized(const NetworkInterface& iface = NetworkInterface()) const;
int get_ether_socket(const NetworkInterface& iface = NetworkInterface()); int get_ether_socket(const NetworkInterface& iface = NetworkInterface());
#endif #endif
@@ -399,7 +399,7 @@ namespace Tins {
uint32_t addrlen); uint32_t addrlen);
std::vector<int> _sockets; std::vector<int> _sockets;
#ifndef WIN32 #ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
typedef std::map<uint32_t, int> BSDEtherSockets; typedef std::map<uint32_t, int> BSDEtherSockets;
BSDEtherSockets _ether_socket; BSDEtherSockets _ether_socket;

View File

@@ -141,7 +141,7 @@ namespace Tins {
/* Setters */ /* Setters */
#ifndef WIN32 #ifndef _WIN32
/** /**
* \sa PDU::send() * \sa PDU::send()
*/ */

View File

@@ -30,7 +30,7 @@
#ifndef TINS_TIMESTAMP_H #ifndef TINS_TIMESTAMP_H
#define TINS_TIMESTAMP_H #define TINS_TIMESTAMP_H
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
@@ -46,7 +46,7 @@ namespace Tins {
*/ */
class Timestamp { class Timestamp {
public: public:
#ifdef WIN32 #ifdef _WIN32
typedef long seconds_type; typedef long seconds_type;
typedef long microseconds_type; typedef long microseconds_type;
#else #else
@@ -58,7 +58,7 @@ public:
* \brief Constructs a Timestamp which will hold the current time. * \brief Constructs a Timestamp which will hold the current time.
*/ */
static Timestamp current_time() { static Timestamp current_time() {
#ifdef WIN32 #ifdef _WIN32
//fixme //fixme
return Timestamp(); return Timestamp();
#else #else

View File

@@ -30,7 +30,7 @@
#ifndef TINS_UTILS_H #ifndef TINS_UTILS_H
#define TINS_UTILS_H #define TINS_UTILS_H
#ifndef WIN32 #ifndef _WIN32
#include <ifaddrs.h> #include <ifaddrs.h>
#else #else
#include <winsock2.h> #include <winsock2.h>
@@ -248,7 +248,7 @@ namespace Tins {
* the object to collect data from them. * the object to collect data from them.
* \param functor An instance of an class which implements operator(struct ifaddrs*). * \param functor An instance of an class which implements operator(struct ifaddrs*).
*/ */
#ifndef WIN32 #ifndef _WIN32
template<class Functor> template<class Functor>
void generic_iface_loop(Functor &functor) { void generic_iface_loop(Functor &functor) {
struct ifaddrs *ifaddrs = 0; struct ifaddrs *ifaddrs = 0;
@@ -261,7 +261,7 @@ namespace Tins {
if(ifaddrs) if(ifaddrs)
freeifaddrs(ifaddrs); freeifaddrs(ifaddrs);
} }
#else // WIN32 #else // _WIN32
template<class Functor> template<class Functor>
void generic_iface_loop(Functor &functor) { void generic_iface_loop(Functor &functor) {
ULONG size; ULONG size;
@@ -276,7 +276,7 @@ namespace Tins {
} }
} }
} }
#endif // WIN32 #endif // _WIN32
template <typename T> template <typename T>
struct is_pdu { struct is_pdu {
@@ -376,7 +376,7 @@ void Tins::Utils::route_entries(ForwardIterator output) {
next += rtm->rtm_msglen; next += rtm->rtm_msglen;
} }
} }
#elif defined(WIN32) #elif defined(_WIN32)
template<class ForwardIterator> template<class ForwardIterator>
void Tins::Utils::route_entries(ForwardIterator output) { void Tins::Utils::route_entries(ForwardIterator output) {
MIB_IPFORWARDTABLE *table; MIB_IPFORWARDTABLE *table;

View File

@@ -39,7 +39,7 @@
#include "macros.h" #include "macros.h"
#include "exceptions.h" #include "exceptions.h"
#ifndef WIN32 #ifndef _WIN32
#if defined(__FreeBSD_kernel__) || defined(BSD) || defined(__APPLE__) #if defined(__FreeBSD_kernel__) || defined(BSD) || defined(__APPLE__)
#include <sys/types.h> #include <sys/types.h>
#include <net/if_dl.h> #include <net/if_dl.h>
@@ -171,7 +171,7 @@ uint32_t Dot11::header_size() const {
return sz; return sz;
} }
#ifndef WIN32 #ifndef _WIN32
void Dot11::send(PacketSender &sender, const NetworkInterface &iface) { void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
if(!iface) if(!iface)
throw invalid_interface(); throw invalid_interface();
@@ -191,7 +191,7 @@ void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
sender.send_l2(*this, 0, 0, iface); sender.send_l2(*this, 0, 0, iface);
#endif #endif
} }
#endif // WIN32 #endif // _WIN32
void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG #ifdef TINS_DEBUG

View File

@@ -34,7 +34,7 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
#include "macros.h" #include "macros.h"
#ifndef WIN32 #ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h> #include <net/if_dl.h>
#else #else
@@ -87,7 +87,7 @@ uint32_t Dot3::header_size() const {
return sizeof(ethhdr); 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) { void Dot3::send(PacketSender &sender, const NetworkInterface &iface) {
if(!iface) if(!iface)
throw invalid_interface(); 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)); sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
#endif #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 { bool Dot3::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
if(total_sz < sizeof(ethhdr)) 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)); memcpy(buffer, &_eth, sizeof(ethhdr));
} }
#ifndef WIN32 #ifndef _WIN32
PDU *Dot3::recv_response(PacketSender &sender, const NetworkInterface &iface) { PDU *Dot3::recv_response(PacketSender &sender, const NetworkInterface &iface) {
if(!iface) if(!iface)
throw invalid_interface(); throw invalid_interface();
@@ -154,5 +154,5 @@ PDU *Dot3::recv_response(PacketSender &sender, const NetworkInterface &iface) {
return sender.recv_l2(*this, 0, 0, iface); return sender.recv_l2(*this, 0, 0, iface);
#endif #endif
} }
#endif // WIN32 #endif // _WIN32
} }

View File

@@ -34,7 +34,7 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
#include "macros.h" #include "macros.h"
#ifndef WIN32 #ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h> #include <net/if_dl.h>
#else #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__) #if defined(HAVE_PACKET_SENDER_PCAP_SENDPACKET) || defined(BSD) || defined(__FreeBSD_kernel__)
// Sending using pcap_sendpacket/BSD bpf packet mode is the same here // Sending using pcap_sendpacket/BSD bpf packet mode is the same here
sender.send_l2(*this, 0, 0, iface); sender.send_l2(*this, 0, 0, iface);
#elif defined(WIN32) #elif defined(_WIN32)
// On Windows we can only send l2 PDUs using pcap_sendpacket // On Windows we can only send l2 PDUs using pcap_sendpacket
throw std::runtime_error("LIBTINS_USE_PCAP_SENDPACKET is not enabled"); throw std::runtime_error("LIBTINS_USE_PCAP_SENDPACKET is not enabled");
#else #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) { PDU *EthernetII::recv_response(PacketSender &sender, const NetworkInterface &iface) {
#if !defined(BSD) && !defined(__FreeBSD_kernel__) #if !defined(BSD) && !defined(__FreeBSD_kernel__)
struct sockaddr_ll addr; 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); return sender.recv_l2(*this, 0, 0, iface);
#endif #endif
} }
#endif // WIN32 #endif // _WIN32
} }

View File

@@ -32,7 +32,7 @@
#ifdef TINS_DEBUG #ifdef TINS_DEBUG
#include <cassert> #include <cassert>
#endif #endif
#ifndef WIN32 #ifndef _WIN32
#include <netinet/in.h> #include <netinet/in.h>
#endif #endif
#include "rawpdu.h" #include "rawpdu.h"

View File

@@ -33,7 +33,7 @@
#include <cassert> #include <cassert>
#endif #endif
#include <algorithm> #include <algorithm>
#ifndef WIN32 #ifndef _WIN32
#include <netdb.h> #include <netdb.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>

View File

@@ -27,12 +27,12 @@
* *
*/ */
#ifdef WIN32 #ifdef _WIN32
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else // WIN32 #else // _WIN32
#include <sys/socket.h> #include <sys/socket.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#endif // WIN32 #endif // _WIN32
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include "ip_address.h" #include "ip_address.h"
@@ -78,7 +78,7 @@ std::string IPv4Address::to_string() const {
} }
uint32_t IPv4Address::ip_to_int(const char* ip) { uint32_t IPv4Address::ip_to_int(const char* ip) {
#ifdef WIN32 #ifdef _WIN32
in_addr addr; in_addr addr;
if(InetPtonA(AF_INET, ip, &addr)) { if(InetPtonA(AF_INET, ip, &addr)) {
return Endian::be_to_host(addr.s_addr); return Endian::be_to_host(addr.s_addr);
@@ -86,7 +86,7 @@ uint32_t IPv4Address::ip_to_int(const char* ip) {
else { else {
throw std::runtime_error("Invalid ip address"); throw std::runtime_error("Invalid ip address");
} }
#else // WIN32 #else // _WIN32
in_addr addr; in_addr addr;
if(inet_pton(AF_INET, ip, &addr) == 1) { if(inet_pton(AF_INET, ip, &addr) == 1) {
return Endian::be_to_host(addr.s_addr); return Endian::be_to_host(addr.s_addr);
@@ -94,7 +94,7 @@ uint32_t IPv4Address::ip_to_int(const char* ip) {
else { else {
throw std::runtime_error("Invalid ip address"); throw std::runtime_error("Invalid ip address");
} }
#endif // WIN32 #endif // _WIN32
} }
std::ostream &operator<<(std::ostream &output, const IPv4Address &addr) { std::ostream &operator<<(std::ostream &output, const IPv4Address &addr) {

View File

@@ -31,7 +31,7 @@
#ifdef TINS_DEBUG #ifdef TINS_DEBUG
#include <cassert> #include <cassert>
#endif #endif
#ifndef WIN32 #ifndef _WIN32
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#else #else

View File

@@ -29,7 +29,7 @@
#include <algorithm> #include <algorithm>
#include "macros.h" #include "macros.h"
#ifndef WIN32 #ifndef _WIN32
#include <arpa/inet.h> #include <arpa/inet.h>
#ifdef BSD #ifdef BSD
#include <sys/socket.h> #include <sys/socket.h>
@@ -64,7 +64,7 @@ IPv6Address::IPv6Address(const std::string &addr) {
} }
void IPv6Address::init(const char *addr) { void IPv6Address::init(const char *addr) {
#ifdef WIN32 #ifdef _WIN32
// mingw on linux somehow doesn't have InetPton // mingw on linux somehow doesn't have InetPton
#ifdef _MSC_VER #ifdef _MSC_VER
if(InetPtonA(AF_INET6, addr, address) != 1) if(InetPtonA(AF_INET6, addr, address) != 1)
@@ -84,7 +84,7 @@ void IPv6Address::init(const char *addr) {
std::string IPv6Address::to_string() const { std::string IPv6Address::to_string() const {
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
#ifdef WIN32 #ifdef _WIN32
// mingw on linux somehow doesn't have InetNtop // mingw on linux somehow doesn't have InetNtop
#ifdef _MSC_VER #ifdef _MSC_VER
if(InetNtopA(AF_INET6, (PVOID)address, buffer, sizeof(buffer)) == 0) if(InetNtopA(AF_INET6, (PVOID)address, buffer, sizeof(buffer)) == 0)

View File

@@ -27,7 +27,7 @@
* *
*/ */
#ifndef WIN32 #ifndef _WIN32
#include <sys/socket.h> #include <sys/socket.h>
#ifdef BSD #ifdef BSD
#include <net/if_dl.h> #include <net/if_dl.h>
@@ -68,7 +68,7 @@ Loopback::Loopback(const uint8_t *buffer, uint32_t total_sz)
_family = *reinterpret_cast<const uint32_t*>(buffer); _family = *reinterpret_cast<const uint32_t*>(buffer);
buffer += sizeof(uint32_t); buffer += sizeof(uint32_t);
total_sz -= sizeof(uint32_t); total_sz -= sizeof(uint32_t);
#ifndef WIN32 #ifndef _WIN32
if(total_sz) { if(total_sz) {
switch(_family) { switch(_family) {
case PF_INET: case PF_INET:
@@ -82,7 +82,7 @@ Loopback::Loopback(const uint8_t *buffer, uint32_t total_sz)
break; break;
}; };
} }
#endif // WIN32 #endif // _WIN32
} }
void Loopback::family(uint32_t family_id) { 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 #ifdef TINS_DEBUG
assert(total_sz >= sizeof(_family)); assert(total_sz >= sizeof(_family));
#endif #endif
#ifndef WIN32 #ifndef _WIN32
if(tins_cast<const Tins::IP*>(inner_pdu())) if(tins_cast<const Tins::IP*>(inner_pdu()))
_family = PF_INET; _family = PF_INET;
else if(tins_cast<const Tins::LLC*>(inner_pdu())) else if(tins_cast<const Tins::LLC*>(inner_pdu()))
_family = PF_LLC; _family = PF_LLC;
*reinterpret_cast<uint32_t*>(buffer) = _family; *reinterpret_cast<uint32_t*>(buffer) = _family;
#endif // WIN32 #endif // _WIN32
} }
bool Loopback::matches_response(const uint8_t *ptr, uint32_t total_sz) const { 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); sender.send_l2(*this, 0, 0, iface);
} }
#endif // WIN32 #endif // _WIN32
} }

View File

@@ -31,7 +31,7 @@
#include <vector> #include <vector>
#include <cstring> #include <cstring>
#include "macros.h" #include "macros.h"
#ifndef WIN32 #ifndef _WIN32
#include <netinet/in.h> #include <netinet/in.h>
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
#include <ifaddrs.h> #include <ifaddrs.h>
@@ -65,7 +65,7 @@ struct InterfaceInfoCollector {
InterfaceInfoCollector(info_type *res, int id, const char* if_name) 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) { } : 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) { bool operator() (const struct ifaddrs *addr) {
using Tins::Endian::host_to_be; using Tins::Endian::host_to_be;
using Tins::IPv4Address; using Tins::IPv4Address;
@@ -107,7 +107,7 @@ struct InterfaceInfoCollector {
return found_ip && found_hw; return found_ip && found_hw;
} }
#else // WIN32 #else // _WIN32
bool operator() (const IP_ADAPTER_ADDRESSES *iface) { bool operator() (const IP_ADAPTER_ADDRESSES *iface) {
using Tins::IPv4Address; using Tins::IPv4Address;
using Tins::Endian::host_to_be; using Tins::Endian::host_to_be;
@@ -124,7 +124,7 @@ struct InterfaceInfoCollector {
} }
return found_ip && found_hw; return found_ip && found_hw;
} }
#endif // WIN32 #endif // _WIN32
}; };
/** \endcond */ /** \endcond */
@@ -189,12 +189,12 @@ NetworkInterface::NetworkInterface(IPv4Address ip) : iface_id(0) {
} }
std::string NetworkInterface::name() const { std::string NetworkInterface::name() const {
#ifndef WIN32 #ifndef _WIN32
char iface_name[IF_NAMESIZE]; char iface_name[IF_NAMESIZE];
if(!if_indextoname(iface_id, iface_name)) if(!if_indextoname(iface_id, iface_name))
throw std::runtime_error("Error fetching this interface's name"); throw std::runtime_error("Error fetching this interface's name");
return iface_name; return iface_name;
#else // WIN32 #else // _WIN32
ULONG size; ULONG size;
::GetAdaptersAddresses(AF_INET, 0, 0, 0, &size); ::GetAdaptersAddresses(AF_INET, 0, 0, 0, &size);
std::vector<uint8_t> buffer(size); std::vector<uint8_t> buffer(size);
@@ -208,7 +208,7 @@ std::string NetworkInterface::name() const {
} }
} }
throw std::runtime_error("Failed to find interface name"); throw std::runtime_error("Failed to find interface name");
#endif // WIN32 #endif // _WIN32
} }
NetworkInterface::Info NetworkInterface::addresses() const { NetworkInterface::Info NetworkInterface::addresses() const {
@@ -228,7 +228,7 @@ bool NetworkInterface::is_loopback() const {
} }
NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) { NetworkInterface::id_type NetworkInterface::resolve_index(const char *name) {
#ifndef WIN32 #ifndef _WIN32
id_type id = if_nametoindex(name); id_type id = if_nametoindex(name);
if(!id) if(!id)
throw std::runtime_error("Invalid interface"); throw std::runtime_error("Invalid interface");

View File

@@ -28,7 +28,7 @@
*/ */
#include "packet_sender.h" #include "packet_sender.h"
#ifndef WIN32 #ifndef _WIN32
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/time.h> #include <sys/time.h>
@@ -73,7 +73,7 @@ namespace Tins {
const int PacketSender::INVALID_RAW_SOCKET = -1; const int PacketSender::INVALID_RAW_SOCKET = -1;
const uint32_t PacketSender::DEFAULT_TIMEOUT = 2; const uint32_t PacketSender::DEFAULT_TIMEOUT = 2;
#ifndef WIN32 #ifndef _WIN32
const char *make_error_string() { const char *make_error_string() {
return strerror(errno); return strerror(errno);
} }
@@ -87,7 +87,7 @@ const uint32_t PacketSender::DEFAULT_TIMEOUT = 2;
PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout, PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout,
uint32_t usec) uint32_t usec)
: _sockets(SOCKETS_END, INVALID_RAW_SOCKET), : _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), _ether_socket(INVALID_RAW_SOCKET),
#endif #endif
_timeout(recv_timeout), _timeout_usec(usec), default_iface(iface) _timeout(recv_timeout), _timeout_usec(usec), default_iface(iface)
@@ -102,7 +102,7 @@ PacketSender::PacketSender(const NetworkInterface &iface, uint32_t recv_timeout,
PacketSender::~PacketSender() { PacketSender::~PacketSender() {
for(unsigned i(0); i < _sockets.size(); ++i) { for(unsigned i(0); i < _sockets.size(); ++i) {
if(_sockets[i] != INVALID_RAW_SOCKET) if(_sockets[i] != INVALID_RAW_SOCKET)
#ifndef WIN32 #ifndef _WIN32
::close(_sockets[i]); ::close(_sockets[i]);
#else #else
::closesocket(_sockets[i]); ::closesocket(_sockets[i]);
@@ -111,7 +111,7 @@ PacketSender::~PacketSender() {
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
for(BSDEtherSockets::iterator it = _ether_socket.begin(); it != _ether_socket.end(); ++it) for(BSDEtherSockets::iterator it = _ether_socket.begin(); it != _ether_socket.end(); ++it)
::close(it->second); ::close(it->second);
#elif !defined(WIN32) #elif !defined(_WIN32)
if(_ether_socket != INVALID_RAW_SOCKET) if(_ether_socket != INVALID_RAW_SOCKET)
::close(_ether_socket); ::close(_ether_socket);
#endif #endif
@@ -132,9 +132,9 @@ const NetworkInterface& PacketSender::default_interface() const {
return default_iface; 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 { bool PacketSender::ether_socket_initialized(const NetworkInterface& iface) const {
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
return _ether_socket.count(iface.id()); return _ether_socket.count(iface.id());
@@ -152,16 +152,16 @@ int PacketSender::get_ether_socket(const NetworkInterface& iface) {
return _ether_socket; return _ether_socket;
#endif #endif
} }
#endif // WIN32 #endif // _WIN32
#ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET #ifdef HAVE_PACKET_SENDER_PCAP_SENDPACKET
pcap_t* PacketSender::make_pcap_handle(const NetworkInterface& iface) const { pcap_t* PacketSender::make_pcap_handle(const NetworkInterface& iface) const {
#ifdef WIN32 #ifdef _WIN32
#define TINS_PREFIX_INTERFACE(x) ("\\Device\\NPF_" + x) #define TINS_PREFIX_INTERFACE(x) ("\\Device\\NPF_" + x)
#else // WIN32 #else // _WIN32
#define TINS_PREFIX_INTERFACE(x) (x) #define TINS_PREFIX_INTERFACE(x) (x)
#endif // WIN32 #endif // _WIN32
char error[PCAP_ERRBUF_SIZE]; char error[PCAP_ERRBUF_SIZE];
pcap_t* handle = pcap_create(TINS_PREFIX_INTERFACE(iface.name()).c_str(), error); 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
} }
#endif // !WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET #endif // !_WIN32 || HAVE_PACKET_SENDER_PCAP_SENDPACKET
void PacketSender::open_l3_socket(SocketType type) { void PacketSender::open_l3_socket(SocketType type) {
int socktype = find_type(type); int socktype = find_type(type);
@@ -232,7 +232,7 @@ void PacketSender::open_l3_socket(SocketType type) {
throw socket_open_error(make_error_string()); throw socket_open_error(make_error_string());
const int on = 1; const int on = 1;
#ifndef WIN32 #ifndef _WIN32
typedef const void* option_ptr; typedef const void* option_ptr;
#else #else
typedef const char* option_ptr; typedef const char* option_ptr;
@@ -252,7 +252,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface &iface)
if(::close(it->second) == -1) if(::close(it->second) == -1)
throw socket_close_error(make_error_string()); throw socket_close_error(make_error_string());
_ether_socket.erase(it); _ether_socket.erase(it);
#elif !defined(WIN32) #elif !defined(_WIN32)
if(_ether_socket == INVALID_RAW_SOCKET) if(_ether_socket == INVALID_RAW_SOCKET)
throw invalid_socket_type(); throw invalid_socket_type();
if(::close(_ether_socket) == -1) if(::close(_ether_socket) == -1)
@@ -263,7 +263,7 @@ void PacketSender::close_socket(SocketType type, const NetworkInterface &iface)
else { else {
if(type >= SOCKETS_END || _sockets[type] == INVALID_RAW_SOCKET) if(type >= SOCKETS_END || _sockets[type] == INVALID_RAW_SOCKET)
throw invalid_socket_type(); throw invalid_socket_type();
#ifndef WIN32 #ifndef _WIN32
if(close(_sockets[type]) == -1) if(close(_sockets[type]) == -1)
throw socket_close_error(make_error_string()); throw socket_close_error(make_error_string());
#else #else
@@ -305,7 +305,7 @@ PDU *PacketSender::send_recv(PDU &pdu, const NetworkInterface &iface) {
return pdu.recv_response(*this, 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, void PacketSender::send_l2(PDU &pdu, struct sockaddr* link_addr,
uint32_t len_addr, const NetworkInterface &iface) 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 // 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, PDU *PacketSender::recv_l2(PDU &pdu, struct sockaddr *link_addr,
uint32_t len_addr, const NetworkInterface &iface) uint32_t len_addr, const NetworkInterface &iface)
{ {
@@ -340,7 +340,7 @@ PDU *PacketSender::recv_l2(PDU &pdu, struct sockaddr *link_addr,
std::vector<int> sockets(1, sock); std::vector<int> sockets(1, sock);
return recv_match_loop(sockets, pdu, link_addr, len_addr); 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) { PDU *PacketSender::recv_l3(PDU &pdu, struct sockaddr* link_addr, uint32_t len_addr, SocketType type) {
open_l3_socket(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<int>& sockets, PDU &pdu, struct sockaddr* link_addr, uint32_t addrlen) { PDU *PacketSender::recv_match_loop(const std::vector<int>& sockets, PDU &pdu, struct sockaddr* link_addr, uint32_t addrlen) {
#ifdef WIN32 #ifdef _WIN32
typedef int socket_len_type; typedef int socket_len_type;
typedef int recvfrom_ret_type; typedef int recvfrom_ret_type;
#else #else
@@ -422,11 +422,11 @@ PDU *PacketSender::recv_match_loop(const std::vector<int>& sockets, PDU &pdu, st
} }
} }
struct timeval this_time, diff; struct timeval this_time, diff;
#ifdef WIN32 #ifdef _WIN32
// fixme // fixme
#else #else
gettimeofday(&this_time, 0); gettimeofday(&this_time, 0);
#endif // WIN32 #endif // _WIN32
if(timeval_subtract(&diff, &end_time, &this_time)) if(timeval_subtract(&diff, &end_time, &this_time))
return 0; return 0;
timeout.tv_sec = diff.tv_sec; timeout.tv_sec = diff.tv_sec;

View File

@@ -27,7 +27,7 @@
* *
*/ */
#ifndef WIN32 #ifndef _WIN32
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <stdexcept> #include <stdexcept>
@@ -49,7 +49,7 @@ PacketWriter::~PacketWriter() {
void PacketWriter::write(PDU &pdu) { void PacketWriter::write(PDU &pdu) {
PDU::serialization_type buffer = pdu.serialize(); PDU::serialization_type buffer = pdu.serialize();
timeval tm; timeval tm;
#ifndef WIN32 #ifndef _WIN32
gettimeofday(&tm, 0); gettimeofday(&tm, 0);
#else #else
// fixme // fixme

View File

@@ -37,7 +37,7 @@
#endif #endif
#include <stdexcept> #include <stdexcept>
#include "macros.h" #include "macros.h"
#ifndef WIN32 #ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h> #include <net/if_dl.h>
#else #else
@@ -430,7 +430,7 @@ uint8_t RadioTap::data_retries() const {
return _data_retries; return _data_retries;
} }
#ifndef WIN32 #ifndef _WIN32
void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) { void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) {
if(!iface) if(!iface)
throw invalid_interface(); throw invalid_interface();

View File

@@ -32,7 +32,7 @@
#include <cassert> #include <cassert>
#endif #endif
#include <stdexcept> #include <stdexcept>
#ifndef WIN32 #ifndef _WIN32
#include <sys/types.h> #include <sys/types.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#endif #endif

View File

@@ -27,11 +27,11 @@
* *
*/ */
#ifdef WIN32 #ifdef _WIN32
#define TINS_PREFIX_INTERFACE(x) ("\\Device\\NPF_" + x) #define TINS_PREFIX_INTERFACE(x) ("\\Device\\NPF_" + x)
#else // WIN32 #else // _WIN32
#define TINS_PREFIX_INTERFACE(x) (x) #define TINS_PREFIX_INTERFACE(x) (x)
#endif // WIN32 #endif // _WIN32
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
@@ -191,11 +191,11 @@ void BaseSniffer::stop_sniff() {
} }
int BaseSniffer::get_fd() { int BaseSniffer::get_fd() {
#ifndef WIN32 #ifndef _WIN32
return pcap_get_selectable_fd(handle); return pcap_get_selectable_fd(handle);
#else #else
throw std::runtime_error("Method not supported in Windows platform"); throw std::runtime_error("Method not supported in Windows platform");
#endif // WIN32 #endif // _WIN32
} }
int BaseSniffer::link_type() const { int BaseSniffer::link_type() const {
@@ -343,7 +343,7 @@ void Sniffer::set_promisc_mode(bool promisc_enabled)
void Sniffer::set_rfmon(bool rfmon_enabled) void Sniffer::set_rfmon(bool rfmon_enabled)
{ {
#ifndef WIN32 #ifndef _WIN32
if (pcap_can_set_rfmon(get_pcap_handle()) == 1) { if (pcap_can_set_rfmon(get_pcap_handle()) == 1) {
if (pcap_set_rfmon(get_pcap_handle(), rfmon_enabled)) { if (pcap_set_rfmon(get_pcap_handle(), rfmon_enabled)) {
throw runtime_error(pcap_geterr(get_pcap_handle())); throw runtime_error(pcap_geterr(get_pcap_handle()));

View File

@@ -33,7 +33,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include "utils.h" #include "utils.h"
#ifndef WIN32 #ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__) #if defined(BSD) || defined(__FreeBSD_kernel__)
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -61,7 +61,7 @@ using namespace std;
struct InterfaceCollector { struct InterfaceCollector {
set<string> ifaces; set<string> ifaces;
#ifdef WIN32 #ifdef _WIN32
bool operator() (PIP_ADAPTER_ADDRESSES addr) { bool operator() (PIP_ADAPTER_ADDRESSES addr) {
ifaces.insert(addr->AdapterName); ifaces.insert(addr->AdapterName);
return false; return false;

View File

@@ -3,7 +3,7 @@
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
#include "macros.h" #include "macros.h"
#ifndef WIN32 #ifndef _WIN32
#include <sys/socket.h> #include <sys/socket.h>
#ifdef BSD #ifdef BSD
#include <net/if_dl.h> #include <net/if_dl.h>
@@ -23,7 +23,7 @@ public:
}; };
#ifndef WIN32 #ifndef _WIN32
TEST_F(LoopbackTest, MatchesResponse) { TEST_F(LoopbackTest, MatchesResponse) {
Loopback loop1 = Loopback() / IP("192.168.0.1", "192.168.0.2") / TCP(22, 21); Loopback loop1 = Loopback() / IP("192.168.0.1", "192.168.0.2") / TCP(22, 21);
loop1.family(PF_INET); loop1.family(PF_INET);
@@ -32,4 +32,4 @@ TEST_F(LoopbackTest, MatchesResponse) {
PDU::serialization_type buffer = loop2.serialize(); PDU::serialization_type buffer = loop2.serialize();
EXPECT_TRUE(loop1.matches_response(&buffer[0], buffer.size())); EXPECT_TRUE(loop1.matches_response(&buffer[0], buffer.size()));
} }
#endif // WIN32 #endif // _WIN32

View File

@@ -21,7 +21,7 @@ const string NetworkInterfaceTest::iface_name("lo"),
NetworkInterfaceTest::iface_addr(""); NetworkInterfaceTest::iface_addr("");
#endif #endif
#ifndef WIN32 #ifndef _WIN32
TEST_F(NetworkInterfaceTest, ConstructorFromString) { TEST_F(NetworkInterfaceTest, ConstructorFromString) {
// just test this doesn't throw // just test this doesn't throw
NetworkInterface iface(iface_name); NetworkInterface iface(iface_name);
@@ -62,7 +62,7 @@ TEST_F(NetworkInterfaceTest, DistinctOperator) {
NetworkInterface iface1(iface_name), iface2; NetworkInterface iface1(iface_name), iface2;
EXPECT_NE(iface1, iface2); EXPECT_NE(iface1, iface2);
} }
#endif // WIN32 #endif // _WIN32
// This is a more generic test that can be run on all platforms. // 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. // The above ones won't run on windows since there's no name for the loopback interface.