2 * Copyright (C) 2003 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * This module implements functions shared by DLLs that need to enumerate
19 * network interfaces and addresses. It's meant to hide some problematic
20 * defines like socket(), as well as provide only one file
21 * that needs to be ported to implement these functions on different platforms,
22 * since the Windows API provides multiple ways to get at this info.
24 * Like Windows, it uses a numeric index to identify an interface uniquely.
25 * As implemented, an interface represents a UNIX network interface, virtual
26 * or real, and thus can have 0 or 1 IP addresses associated with it. (This
27 * only supports IPv4.)
28 * The indexes returned are not guaranteed to be contiguous, so don't call
29 * getNumInterfaces() and assume the values [0,getNumInterfaces() - 1] will be
30 * valid indexes; use getInterfaceIndexTable() instead. Non-loopback
31 * interfaces have lower index values than loopback interfaces, in order to
32 * make the indexes somewhat reusable as Netbios LANA numbers. See ifenum.c
33 * for more detail on this.
35 * See also the companion file, ipstats.h, for functions related to getting
38 #ifndef WINE_IFENUM_H_
39 #define WINE_IFENUM_H_
44 #define MAX_INTERFACE_PHYSADDR 8
45 #define MAX_INTERFACE_DESCRIPTION 256
47 DWORD getNumInterfaces(void);
48 DWORD getNumNonLoopbackInterfaces(void);
50 /* A table of interface indexes, see get*InterfaceTable(). Ignore numAllocated,
51 * it's used during the creation of the table.
53 typedef struct _InterfaceIndexTable {
57 } InterfaceIndexTable;
59 /* Returns a table with all known interface indexes, or NULL if one could not
60 * be allocated. free() the returned table.
62 InterfaceIndexTable *getInterfaceIndexTable(void);
64 /* Like getInterfaceIndexTable, but filters out loopback interfaces. */
65 InterfaceIndexTable *getNonLoopbackInterfaceIndexTable(void);
67 /* ByName/ByIndex versions of various getter functions. */
69 /* can be used as quick check to see if you've got a valid index, returns NULL
70 * if not. The buffer's only valid till the next call, so copy it right away
73 const char *getInterfaceNameByIndex(DWORD index);
75 /* Fills index with the index of name, if found. Returns
76 * ERROR_INVALID_PARAMETER if name or index is NULL, ERROR_INVALID_DATA if name
77 * is not found, and NO_ERROR on success.
79 DWORD getInterfaceIndexByName(const char *name, PDWORD index);
81 /* This bunch returns IP addresses, and INADDR_ANY or INADDR_NONE if not found,
82 * appropriately depending on the f/n.
84 DWORD getInterfaceIPAddrByName(const char *name);
85 DWORD getInterfaceIPAddrByIndex(DWORD index);
86 DWORD getInterfaceMaskByName(const char *name);
87 DWORD getInterfaceMaskByIndex(DWORD index);
88 DWORD getInterfaceBCastAddrByName(const char *name);
89 DWORD getInterfaceBCastAddrByIndex(DWORD index);
91 /* Gets a few physical charactersistics of a device: MAC addr len, MAC addr,
92 * and type as one of the MIB_IF_TYPEs.
93 * len's in-out: on in, needs to say how many bytes are available in addr,
94 * which to be safe should be MAX_INTERFACE_PHYSADDR. On out, it's how many
95 * bytes were set, or how many were required if addr isn't big enough.
96 * Returns ERROR_INVALID_PARAMETER if name, len, addr, or type is NULL.
97 * Returns ERROR_INVALID_DATA if name/index isn't valid.
98 * Returns ERROR_INSUFFICIENT_BUFFER if addr isn't large enough for the
99 * physical address; *len will contain the required size.
100 * May return other errors, e.g. ERROR_OUTOFMEMORY or ERROR_NO_MORE_FILES,
101 * if internal errors occur.
102 * Returns NO_ERROR on success.
104 DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
106 DWORD getInterfacePhysicalByIndex(DWORD index, PDWORD len, PBYTE addr,
109 /* Get the operational status as a (MIB_)IF_OPER_STATUS type.
111 DWORD getInterfaceStatusByName(const char *name, PDWORD status);
112 DWORD getInterfaceStatusByIndex(DWORD index, PDWORD status);
114 DWORD getInterfaceMtuByName(const char *name, PDWORD mtu);
115 DWORD getInterfaceMtuByIndex(DWORD index, PDWORD mtu);
117 /* Fills in the MIB_IFROW by name/index. Doesn't fill in interface statistics,
118 * see ipstats.h for that.
119 * Returns ERROR_INVALID_PARAMETER if name or entry is NULL, ERROR_INVALID_DATA
120 * if name/index isn't valid, and NO_ERROR otherwise.
122 DWORD getInterfaceEntryByName(const char *name, PMIB_IFROW entry);
123 DWORD getInterfaceEntryByIndex(DWORD index, PMIB_IFROW entry);
125 /* Converts the network-order bytes in addr to a printable string. Returns
128 char *toIPAddressString(unsigned int addr, char string[16]);
130 #endif /* ndef WINE_IFENUM_H_ */