Copy msimg32
[reactos.git] / rosapps / net / niclist / niclist.c
1 /* $Id: niclist.c,v 1.3 2004/01/12 22:45:53 sedwards Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS packet driver interface list utility
5 * FILE: apps/net/niclist/niclist.c
6 * PURPOSE: Network information utility
7 * PROGRAMMERS: Robert Dickenson (robert_dickenson@users.sourceforge.net)
8 * REVISIONS:
9 * RDD 10/07/2002 Created from bochs sources
10 */
11 /*
12 For this program and for win32 ethernet, the winpcap library is required.
13 Download it from http://netgroup-serv.polito.it/winpcap.
14 */
15 #ifdef MSC_VER
16 #define WIN32_LEAN_AND_MEAN
17 #endif
18 #include <windows.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #define MAX_ADAPTERS 10
23 #define NIC_BUFFER_SIZE 2048
24
25
26 // structure to hold the adapter name and description
27 typedef struct {
28 LPWSTR wstrName;
29 LPSTR strDesc;
30 } NIC_INFO_NT;
31
32 // array of structures to hold information for our adapters
33 NIC_INFO_NT nic_info[MAX_ADAPTERS];
34
35 // pointer to exported function in winpcap library
36 BOOLEAN (*PacketGetAdapterNames)(PTSTR, PULONG) = NULL;
37 PCHAR (*PacketGetVersion)(VOID) = NULL;
38
39
40 int main(int argc, char **argv)
41 {
42 char AdapterInfo[NIC_BUFFER_SIZE] = { '\0','\0' };
43 unsigned long AdapterLength = NIC_BUFFER_SIZE;
44 LPWSTR wstrName;
45 LPSTR strDesc;
46 int nAdapterCount;
47 int i;
48
49 char* PacketLibraryVersion;
50
51
52 // Attemp to load the WinPCap dynamic link library
53 HINSTANCE hPacket = LoadLibrary("PACKET.DLL");
54 if (hPacket) {
55 PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames");
56 PacketGetVersion = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetVersion");
57 } else {
58 printf("Could not load WinPCap driver! for more information goto:\n");
59 printf ("http://netgroup-serv.polito.it/winpcap\n");
60 return 1;
61 }
62 if (!(PacketLibraryVersion = PacketGetVersion())) {
63 printf("ERROR: Could not get Packet DLL Version string.\n");
64 return 2;
65 }
66 printf("Packet Library Version: %s\n", PacketLibraryVersion);
67
68 if (!PacketGetAdapterNames(AdapterInfo, &AdapterLength)) {
69 printf("ERROR: Could not get Packet Adaptor Names.\n");
70 return 2;
71 }
72 wstrName = (LPWSTR)AdapterInfo;
73
74 // Enumerate all the adapters names found...
75 nAdapterCount = 0;
76 while ((*wstrName)) {
77 nic_info[nAdapterCount].wstrName = wstrName;
78 wstrName += lstrlenW(wstrName) + 1;
79 nAdapterCount++;
80 if (nAdapterCount > 9) break;
81 }
82 strDesc = (LPSTR)++wstrName;
83
84 if (!nAdapterCount) {
85 printf("No Packet Adaptors found (%d)\n", AdapterLength);
86 } else {
87 printf("Adaptor count: %d\n", nAdapterCount);
88 }
89
90 // And obtain the adapter description strings....
91 for (i = 0; i < nAdapterCount; i++) {
92 nic_info[i].strDesc = strDesc;
93 strDesc += lstrlen(strDesc) + 1;
94
95 // display adapter info
96 printf("%d: %s\n", i + 1, nic_info[i].strDesc);
97 wprintf(L" Device: %s\n", nic_info[i].wstrName);
98 }
99 return 0;
100 }