/* ifenum.h
- * Copyright (C) 2003 Juan Lang
+ * Copyright (C) 2003,2006 Juan Lang
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
- * This module implements functions shared by DLLs that need to enumerate
- * network interfaces and addresses. It's meant to hide some problematic
- * defines like socket(), as well as provide only one file
- * that needs to be ported to implement these functions on different platforms,
- * since the Windows API provides multiple ways to get at this info.
+ * This module implements network interface and address enumeration. It's
+ * meant to hide some problematic defines like socket(), and make iphlpapi
+ * more portable.
*
* Like Windows, it uses a numeric index to identify an interface uniquely.
* As implemented, an interface represents a UNIX network interface, virtual
* only supports IPv4.)
* The indexes returned are not guaranteed to be contiguous, so don't call
* getNumInterfaces() and assume the values [0,getNumInterfaces() - 1] will be
- * valid indexes; use getInterfaceIndexTable() instead. Non-loopback
- * interfaces have lower index values than loopback interfaces, in order to
- * make the indexes somewhat reusable as Netbios LANA numbers. See ifenum.c
- * for more detail on this.
+ * valid indexes; use getInterfaceIndexTable() instead.
*
* See also the companion file, ipstats.h, for functions related to getting
* statistics.
#define MAX_INTERFACE_PHYSADDR 8
#define MAX_INTERFACE_DESCRIPTION 256
-/* Call before using the functions in this module */
-void interfaceMapInit(void);
-/* Call to free resources allocated in interfaceMapInit() */
-void interfaceMapFree(void);
-
DWORD getNumInterfaces(void);
DWORD getNumNonLoopbackInterfaces(void);
-/* A table of interface indexes, see get*InterfaceTable(). Ignore numAllocated,
- * it's used during the creation of the table.
- */
+/* A table of interface indexes, see get*InterfaceTable(). */
typedef struct _InterfaceIndexTable {
DWORD numIndexes;
- DWORD numAllocated;
DWORD indexes[1];
} InterfaceIndexTable;
/* 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);
/* ByName/ByIndex versions of various getter functions. */
/* can be used as quick check to see if you've got a valid index, returns NULL
- * if not. The buffer's only valid till the next call, so copy it right away
- * if you care.
+ * if not. Overwrites your buffer, which should be at least of size
+ * MAX_ADAPTER_NAME.
*/
-const char *getInterfaceNameByIndex(DWORD index);
+char *getInterfaceNameByIndex(DWORD index, char *name);
/* Fills index with the index of name, if found. Returns
* ERROR_INVALID_PARAMETER if name or index is NULL, ERROR_INVALID_DATA if name
*/
DWORD getInterfaceIndexByName(const char *name, PDWORD index);
-/* This bunch returns IP addresses, and INADDR_ANY or INADDR_NONE if not found,
- * appropriately depending on the f/n.
- */
-DWORD getInterfaceIPAddrByName(const char *name);
-DWORD getInterfaceIPAddrByIndex(DWORD index);
-DWORD getInterfaceMaskByName(const char *name);
-DWORD getInterfaceMaskByIndex(DWORD index);
-DWORD getInterfaceBCastAddrByName(const char *name);
-DWORD getInterfaceBCastAddrByIndex(DWORD index);
-
/* Gets a few physical charactersistics of a device: MAC addr len, MAC addr,
* and type as one of the MIB_IF_TYPEs.
* len's in-out: on in, needs to say how many bytes are available in addr,
DWORD getInterfacePhysicalByIndex(DWORD index, PDWORD len, PBYTE addr,
PDWORD type);
-/* Get the operational status as a (MIB_)IF_OPER_STATUS type.
- */
-DWORD getInterfaceStatusByName(const char *name, PDWORD status);
-DWORD getInterfaceStatusByIndex(DWORD index, PDWORD status);
-
-DWORD getInterfaceMtuByName(const char *name, PDWORD mtu);
-DWORD getInterfaceMtuByIndex(DWORD index, PDWORD mtu);
-
/* Fills in the MIB_IFROW by name/index. Doesn't fill in interface statistics,
* see ipstats.h for that.
* Returns ERROR_INVALID_PARAMETER if name or entry is NULL, ERROR_INVALID_DATA
DWORD getInterfaceEntryByName(const char *name, PMIB_IFROW entry);
DWORD getInterfaceEntryByIndex(DWORD index, PMIB_IFROW entry);
+DWORD getNumIPAddresses(void);
+
+/* Gets the configured IP addresses for the system, and sets *ppIpAddrTable to
+ * a table of them allocated from heap, or NULL if out of memory. Returns
+ * NO_ERROR on success, something else on failure. Note there may be more than
+ * one IP address may exist per interface.
+ */
+DWORD getIPAddrTable(PMIB_IPADDRTABLE *ppIpAddrTable, HANDLE heap, DWORD flags);
+
/* Converts the network-order bytes in addr to a printable string. Returns
* string.
*/