2 * win_if_list - Display network interfaces with description (for Windows)
3 * Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
14 * This small tool is for the Windows build to provide an easy way of fetching
15 * a list of available network interfaces.
20 #ifdef CONFIG_USE_NDISUIO
23 #else /* CONFIG_USE_NDISUIO */
26 #endif /* CONFIG_USE_NDISUIO */
28 #ifdef CONFIG_USE_NDISUIO
31 #define FSCTL_NDISUIO_BASE FILE_DEVICE_NETWORK
33 #define _NDISUIO_CTL_CODE(_Function, _Method, _Access) \
34 CTL_CODE(FSCTL_NDISUIO_BASE, _Function, _Method, _Access)
36 #define IOCTL_NDISUIO_QUERY_BINDING \
37 _NDISUIO_CTL_CODE(0x203, METHOD_BUFFERED, \
38 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
40 #define IOCTL_NDISUIO_BIND_WAIT \
41 _NDISUIO_CTL_CODE(0x204, METHOD_BUFFERED, \
42 FILE_READ_ACCESS | FILE_WRITE_ACCESS)
44 typedef struct _NDISUIO_QUERY_BINDING
47 ULONG DeviceNameOffset
;
48 ULONG DeviceNameLength
;
49 ULONG DeviceDescrOffset
;
50 ULONG DeviceDescrLength
;
51 } NDISUIO_QUERY_BINDING
, *PNDISUIO_QUERY_BINDING
;
54 static HANDLE
ndisuio_open(void)
59 h
= CreateFile(TEXT("\\\\.\\\\Ndisuio"),
60 GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
61 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
,
62 INVALID_HANDLE_VALUE
);
63 if (h
== INVALID_HANDLE_VALUE
)
67 if (!DeviceIoControl(h
, IOCTL_NDISUIO_BIND_WAIT
, NULL
, 0, NULL
, 0,
69 printf("IOCTL_NDISUIO_BIND_WAIT failed: %d",
70 (int) GetLastError());
72 return INVALID_HANDLE_VALUE
;
74 #endif /* _WIN32_WCE */
80 static void ndisuio_query_bindings(HANDLE ndisuio
)
82 NDISUIO_QUERY_BINDING
*b
;
83 size_t blen
= sizeof(*b
) + 1024;
86 char name
[256], desc
[256];
97 if (!DeviceIoControl(ndisuio
, IOCTL_NDISUIO_QUERY_BINDING
,
98 b
, sizeof(NDISUIO_QUERY_BINDING
), b
,
99 (DWORD
) blen
, &written
, NULL
)) {
100 error
= (int) GetLastError();
101 if (error
== ERROR_NO_MORE_ITEMS
)
103 printf("IOCTL_NDISUIO_QUERY_BINDING failed: %d",
108 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceNameOffset
);
109 len
= b
->DeviceNameLength
;
110 if (len
>= sizeof(name
))
111 len
= sizeof(name
) - 1;
112 for (j
= 0; j
< len
; j
++)
113 name
[j
] = (char) pos
[j
];
116 pos
= (WCHAR
*) ((char *) b
+ b
->DeviceDescrOffset
);
117 len
= b
->DeviceDescrLength
;
118 if (len
>= sizeof(desc
))
119 len
= sizeof(desc
) - 1;
120 for (j
= 0; j
< len
; j
++)
121 desc
[j
] = (char) pos
[j
];
124 printf("ifname: %s\ndescription: %s\n\n", name
, desc
);
131 static void ndisuio_enum_bindings(void)
133 HANDLE ndisuio
= ndisuio_open();
134 if (ndisuio
== INVALID_HANDLE_VALUE
)
137 ndisuio_query_bindings(ndisuio
);
138 CloseHandle(ndisuio
);
141 #else /* CONFIG_USE_NDISUIO */
143 static void show_dev(pcap_if_t
*dev
)
145 printf("ifname: %s\ndescription: %s\n\n",
146 dev
->name
, dev
->description
);
150 static void pcap_enum_devs(void)
152 pcap_if_t
*devs
, *dev
;
153 char err
[PCAP_ERRBUF_SIZE
+ 1];
155 if (pcap_findalldevs(&devs
, err
) < 0) {
156 fprintf(stderr
, "Error - pcap_findalldevs: %s\n", err
);
160 for (dev
= devs
; dev
; dev
= dev
->next
) {
164 pcap_freealldevs(devs
);
167 #endif /* CONFIG_USE_NDISUIO */
170 int main(int argc
, char *argv
[])
172 #ifdef CONFIG_USE_NDISUIO
173 ndisuio_enum_bindings();
174 #else /* CONFIG_USE_NDISUIO */
176 #endif /* CONFIG_USE_NDISUIO */