Skip to content

Commit

Permalink
CNetworkInfo::getNetworkInterface() FreeBSD support
Browse files Browse the repository at this point in the history
modified IPv4 default routing information request code to support FreeBSD
  • Loading branch information
jg1uaa committed Oct 7, 2020
1 parent f2c3993 commit 630551f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions NetworkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
#include <clocale>

#include <sys/types.h>
#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__)
#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
#include <ifaddrs.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#if defined(__OpenBSD__) || defined(__NetBSD__)
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
Expand Down Expand Up @@ -66,7 +66,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)

::strcpy((char*)info, "(address unknown)");

#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__)
#if defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
char* dflt = NULL;

#if defined(__linux__)
Expand All @@ -91,15 +91,15 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)

::fclose(fp);

#elif defined(__OpenBSD__) || defined(__NetBSD__)
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)
const int mib[] = {
CTL_NET,
PF_ROUTE,
0, // protocol
AF_INET, // IPv4 routing
NET_RT_DUMP,
0, // show all routes
#if defined(__OpenBSD__)
#if defined(__OpenBSD__) || defined(__FreeBSD__)
0, // table id
#endif
};
Expand All @@ -126,7 +126,7 @@ void CNetworkInfo::getNetworkInterface(unsigned char* info)
continue;
#if defined(__OpenBSD__)
struct sockaddr_in *sa = (struct sockaddr_in *)(p + rtm->rtm_hdrlen);
#elif defined(__NetBSD__)
#elif defined(__NetBSD__) || defined(__FreeBSD__)
struct sockaddr_in *sa = (struct sockaddr_in *)(rtm + 1);
#endif
if (sa->sin_addr.s_addr == INADDR_ANY) {
Expand Down

0 comments on commit 630551f

Please sign in to comment.