Portability fixes.
This commit is contained in:
parent
315b00e861
commit
bf3e2e9fb0
|
@ -21,12 +21,9 @@
|
||||||
#ifdef HAVE_SYS_FILIO_H
|
#ifdef HAVE_SYS_FILIO_H
|
||||||
# include <sys/filio.h>
|
# include <sys/filio.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(__svr4__) || defined(__sun)
|
|
||||||
#include <sys/ioccom.h>
|
|
||||||
#ifdef HAVE_SYS_SOCKIO_H
|
#ifdef HAVE_SYS_SOCKIO_H
|
||||||
# include <sys/sockio.h>
|
# include <sys/sockio.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__EMX__)
|
#if defined(__EMX__)
|
||||||
# include <sys/so_ioctl.h>
|
# include <sys/so_ioctl.h>
|
||||||
|
@ -1384,11 +1381,28 @@ INT WINAPI WSAIoctl (SOCKET s,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct ws_sockaddr_in *ipTemp = (struct ws_sockaddr_in *)&ifInfo.ifr_netmask;
|
/* Trying to avoid some compile problems across platforms.
|
||||||
|
(Linux, FreeBSD, Solaris...) */
|
||||||
|
#ifndef ifr_netmask
|
||||||
|
#ifndef ifr_addr
|
||||||
|
intArray->iiNetmask.AddressIn.sin_family = AF_INET;
|
||||||
|
intArray->iiNetmask.AddressIn.sin_port = 0;
|
||||||
|
intArray->iiNetmask.AddressIn.sin_addr.ws_addr = 0;
|
||||||
|
ERR ("Unable to determine Netmask on your platform!\n");
|
||||||
|
#else
|
||||||
|
struct ws_sockaddr_in *ipTemp = (struct ws_sockaddr_in *)&ifInfo.ifr_addr;
|
||||||
|
|
||||||
intArray->iiNetmask.AddressIn.sin_family = AF_INET;
|
intArray->iiNetmask.AddressIn.sin_family = AF_INET;
|
||||||
intArray->iiNetmask.AddressIn.sin_port = ipTemp->sin_port;
|
intArray->iiNetmask.AddressIn.sin_port = ipTemp->sin_port;
|
||||||
intArray->iiNetmask.AddressIn.sin_addr.ws_addr = ipTemp->sin_addr.S_un.S_addr;
|
intArray->iiNetmask.AddressIn.sin_addr.ws_addr = ipTemp->sin_addr.S_un.S_addr;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
struct ws_sockaddr_in *ipTemp = (struct ws_sockaddr_in *)&ifInfo.ifr_netmask;
|
||||||
|
|
||||||
|
intArray->iiNetmask.AddressIn.sin_family = AF_INET;
|
||||||
|
intArray->iiNetmask.AddressIn.sin_port = ipTemp->sin_port;
|
||||||
|
intArray->iiNetmask.AddressIn.sin_addr.ws_addr = ipTemp->sin_addr.S_un.S_addr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Socket Status Flags */
|
/* Socket Status Flags */
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifdef HAVE_SYS_SOCKIO_H
|
||||||
|
# include <sys/sockio.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_NET_IF_H
|
#ifdef HAVE_NET_IF_H
|
||||||
# include <net/if.h>
|
# include <net/if.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -176,20 +179,39 @@ DWORD WINAPI WsControl(DWORD protocoll,
|
||||||
/* Interface ID */
|
/* Interface ID */
|
||||||
IntInfo->if_index = pcommand->toi_entity.tei_instance;
|
IntInfo->if_index = pcommand->toi_entity.tei_instance;
|
||||||
|
|
||||||
/* MAC Address */
|
/* MAC Address - Let's try to do this in a cross-platform way... */
|
||||||
strcpy(ifInfo.ifr_name, ifName);
|
#if defined(SIOCGIFHWADDR) /* Linux */
|
||||||
if (ioctl(sock, SIOCGIFHWADDR, &ifInfo) < 0)
|
strcpy(ifInfo.ifr_name, ifName);
|
||||||
{
|
if (ioctl(sock, SIOCGIFHWADDR, &ifInfo) < 0)
|
||||||
ERR ("Error obtaining MAC Address!\n");
|
{
|
||||||
close(sock);
|
ERR ("Error obtaining MAC Address!\n");
|
||||||
return (-1);
|
close(sock);
|
||||||
}
|
return (-1);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
/* FIXME: Is it correct to assume size of 6? */
|
{
|
||||||
memcpy(IntInfo->if_physaddr, ifInfo.ifr_hwaddr.sa_data, 6);
|
/* FIXME: Is it correct to assume size of 6? */
|
||||||
IntInfo->if_physaddrlen=6;
|
memcpy(IntInfo->if_physaddr, ifInfo.ifr_hwaddr.sa_data, 6);
|
||||||
}
|
IntInfo->if_physaddrlen=6;
|
||||||
|
}
|
||||||
|
#elif defined(SIOCGENADDR) /* Solaris */
|
||||||
|
if (ioctl(sock, SIOCGENADDR, &ifInfo) < 0)
|
||||||
|
{
|
||||||
|
ERR ("Error obtaining MAC Address!\n");
|
||||||
|
close(sock);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* FIXME: Is it correct to assume size of 6? */
|
||||||
|
memcpy(IntInfo->if_physaddr, ifInfo.ifr_enaddr, 6);
|
||||||
|
IntInfo->if_physaddrlen=6;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
memset (IntInfo->if_physaddr, 0, 6);
|
||||||
|
ERR ("Unable to determine MAC Address on your platform!\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Interface name and length */
|
/* Interface name and length */
|
||||||
strcpy (IntInfo->if_descr, ifName);
|
strcpy (IntInfo->if_descr, ifName);
|
||||||
|
@ -349,8 +371,20 @@ DWORD WINAPI WsControl(DWORD protocoll,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct ws_sockaddr_in *ipTemp = (struct ws_sockaddr_in *)&ifInfo.ifr_netmask;
|
/* Trying to avoid some compile problems across platforms.
|
||||||
baseIPInfo->iae_mask = ipTemp->sin_addr.S_un.S_addr;
|
(Linux, FreeBSD, Solaris...) */
|
||||||
|
#ifndef ifr_netmask
|
||||||
|
#ifndef ifr_addr
|
||||||
|
baseIPInfo->iae_mask = 0;
|
||||||
|
ERR ("Unable to determine Netmask on your platform!\n");
|
||||||
|
#else
|
||||||
|
struct ws_sockaddr_in *ipTemp = (struct ws_sockaddr_in *)&ifInfo.ifr_addr;
|
||||||
|
baseIPInfo->iae_mask = ipTemp->sin_addr.S_un.S_addr;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
struct ws_sockaddr_in *ipTemp = (struct ws_sockaddr_in *)&ifInfo.ifr_netmask;
|
||||||
|
baseIPInfo->iae_mask = ipTemp->sin_addr.S_un.S_addr;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: How should the below be properly calculated? ******************/
|
/* FIXME: How should the below be properly calculated? ******************/
|
||||||
|
@ -536,7 +570,7 @@ int WSCNTL_GetInterfaceName(int intNumber, char *intName)
|
||||||
Helper function for WsControl - This function returns the bytes (octets) transmitted
|
Helper function for WsControl - This function returns the bytes (octets) transmitted
|
||||||
and received for the supplied interface number from the /proc fs.
|
and received for the supplied interface number from the /proc fs.
|
||||||
*/
|
*/
|
||||||
int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes)
|
int WSCNTL_GetTransRecvStat(int intNumber, unsigned long *transBytes, unsigned long *recvBytes)
|
||||||
{
|
{
|
||||||
FILE *procfs;
|
FILE *procfs;
|
||||||
char buf[512], result[512]; /* Size doesn't matter, something big */
|
char buf[512], result[512]; /* Size doesn't matter, something big */
|
||||||
|
@ -616,7 +650,7 @@ int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes)
|
||||||
result[resultPos+1]='\0';
|
result[resultPos+1]='\0';
|
||||||
resultPos++; bufPos++;
|
resultPos++; bufPos++;
|
||||||
}
|
}
|
||||||
*recvBytes = strtoul (result, NULL, 10); /* convert string to ulong, using base 10 */
|
*recvBytes = strtoul (result, NULL, 10); /* convert string to unsigned long, using base 10 */
|
||||||
|
|
||||||
|
|
||||||
/* Skip columns #3 to #9 (Don't need them) */
|
/* Skip columns #3 to #9 (Don't need them) */
|
||||||
|
@ -640,7 +674,7 @@ int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes)
|
||||||
result[resultPos+1]='\0';
|
result[resultPos+1]='\0';
|
||||||
resultPos++; bufPos++;
|
resultPos++; bufPos++;
|
||||||
}
|
}
|
||||||
*transBytes = strtoul (result, NULL, 10); /* convert string to ulong, using base 10 */
|
*transBytes = strtoul (result, NULL, 10); /* convert string to unsigned long, using base 10 */
|
||||||
|
|
||||||
|
|
||||||
fclose(procfs);
|
fclose(procfs);
|
||||||
|
|
|
@ -22,7 +22,7 @@ typedef unsigned char uchar; /* This doesn't seem to be in any standard headers
|
||||||
/* WsControl Helper Functions */
|
/* WsControl Helper Functions */
|
||||||
int WSCNTL_GetInterfaceCount(void); /* Obtains the number of network interfaces */
|
int WSCNTL_GetInterfaceCount(void); /* Obtains the number of network interfaces */
|
||||||
int WSCNTL_GetInterfaceName(int, char *); /* Obtains the name of an interface */
|
int WSCNTL_GetInterfaceName(int, char *); /* Obtains the name of an interface */
|
||||||
int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes); /* Obtains bytes
|
int WSCNTL_GetTransRecvStat(int intNumber, unsigned long *transBytes, unsigned long *recvBytes); /* Obtains bytes
|
||||||
recv'd/trans by interface */
|
recv'd/trans by interface */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -37,55 +37,55 @@ int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes);
|
||||||
/* Structure of an entity ID */
|
/* Structure of an entity ID */
|
||||||
typedef struct TDIEntityID
|
typedef struct TDIEntityID
|
||||||
{
|
{
|
||||||
ulong tei_entity;
|
unsigned long tei_entity;
|
||||||
ulong tei_instance;
|
unsigned long tei_instance;
|
||||||
} TDIEntityID;
|
} TDIEntityID;
|
||||||
|
|
||||||
/* Structure of an object ID */
|
/* Structure of an object ID */
|
||||||
typedef struct TDIObjectID
|
typedef struct TDIObjectID
|
||||||
{
|
{
|
||||||
TDIEntityID toi_entity;
|
TDIEntityID toi_entity;
|
||||||
ulong toi_class;
|
unsigned long toi_class;
|
||||||
ulong toi_type;
|
unsigned long toi_type;
|
||||||
ulong toi_id;
|
unsigned long toi_id;
|
||||||
} TDIObjectID;
|
} TDIObjectID;
|
||||||
|
|
||||||
typedef struct IPSNMPInfo
|
typedef struct IPSNMPInfo
|
||||||
{
|
{
|
||||||
ulong ipsi_forwarding;
|
unsigned long ipsi_forwarding;
|
||||||
ulong ipsi_defaultttl;
|
unsigned long ipsi_defaultttl;
|
||||||
ulong ipsi_inreceives;
|
unsigned long ipsi_inreceives;
|
||||||
ulong ipsi_inhdrerrors;
|
unsigned long ipsi_inhdrerrors;
|
||||||
ulong ipsi_inaddrerrors;
|
unsigned long ipsi_inaddrerrors;
|
||||||
ulong ipsi_forwdatagrams;
|
unsigned long ipsi_forwdatagrams;
|
||||||
ulong ipsi_inunknownprotos;
|
unsigned long ipsi_inunknownprotos;
|
||||||
ulong ipsi_indiscards;
|
unsigned long ipsi_indiscards;
|
||||||
ulong ipsi_indelivers;
|
unsigned long ipsi_indelivers;
|
||||||
ulong ipsi_outrequests;
|
unsigned long ipsi_outrequests;
|
||||||
ulong ipsi_routingdiscards;
|
unsigned long ipsi_routingdiscards;
|
||||||
ulong ipsi_outdiscards;
|
unsigned long ipsi_outdiscards;
|
||||||
ulong ipsi_outnoroutes;
|
unsigned long ipsi_outnoroutes;
|
||||||
ulong ipsi_reasmtimeout;
|
unsigned long ipsi_reasmtimeout;
|
||||||
ulong ipsi_reasmreqds;
|
unsigned long ipsi_reasmreqds;
|
||||||
ulong ipsi_reasmoks;
|
unsigned long ipsi_reasmoks;
|
||||||
ulong ipsi_reasmfails;
|
unsigned long ipsi_reasmfails;
|
||||||
ulong ipsi_fragoks;
|
unsigned long ipsi_fragoks;
|
||||||
ulong ipsi_fragfails;
|
unsigned long ipsi_fragfails;
|
||||||
ulong ipsi_fragcreates;
|
unsigned long ipsi_fragcreates;
|
||||||
ulong ipsi_numif;
|
unsigned long ipsi_numif;
|
||||||
ulong ipsi_numaddr;
|
unsigned long ipsi_numaddr;
|
||||||
ulong ipsi_numroutes;
|
unsigned long ipsi_numroutes;
|
||||||
} IPSNMPInfo;
|
} IPSNMPInfo;
|
||||||
|
|
||||||
typedef struct IPAddrEntry
|
typedef struct IPAddrEntry
|
||||||
{
|
{
|
||||||
ulong iae_addr;
|
unsigned long iae_addr;
|
||||||
ulong iae_index;
|
unsigned long iae_index;
|
||||||
ulong iae_mask;
|
unsigned long iae_mask;
|
||||||
ulong iae_bcastaddr;
|
unsigned long iae_bcastaddr;
|
||||||
ulong iae_reasmsize;
|
unsigned long iae_reasmsize;
|
||||||
ushort iae_context;
|
ushort iae_context;
|
||||||
ushort iae_pad;
|
ushort iae_pad;
|
||||||
} IPAddrEntry;
|
} IPAddrEntry;
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,29 +93,29 @@ typedef struct IPAddrEntry
|
||||||
#define MAX_IFDESCR_LEN 256
|
#define MAX_IFDESCR_LEN 256
|
||||||
typedef struct IFEntry
|
typedef struct IFEntry
|
||||||
{
|
{
|
||||||
ulong if_index;
|
unsigned long if_index;
|
||||||
ulong if_type;
|
unsigned long if_type;
|
||||||
ulong if_mtu;
|
unsigned long if_mtu;
|
||||||
ulong if_speed;
|
unsigned long if_speed;
|
||||||
ulong if_physaddrlen;
|
unsigned long if_physaddrlen;
|
||||||
uchar if_physaddr[MAX_PHYSADDR_SIZE];
|
uchar if_physaddr[MAX_PHYSADDR_SIZE];
|
||||||
ulong if_adminstatus;
|
unsigned long if_adminstatus;
|
||||||
ulong if_operstatus;
|
unsigned long if_operstatus;
|
||||||
ulong if_lastchange;
|
unsigned long if_lastchange;
|
||||||
ulong if_inoctets;
|
unsigned long if_inoctets;
|
||||||
ulong if_inucastpkts;
|
unsigned long if_inucastpkts;
|
||||||
ulong if_innucastpkts;
|
unsigned long if_innucastpkts;
|
||||||
ulong if_indiscards;
|
unsigned long if_indiscards;
|
||||||
ulong if_inerrors;
|
unsigned long if_inerrors;
|
||||||
ulong if_inunknownprotos;
|
unsigned long if_inunknownprotos;
|
||||||
ulong if_outoctets;
|
unsigned long if_outoctets;
|
||||||
ulong if_outucastpkts;
|
unsigned long if_outucastpkts;
|
||||||
ulong if_outnucastpkts;
|
unsigned long if_outnucastpkts;
|
||||||
ulong if_outdiscards;
|
unsigned long if_outdiscards;
|
||||||
ulong if_outerrors;
|
unsigned long if_outerrors;
|
||||||
ulong if_outqlen;
|
unsigned long if_outqlen;
|
||||||
ulong if_descrlen;
|
unsigned long if_descrlen;
|
||||||
uchar if_descr[1];
|
uchar if_descr[1];
|
||||||
} IFEntry;
|
} IFEntry;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue