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

@@ -39,7 +39,7 @@
#include "macros.h"
#include "exceptions.h"
#ifndef WIN32
#ifndef _WIN32
#if defined(__FreeBSD_kernel__) || defined(BSD) || defined(__APPLE__)
#include <sys/types.h>
#include <net/if_dl.h>
@@ -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

View File

@@ -34,7 +34,7 @@
#include <stdexcept>
#include <algorithm>
#include "macros.h"
#ifndef WIN32
#ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h>
#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
}

View File

@@ -34,7 +34,7 @@
#include <stdexcept>
#include <algorithm>
#include "macros.h"
#ifndef WIN32
#ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h>
#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
}

View File

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

View File

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

View File

@@ -27,12 +27,12 @@
*
*/
#ifdef WIN32
#ifdef _WIN32
#include <ws2tcpip.h>
#else // WIN32
#else // _WIN32
#include <sys/socket.h>
#include <arpa/inet.h>
#endif // WIN32
#endif // _WIN32
#include <stdexcept>
#include <sstream>
#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) {

View File

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

View File

@@ -29,7 +29,7 @@
#include <algorithm>
#include "macros.h"
#ifndef WIN32
#ifndef _WIN32
#include <arpa/inet.h>
#ifdef BSD
#include <sys/socket.h>
@@ -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)

View File

@@ -27,7 +27,7 @@
*
*/
#ifndef WIN32
#ifndef _WIN32
#include <sys/socket.h>
#ifdef BSD
#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);
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<const Tins::IP*>(inner_pdu()))
_family = PF_INET;
else if(tins_cast<const Tins::LLC*>(inner_pdu()))
_family = PF_LLC;
*reinterpret_cast<uint32_t*>(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
}

View File

@@ -31,7 +31,7 @@
#include <vector>
#include <cstring>
#include "macros.h"
#ifndef WIN32
#ifndef _WIN32
#include <netinet/in.h>
#if defined(BSD) || defined(__FreeBSD_kernel__)
#include <ifaddrs.h>
@@ -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<uint8_t> 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");

View File

@@ -28,7 +28,7 @@
*/
#include "packet_sender.h"
#ifndef WIN32
#ifndef _WIN32
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
@@ -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<int> 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<int>& 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<int>& 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;

View File

@@ -27,7 +27,7 @@
*
*/
#ifndef WIN32
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <stdexcept>
@@ -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

View File

@@ -37,7 +37,7 @@
#endif
#include <stdexcept>
#include "macros.h"
#ifndef WIN32
#ifndef _WIN32
#if defined(BSD) || defined(__FreeBSD_kernel__)
#include <net/if_dl.h>
#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();

View File

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

View File

@@ -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 <algorithm>
#include <sstream>
@@ -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()));

View File

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