- use Heap functions rather than libc for mem allocation
- document a bunch of functions
This commit is contained in:
parent
53b71e464a
commit
76d8779c6f
|
@ -33,7 +33,6 @@
|
||||||
* than my current mess would probably be better.
|
* than my current mess would probably be better.
|
||||||
* FIXME:
|
* FIXME:
|
||||||
* - I don't support IPv6 addresses here, since SIOCGIFCONF can't return them
|
* - I don't support IPv6 addresses here, since SIOCGIFCONF can't return them
|
||||||
* - the memory interface uses malloc/free; it should be using HeapAlloc instead
|
|
||||||
*
|
*
|
||||||
* There are three implemened methods for determining the MAC address of an
|
* There are three implemened methods for determining the MAC address of an
|
||||||
* interface:
|
* interface:
|
||||||
|
@ -154,9 +153,9 @@ void interfaceMapFree(void)
|
||||||
{
|
{
|
||||||
DeleteCriticalSection(&mapCS);
|
DeleteCriticalSection(&mapCS);
|
||||||
if (gNonLoopbackInterfaceMap)
|
if (gNonLoopbackInterfaceMap)
|
||||||
free(gNonLoopbackInterfaceMap);
|
HeapFree(GetProcessHeap(), 0, gNonLoopbackInterfaceMap);
|
||||||
if (gLoopbackInterfaceMap)
|
if (gLoopbackInterfaceMap)
|
||||||
free(gLoopbackInterfaceMap);
|
HeapFree(GetProcessHeap(), 0, gLoopbackInterfaceMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sizes the passed-in map to have enough space for numInterfaces interfaces.
|
/* Sizes the passed-in map to have enough space for numInterfaces interfaces.
|
||||||
|
@ -168,14 +167,16 @@ static InterfaceNameMap *sizeMap(InterfaceNameMap *map, DWORD numInterfaces)
|
||||||
{
|
{
|
||||||
if (!map) {
|
if (!map) {
|
||||||
numInterfaces = max(numInterfaces, INITIAL_INTERFACES_ASSUMED);
|
numInterfaces = max(numInterfaces, INITIAL_INTERFACES_ASSUMED);
|
||||||
map = (InterfaceNameMap *)calloc(1, sizeof(InterfaceNameMap) +
|
map = (InterfaceNameMap *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(InterfaceNameMap) +
|
||||||
(numInterfaces - 1) * sizeof(InterfaceNameMapEntry));
|
(numInterfaces - 1) * sizeof(InterfaceNameMapEntry));
|
||||||
if (map)
|
if (map)
|
||||||
map->numAllocated = numInterfaces;
|
map->numAllocated = numInterfaces;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (map->numAllocated < numInterfaces) {
|
if (map->numAllocated < numInterfaces) {
|
||||||
map = (InterfaceNameMap *)realloc(map, sizeof(InterfaceNameMap) +
|
map = (InterfaceNameMap *)HeapReAlloc(GetProcessHeap(), 0, map,
|
||||||
|
sizeof(InterfaceNameMap) +
|
||||||
(numInterfaces - 1) * sizeof(InterfaceNameMapEntry));
|
(numInterfaces - 1) * sizeof(InterfaceNameMapEntry));
|
||||||
if (map)
|
if (map)
|
||||||
memset(&map->table[map->numAllocated], 0,
|
memset(&map->table[map->numAllocated], 0,
|
||||||
|
@ -321,9 +322,9 @@ static void enumerateInterfaces(void)
|
||||||
else
|
else
|
||||||
guessedNumInterfaces *= 2;
|
guessedNumInterfaces *= 2;
|
||||||
if (ifc.ifc_buf)
|
if (ifc.ifc_buf)
|
||||||
free(ifc.ifc_buf);
|
HeapFree(GetProcessHeap(), 0, ifc.ifc_buf);
|
||||||
ifc.ifc_len = sizeof(struct ifreq) * guessedNumInterfaces;
|
ifc.ifc_len = sizeof(struct ifreq) * guessedNumInterfaces;
|
||||||
ifc.ifc_buf = (char *)malloc(ifc.ifc_len);
|
ifc.ifc_buf = (char *)HeapAlloc(GetProcessHeap(), 0, ifc.ifc_len);
|
||||||
ret = ioctl(fd, SIOCGIFCONF, &ifc);
|
ret = ioctl(fd, SIOCGIFCONF, &ifc);
|
||||||
} while (ret == 0 &&
|
} while (ret == 0 &&
|
||||||
ifc.ifc_len == (sizeof(struct ifreq) * guessedNumInterfaces));
|
ifc.ifc_len == (sizeof(struct ifreq) * guessedNumInterfaces));
|
||||||
|
@ -336,7 +337,7 @@ static void enumerateInterfaces(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ifc.ifc_buf)
|
if (ifc.ifc_buf)
|
||||||
free(ifc.ifc_buf);
|
HeapFree(GetProcessHeap(), 0, ifc.ifc_buf);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,7 +433,7 @@ InterfaceIndexTable *getInterfaceIndexTable(void)
|
||||||
|
|
||||||
EnterCriticalSection(&mapCS);
|
EnterCriticalSection(&mapCS);
|
||||||
numInterfaces = getNumInterfaces();
|
numInterfaces = getNumInterfaces();
|
||||||
ret = (InterfaceIndexTable *)calloc(1,
|
ret = (InterfaceIndexTable *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
sizeof(InterfaceIndexTable) + (numInterfaces - 1) * sizeof(DWORD));
|
sizeof(InterfaceIndexTable) + (numInterfaces - 1) * sizeof(DWORD));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret->numAllocated = numInterfaces;
|
ret->numAllocated = numInterfaces;
|
||||||
|
@ -450,7 +451,7 @@ InterfaceIndexTable *getNonLoopbackInterfaceIndexTable(void)
|
||||||
|
|
||||||
EnterCriticalSection(&mapCS);
|
EnterCriticalSection(&mapCS);
|
||||||
numInterfaces = getNumNonLoopbackInterfaces();
|
numInterfaces = getNumNonLoopbackInterfaces();
|
||||||
ret = (InterfaceIndexTable *)calloc(1,
|
ret = (InterfaceIndexTable *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
sizeof(InterfaceIndexTable) + (numInterfaces - 1) * sizeof(DWORD));
|
sizeof(InterfaceIndexTable) + (numInterfaces - 1) * sizeof(DWORD));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ret->numAllocated = numInterfaces;
|
ret->numAllocated = numInterfaces;
|
||||||
|
@ -719,12 +720,12 @@ DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
|
||||||
if (sysctl(mib, 6, NULL, &mibLen, NULL, 0) < 0)
|
if (sysctl(mib, 6, NULL, &mibLen, NULL, 0) < 0)
|
||||||
return ERROR_NO_MORE_FILES;
|
return ERROR_NO_MORE_FILES;
|
||||||
|
|
||||||
buf = (u_char *)malloc(mibLen);
|
buf = (u_char *)HeapAlloc(GetProcessHeap(), 0, mibLen);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return ERROR_NOT_ENOUGH_MEMORY;
|
return ERROR_NOT_ENOUGH_MEMORY;
|
||||||
|
|
||||||
if (sysctl(mib, 6, buf, &mibLen, NULL, 0) < 0) {
|
if (sysctl(mib, 6, buf, &mibLen, NULL, 0) < 0) {
|
||||||
free(buf);
|
HeapFree(GetProcessHeap(), 0, buf);
|
||||||
return ERROR_NO_MORE_FILES;
|
return ERROR_NO_MORE_FILES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,7 +787,7 @@ DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
|
||||||
ret = NO_ERROR;
|
ret = NO_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buf);
|
HeapFree(GetProcessHeap(), 0, buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,7 +62,7 @@ typedef struct _InterfaceIndexTable {
|
||||||
} InterfaceIndexTable;
|
} InterfaceIndexTable;
|
||||||
|
|
||||||
/* Returns a table with all known interface indexes, or NULL if one could not
|
/* Returns a table with all known interface indexes, or NULL if one could not
|
||||||
* be allocated. free() the returned table.
|
* be allocated. HeapFree() the returned table.
|
||||||
*/
|
*/
|
||||||
InterfaceIndexTable *getInterfaceIndexTable(void);
|
InterfaceIndexTable *getInterfaceIndexTable(void);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -565,8 +565,8 @@ RouteTable *getRouteTable(void)
|
||||||
DWORD numRoutes = getNumRoutes();
|
DWORD numRoutes = getNumRoutes();
|
||||||
RouteTable *ret;
|
RouteTable *ret;
|
||||||
|
|
||||||
ret = (RouteTable *)calloc(1, sizeof(RouteTable) +
|
ret = (RouteTable *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
(numRoutes - 1) * sizeof(RouteEntry));
|
sizeof(RouteTable) + (numRoutes - 1) * sizeof(RouteEntry));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
@ -638,8 +638,8 @@ PMIB_IPNETTABLE getArpTable(void)
|
||||||
DWORD numEntries = getNumArpEntries();
|
DWORD numEntries = getNumArpEntries();
|
||||||
PMIB_IPNETTABLE ret;
|
PMIB_IPNETTABLE ret;
|
||||||
|
|
||||||
ret = (PMIB_IPNETTABLE)calloc(1, sizeof(MIB_IPNETTABLE) +
|
ret = (PMIB_IPNETTABLE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
(numEntries - 1) * sizeof(MIB_IPNETROW));
|
sizeof(MIB_IPNETTABLE) + (numEntries - 1) * sizeof(MIB_IPNETROW));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
@ -716,8 +716,8 @@ PMIB_UDPTABLE getUdpTable(void)
|
||||||
DWORD numEntries = getNumUdpEntries();
|
DWORD numEntries = getNumUdpEntries();
|
||||||
PMIB_UDPTABLE ret;
|
PMIB_UDPTABLE ret;
|
||||||
|
|
||||||
ret = (PMIB_UDPTABLE)calloc(1, sizeof(MIB_UDPTABLE) +
|
ret = (PMIB_UDPTABLE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
(numEntries - 1) * sizeof(MIB_UDPROW));
|
sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
@ -768,8 +768,8 @@ PMIB_TCPTABLE getTcpTable(void)
|
||||||
DWORD numEntries = getNumTcpEntries();
|
DWORD numEntries = getNumTcpEntries();
|
||||||
PMIB_TCPTABLE ret;
|
PMIB_TCPTABLE ret;
|
||||||
|
|
||||||
ret = (PMIB_TCPTABLE)calloc(1, sizeof(MIB_TCPTABLE) +
|
ret = (PMIB_TCPTABLE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
||||||
(numEntries - 1) * sizeof(MIB_TCPROW));
|
sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ typedef struct _RouteTable {
|
||||||
} RouteTable;
|
} RouteTable;
|
||||||
|
|
||||||
/* Allocates and returns to you the route table, or NULL if it can't allocate
|
/* Allocates and returns to you the route table, or NULL if it can't allocate
|
||||||
* enough memory. free() the returned table.
|
* enough memory. HeapFree() the returned table.
|
||||||
*/
|
*/
|
||||||
RouteTable *getRouteTable(void);
|
RouteTable *getRouteTable(void);
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ RouteTable *getRouteTable(void);
|
||||||
DWORD getNumArpEntries(void);
|
DWORD getNumArpEntries(void);
|
||||||
|
|
||||||
/* Allocates and returns to you the arp table, or NULL if it can't allocate
|
/* Allocates and returns to you the arp table, or NULL if it can't allocate
|
||||||
* enough memory. free() the returned table.
|
* enough memory. HeapFree() the returned table.
|
||||||
*/
|
*/
|
||||||
PMIB_IPNETTABLE getArpTable(void);
|
PMIB_IPNETTABLE getArpTable(void);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ PMIB_IPNETTABLE getArpTable(void);
|
||||||
DWORD getNumUdpEntries(void);
|
DWORD getNumUdpEntries(void);
|
||||||
|
|
||||||
/* Allocates and returns to you the UDP state table, or NULL if it can't
|
/* Allocates and returns to you the UDP state table, or NULL if it can't
|
||||||
* allocate enough memory. free() the returned table.
|
* allocate enough memory. HeapFree() the returned table.
|
||||||
*/
|
*/
|
||||||
PMIB_UDPTABLE getUdpTable(void);
|
PMIB_UDPTABLE getUdpTable(void);
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ PMIB_UDPTABLE getUdpTable(void);
|
||||||
DWORD getNumTcpEntries(void);
|
DWORD getNumTcpEntries(void);
|
||||||
|
|
||||||
/* Allocates and returns to you the TCP state table, or NULL if it can't
|
/* Allocates and returns to you the TCP state table, or NULL if it can't
|
||||||
* allocate enough memory. free() the returned table.
|
* allocate enough memory. HeapFree() the returned table.
|
||||||
*/
|
*/
|
||||||
PMIB_TCPTABLE getTcpTable(void);
|
PMIB_TCPTABLE getTcpTable(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue