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