1 /////////////////////////////////////////////////////////////////////////
4 // by Don Becker <x-odus@iname.com>
5 // $Id: niclist.c,v 1.14 2007/10/31 13:10:04 sshwarts Exp $
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.
10 // For this program and for win32 ethernet, the winpcap library is required.
11 // Download it from http://www.winpcap.org/
13 /////////////////////////////////////////////////////////////////////////
16 #error Niclist will only work on WIN32 platforms.
24 #define MAX_ADAPTERS 10
25 #define NIC_BUFFER_SIZE 2048
28 // declare our NT/9X structures to hold the adapter name and descriptions
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");
53 int main(int argc
, char **argv
)
57 DWORD dwVersion
, dwMajorVersion
;
58 char AdapterInfo
[NIC_BUFFER_SIZE
] = { '\0','\0' };
59 unsigned long AdapterLength
= NIC_BUFFER_SIZE
;
61 LPSTR strName
, strDesc
;
65 int nDLLMajorVersion
, nDLLMinorVersion
;
68 // Attemp to load the WinpCap packet library
69 hPacket
= LoadLibrary("PACKET.DLL");
72 // Now look up the address
73 PacketGetAdapterNames
= (BOOLEAN (*)(PTSTR
, PULONG
))GetProcAddress(hPacket
, "PacketGetAdapterNames");
74 PacketGetVersion
= (PCHAR (*)())GetProcAddress(hPacket
, "PacketGetVersion");
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");
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
, ",. ");
92 testString
= strtok(NULL
, ",. ") )
94 // If Single Character, Convert
95 if ( strlen( testString
) == 1 )
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
;
122 // store pointer to name
123 niNT
[nAdapterCount
].wstrName
=wstrName
;
124 wstrName
+= lstrlenW(wstrName
) +1;
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
);
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
);
153 strName
=(LPSTR
)AdapterInfo
;
159 // store pointer to name
160 ni9X
[nAdapterCount
].strName
=strName
;
161 strName
+= lstrlen(strName
) +1;
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
);
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
);
190 return 0; /* shut up stupid compilers */