Fixed compilation error
[bochs-mirror.git] / misc / niclist.c
blobef7a5a74a86f3b3581650c4128c5ed00690728d2
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // misc/niclist.c
4 // by Don Becker <x-odus@iname.com>
5 // $Id: niclist.c,v 1.14 2007/10/31 13:10:04 sshwarts Exp $
6 //
7 // This program is for win32 only. It lists the network interface cards
8 // that you can use in the "ethdev" field of the ne2k line in your bochsrc.
9 //
10 // For this program and for win32 ethernet, the winpcap library is required.
11 // Download it from http://www.winpcap.org/
13 /////////////////////////////////////////////////////////////////////////
15 #ifndef WIN32
16 #error Niclist will only work on WIN32 platforms.
17 #endif
19 #include <windows.h>
20 #include <stdio.h>
21 #include <conio.h>
22 #include <stdlib.h>
24 #define MAX_ADAPTERS 10
25 #define NIC_BUFFER_SIZE 2048
28 // declare our NT/9X structures to hold the adapter name and descriptions
29 typedef struct {
30 LPWSTR wstrName;
31 LPSTR strDesc;
32 } NIC_INFO_NT;
34 typedef struct {
35 LPSTR strName;
36 LPSTR strDesc;
37 } NIC_INFO_9X;
39 // declare an array of structures to hold our adapter information
40 NIC_INFO_NT niNT[MAX_ADAPTERS];
41 NIC_INFO_9X ni9X[MAX_ADAPTERS];
43 BOOLEAN (*PacketGetAdapterNames)(PTSTR, PULONG) = NULL;
44 PCHAR (*PacketGetVersion)() = NULL;
46 void myexit (int code)
48 printf ("\nPress any key to continue\n");
49 getch();
50 exit(code);
53 int main(int argc, char **argv)
55 int i;
56 HINSTANCE hPacket;
57 DWORD dwVersion, dwMajorVersion;
58 char AdapterInfo[NIC_BUFFER_SIZE] = { '\0','\0' };
59 unsigned long AdapterLength = NIC_BUFFER_SIZE;
60 LPWSTR wstrName;
61 LPSTR strName, strDesc;
62 int nAdapterCount;
63 PCHAR dllVersion;
64 PCHAR testString;
65 int nDLLMajorVersion, nDLLMinorVersion;
68 // Attemp to load the WinpCap packet library
69 hPacket = LoadLibrary("PACKET.DLL");
70 if(hPacket)
72 // Now look up the address
73 PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames");
74 PacketGetVersion = (PCHAR (*)())GetProcAddress(hPacket, "PacketGetVersion");
76 else {
77 printf("Could not load WinPCap driver!\n");
78 printf ("You can download them for free from\n");
79 printf ("http://www.winpcap.org/\n");
80 myexit(1);
83 dwVersion = GetVersion();
84 dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
86 // Get DLL Version and Tokenize
87 dllVersion = PacketGetVersion();
88 nDLLMajorVersion = -1;
89 nDLLMinorVersion = -1;
90 for ( testString = strtok(dllVersion, ",. ");
91 testString != NULL;
92 testString = strtok(NULL, ",. ") )
94 // If Single Character, Convert
95 if ( strlen( testString ) == 1 )
97 // Check Major First
98 if ( nDLLMajorVersion == -1 )
100 nDLLMajorVersion = atoi(testString);
102 else if ( nDLLMinorVersion == -1 )
104 nDLLMinorVersion = atoi(testString);
109 // Get out blob of adapter info
110 PacketGetAdapterNames(AdapterInfo,&AdapterLength);
112 // If this is Windows NT ... And DLL Returns UNICODE
113 if(!(dwVersion >= 0x80000000 && dwMajorVersion >= 4) &&
114 (nDLLMajorVersion < 3 || (nDLLMajorVersion == 3 && nDLLMinorVersion < 1)))
116 wstrName=(LPWSTR)AdapterInfo;
118 // Obtain Names
119 nAdapterCount = 0;
120 while ((*wstrName))
122 // store pointer to name
123 niNT[nAdapterCount].wstrName=wstrName;
124 wstrName += lstrlenW(wstrName) +1;
125 nAdapterCount++;
128 strDesc = (LPSTR)++wstrName;
130 // Obtain descriptions ....
131 for(i=0;i<nAdapterCount;i++)
133 // store pointer to description
134 niNT[i].strDesc=strDesc;
135 strDesc += lstrlen(strDesc) +1;
137 // ... and display adapter info
138 printf("\n%d: %s\n",i+1,niNT[i].strDesc);
139 wprintf(L" Device: %s",niNT[i].wstrName);
142 if(i)
144 printf("\n\nExample config for bochsrc:\n");
145 wprintf(L"ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",niNT[0].wstrName);
146 printf("\n");
150 else
152 // Windows 9x
153 strName=(LPSTR)AdapterInfo;
155 // Obtain Names
156 nAdapterCount = 0;
157 while ((*strName))
159 // store pointer to name
160 ni9X[nAdapterCount].strName=strName;
161 strName += lstrlen(strName) +1;
162 nAdapterCount++;
165 strDesc = (LPSTR)++strName;
167 // Obtain descriptions ....
168 for(i=0;i<nAdapterCount;i++)
170 // store pointer to description
171 ni9X[i].strDesc=strDesc;
172 strDesc += lstrlen(strDesc) +1;
174 // ... and display adapter info
175 printf("\n%d: %s\n",i+1,ni9X[i].strDesc);
176 printf(" Device: %s",ni9X[i].strName);
179 if(i)
181 printf("\n\nExample config for bochsrc:\n");
182 printf("ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",ni9X[0].strName);
183 printf("\n");
186 printf("\n");
189 myexit (0);
190 return 0; /* shut up stupid compilers */