Portability fixes.

This commit is contained in:
James Hatheway 2000-07-25 17:45:50 +00:00 committed by Alexandre Julliard
parent 315b00e861
commit bf3e2e9fb0
3 changed files with 134 additions and 86 deletions

View File

@ -21,12 +21,9 @@
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
#if defined(__svr4__) || defined(__sun)
#include <sys/ioccom.h>
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
#endif
#if defined(__EMX__)
# include <sys/so_ioctl.h>
@ -1384,11 +1381,28 @@ INT WINAPI WSAIoctl (SOCKET s,
}
else
{
/* 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_port = ipTemp->sin_port;
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 */

View File

@ -17,6 +17,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
#ifdef HAVE_NET_IF_H
# include <net/if.h>
#endif
@ -176,7 +179,8 @@ DWORD WINAPI WsControl(DWORD protocoll,
/* Interface ID */
IntInfo->if_index = pcommand->toi_entity.tei_instance;
/* MAC Address */
/* MAC Address - Let's try to do this in a cross-platform way... */
#if defined(SIOCGIFHWADDR) /* Linux */
strcpy(ifInfo.ifr_name, ifName);
if (ioctl(sock, SIOCGIFHWADDR, &ifInfo) < 0)
{
@ -190,6 +194,24 @@ DWORD WINAPI WsControl(DWORD protocoll,
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 */
strcpy (IntInfo->if_descr, ifName);
@ -349,8 +371,20 @@ DWORD WINAPI WsControl(DWORD protocoll,
}
else
{
/* Trying to avoid some compile problems across platforms.
(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? ******************/
@ -536,7 +570,7 @@ int WSCNTL_GetInterfaceName(int intNumber, char *intName)
Helper function for WsControl - This function returns the bytes (octets) transmitted
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;
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';
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) */
@ -640,7 +674,7 @@ int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes)
result[resultPos+1]='\0';
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);

View File

@ -22,7 +22,7 @@ typedef unsigned char uchar; /* This doesn't seem to be in any standard headers
/* WsControl Helper Functions */
int WSCNTL_GetInterfaceCount(void); /* Obtains the number of network interfaces */
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 */
/*
@ -37,53 +37,53 @@ int WSCNTL_GetTransRecvStat(int intNumber, ulong *transBytes, ulong *recvBytes);
/* Structure of an entity ID */
typedef struct TDIEntityID
{
ulong tei_entity;
ulong tei_instance;
unsigned long tei_entity;
unsigned long tei_instance;
} TDIEntityID;
/* Structure of an object ID */
typedef struct TDIObjectID
{
TDIEntityID toi_entity;
ulong toi_class;
ulong toi_type;
ulong toi_id;
unsigned long toi_class;
unsigned long toi_type;
unsigned long toi_id;
} TDIObjectID;
typedef struct IPSNMPInfo
{
ulong ipsi_forwarding;
ulong ipsi_defaultttl;
ulong ipsi_inreceives;
ulong ipsi_inhdrerrors;
ulong ipsi_inaddrerrors;
ulong ipsi_forwdatagrams;
ulong ipsi_inunknownprotos;
ulong ipsi_indiscards;
ulong ipsi_indelivers;
ulong ipsi_outrequests;
ulong ipsi_routingdiscards;
ulong ipsi_outdiscards;
ulong ipsi_outnoroutes;
ulong ipsi_reasmtimeout;
ulong ipsi_reasmreqds;
ulong ipsi_reasmoks;
ulong ipsi_reasmfails;
ulong ipsi_fragoks;
ulong ipsi_fragfails;
ulong ipsi_fragcreates;
ulong ipsi_numif;
ulong ipsi_numaddr;
ulong ipsi_numroutes;
unsigned long ipsi_forwarding;
unsigned long ipsi_defaultttl;
unsigned long ipsi_inreceives;
unsigned long ipsi_inhdrerrors;
unsigned long ipsi_inaddrerrors;
unsigned long ipsi_forwdatagrams;
unsigned long ipsi_inunknownprotos;
unsigned long ipsi_indiscards;
unsigned long ipsi_indelivers;
unsigned long ipsi_outrequests;
unsigned long ipsi_routingdiscards;
unsigned long ipsi_outdiscards;
unsigned long ipsi_outnoroutes;
unsigned long ipsi_reasmtimeout;
unsigned long ipsi_reasmreqds;
unsigned long ipsi_reasmoks;
unsigned long ipsi_reasmfails;
unsigned long ipsi_fragoks;
unsigned long ipsi_fragfails;
unsigned long ipsi_fragcreates;
unsigned long ipsi_numif;
unsigned long ipsi_numaddr;
unsigned long ipsi_numroutes;
} IPSNMPInfo;
typedef struct IPAddrEntry
{
ulong iae_addr;
ulong iae_index;
ulong iae_mask;
ulong iae_bcastaddr;
ulong iae_reasmsize;
unsigned long iae_addr;
unsigned long iae_index;
unsigned long iae_mask;
unsigned long iae_bcastaddr;
unsigned long iae_reasmsize;
ushort iae_context;
ushort iae_pad;
} IPAddrEntry;
@ -93,28 +93,28 @@ typedef struct IPAddrEntry
#define MAX_IFDESCR_LEN 256
typedef struct IFEntry
{
ulong if_index;
ulong if_type;
ulong if_mtu;
ulong if_speed;
ulong if_physaddrlen;
unsigned long if_index;
unsigned long if_type;
unsigned long if_mtu;
unsigned long if_speed;
unsigned long if_physaddrlen;
uchar if_physaddr[MAX_PHYSADDR_SIZE];
ulong if_adminstatus;
ulong if_operstatus;
ulong if_lastchange;
ulong if_inoctets;
ulong if_inucastpkts;
ulong if_innucastpkts;
ulong if_indiscards;
ulong if_inerrors;
ulong if_inunknownprotos;
ulong if_outoctets;
ulong if_outucastpkts;
ulong if_outnucastpkts;
ulong if_outdiscards;
ulong if_outerrors;
ulong if_outqlen;
ulong if_descrlen;
unsigned long if_adminstatus;
unsigned long if_operstatus;
unsigned long if_lastchange;
unsigned long if_inoctets;
unsigned long if_inucastpkts;
unsigned long if_innucastpkts;
unsigned long if_indiscards;
unsigned long if_inerrors;
unsigned long if_inunknownprotos;
unsigned long if_outoctets;
unsigned long if_outucastpkts;
unsigned long if_outnucastpkts;
unsigned long if_outdiscards;
unsigned long if_outerrors;
unsigned long if_outqlen;
unsigned long if_descrlen;
uchar if_descr[1];
} IFEntry;