~ubuntu-branches/ubuntu/saucy/bochs/saucy-proposed

« back to all changes in this revision

Viewing changes to misc/niclist.c

  • Committer: Bazaar Package Importer
  • Author(s): David Futcher
  • Date: 2009-04-30 07:46:11 UTC
  • mfrom: (1.1.11 upstream) (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090430074611-6dih80a5mk2uvxhk
Tags: 2.3.7+20090416-1ubuntu1
* Merge from debian unstable (LP: #370427), remaining changes:
  - debian/patches/12_no-ssp.patch: Build bios with -fno-stack-protector
  - Add Replaces/Conflicts for bochsbios-qemu (<< 2.3.6-2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
//
3
3
// misc/niclist.c
4
4
// by Don Becker <x-odus@iname.com>
5
 
// $Id: niclist.c,v 1.14 2007/10/31 13:10:04 sshwarts Exp $
 
5
// $Id: niclist.c,v 1.15 2009/04/14 09:45:22 sshwarts Exp $
6
6
//
7
7
// This program is for win32 only.  It lists the network interface cards
8
8
// that you can use in the "ethdev" field of the ne2k line in your bochsrc.
22
22
#include <stdlib.h>
23
23
 
24
24
#define MAX_ADAPTERS 10
25
 
#define NIC_BUFFER_SIZE 2048
26
 
 
 
25
#define NIC_BUFFER_SIZE 2048
27
26
 
28
27
// declare our NT/9X structures to hold the adapter name and descriptions
29
28
typedef struct {
30
 
        LPWSTR  wstrName;
31
 
        LPSTR   strDesc;
 
29
    LPWSTR   wstrName;
 
30
    LPSTR    strDesc;
32
31
} NIC_INFO_NT;
33
32
 
34
33
typedef struct {
35
 
        LPSTR   strName;
36
 
        LPSTR   strDesc;
 
34
    LPSTR    strName;
 
35
    LPSTR    strDesc;
37
36
} NIC_INFO_9X;
38
37
 
39
38
// declare an array of structures to hold our adapter information
40
39
NIC_INFO_NT niNT[MAX_ADAPTERS];
41
40
NIC_INFO_9X ni9X[MAX_ADAPTERS];
42
41
 
43
 
BOOLEAN   (*PacketGetAdapterNames)(PTSTR, PULONG) = NULL;
 
42
BOOLEAN (*PacketGetAdapterNames)(PTSTR, PULONG) = NULL;
44
43
PCHAR   (*PacketGetVersion)() = NULL;
45
44
 
46
45
void myexit (int code)
50
49
  exit(code);
51
50
}
52
51
 
53
 
int main(int argc, char **argv)
 
52
int CDECL main(int argc, char **argv)
54
53
{
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;
66
 
 
67
 
 
68
 
        // Attemp to load the WinpCap packet library
69
 
        hPacket = LoadLibrary("PACKET.DLL");
70
 
        if(hPacket)
71
 
        {
72
 
                // Now look up the address
73
 
                PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames");
74
 
                PacketGetVersion = (PCHAR (*)())GetProcAddress(hPacket, "PacketGetVersion");
75
 
        }
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);
81
 
        }
82
 
 
83
 
        dwVersion      = GetVersion();
84
 
        dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
85
 
 
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, ",. ") )
93
 
        {
94
 
                // If Single Character, Convert
95
 
                if ( strlen( testString ) == 1 )
96
 
                {
97
 
                        // Check Major First
98
 
                        if ( nDLLMajorVersion == -1 )
99
 
                        {
100
 
                                nDLLMajorVersion = atoi(testString);
101
 
                        }
102
 
                        else if ( nDLLMinorVersion == -1 )
103
 
                        {
104
 
                                nDLLMinorVersion = atoi(testString);
105
 
                        }
106
 
                }
107
 
        }
108
 
 
109
 
        // Get out blob of adapter info
110
 
        PacketGetAdapterNames(AdapterInfo,&AdapterLength);
111
 
 
112
 
        // If this is Windows NT ... And DLL Returns UNICODE
113
 
        if(!(dwVersion >= 0x80000000 && dwMajorVersion >= 4) &&
114
 
           (nDLLMajorVersion < 3 || (nDLLMajorVersion == 3 && nDLLMinorVersion < 1)))
115
 
        {
116
 
                wstrName=(LPWSTR)AdapterInfo;
117
 
 
118
 
                // Obtain Names
119
 
                nAdapterCount = 0;
120
 
                while ((*wstrName))
121
 
                {
122
 
                        // store pointer to name
123
 
                        niNT[nAdapterCount].wstrName=wstrName;
124
 
                        wstrName += lstrlenW(wstrName) +1;
125
 
                        nAdapterCount++;
126
 
                }
127
 
 
128
 
                strDesc = (LPSTR)++wstrName;
129
 
 
130
 
                // Obtain descriptions ....
131
 
                for(i=0;i<nAdapterCount;i++)
132
 
                {
133
 
                        // store pointer to description
134
 
                        niNT[i].strDesc=strDesc;
135
 
                        strDesc += lstrlen(strDesc) +1;
136
 
 
137
 
                        // ... and display adapter info
138
 
                        printf("\n%d: %s\n",i+1,niNT[i].strDesc);
139
 
                        wprintf(L"     Device: %s",niNT[i].wstrName);
140
 
                }
141
 
 
142
 
                if(i)
143
 
                {
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");
147
 
                }
148
 
 
149
 
        }
150
 
        else
151
 
        {
152
 
                // Windows 9x
153
 
                strName=(LPSTR)AdapterInfo;
154
 
 
155
 
                // Obtain Names
156
 
                nAdapterCount = 0;
157
 
                while ((*strName))
158
 
                {
159
 
                        // store pointer to name
160
 
                        ni9X[nAdapterCount].strName=strName;
161
 
                        strName += lstrlen(strName) +1;
162
 
                        nAdapterCount++;
163
 
                }
164
 
 
165
 
                strDesc = (LPSTR)++strName;
166
 
 
167
 
                // Obtain descriptions ....
168
 
                for(i=0;i<nAdapterCount;i++)
169
 
                {
170
 
                        // store pointer to description
171
 
                        ni9X[i].strDesc=strDesc;
172
 
                        strDesc += lstrlen(strDesc) +1;
173
 
 
174
 
                        // ... and display adapter info
175
 
                        printf("\n%d: %s\n",i+1,ni9X[i].strDesc);
176
 
                        printf("     Device: %s",ni9X[i].strName);
177
 
                }
178
 
 
179
 
                if(i)
180
 
                {
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");
184
 
                }
185
 
 
186
 
                printf("\n");
187
 
        }
188
 
 
189
 
        myexit (0);
190
 
        return 0; /* shut up stupid compilers */
 
54
    int i;
 
55
    HINSTANCE     hPacket;
 
56
    DWORD         dwVersion, dwMajorVersion;
 
57
    char          AdapterInfo[NIC_BUFFER_SIZE] = { '\0','\0' };
 
58
    unsigned long AdapterLength = NIC_BUFFER_SIZE;
 
59
    LPWSTR        wstrName;
 
60
    LPSTR         strName, strDesc;
 
61
    int           nAdapterCount;
 
62
    PCHAR         dllVersion;
 
63
    PCHAR         testString;
 
64
    int           nDLLMajorVersion, nDLLMinorVersion;
 
65
 
 
66
    // Attemp to load the WinpCap packet library
 
67
    hPacket = LoadLibrary("PACKET.DLL");
 
68
    if(hPacket)
 
69
    {
 
70
        // Now look up the address
 
71
        PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG))GetProcAddress(hPacket, "PacketGetAdapterNames");
 
72
        PacketGetVersion = (PCHAR (*)())GetProcAddress(hPacket, "PacketGetVersion");
 
73
    }
 
74
    else {
 
75
        printf("Could not load WinPCap driver!\n");
 
76
        printf ("You can download them for free from\n");
 
77
        printf ("http://www.winpcap.org/\n");
 
78
        myexit(1);
 
79
    }
 
80
 
 
81
    dwVersion      = GetVersion();
 
82
    dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
 
83
 
 
84
    // Get DLL Version and Tokenize
 
85
    dllVersion = PacketGetVersion();
 
86
    nDLLMajorVersion = -1;
 
87
    nDLLMinorVersion = -1;
 
88
    for (testString = strtok(dllVersion, ",. ");
 
89
              testString != NULL; testString = strtok(NULL, ",. "))
 
90
    {
 
91
        // If Single Character, Convert
 
92
        if (strlen( testString ) == 1)
 
93
        {
 
94
            // Check Major First
 
95
            if (nDLLMajorVersion == -1)
 
96
            {
 
97
                nDLLMajorVersion = atoi(testString);
 
98
            }
 
99
            else if ( nDLLMinorVersion == -1 )
 
100
            {
 
101
                nDLLMinorVersion = atoi(testString);
 
102
            }
 
103
        }
 
104
    }
 
105
 
 
106
    // Get out blob of adapter info
 
107
    PacketGetAdapterNames(AdapterInfo,&AdapterLength);
 
108
 
 
109
    // If this is Windows NT ... And DLL Returns UNICODE
 
110
    if(!(dwVersion >= 0x80000000 && dwMajorVersion >= 4) &&
 
111
       (nDLLMajorVersion < 3 || (nDLLMajorVersion == 3 && nDLLMinorVersion < 1)))
 
112
    {
 
113
        wstrName=(LPWSTR)AdapterInfo;
 
114
 
 
115
        // Obtain Names
 
116
        nAdapterCount = 0;
 
117
        while ((*wstrName))
 
118
        {
 
119
            // store pointer to name
 
120
            niNT[nAdapterCount].wstrName=wstrName;
 
121
            wstrName += lstrlenW(wstrName) +1;
 
122
            nAdapterCount++;
 
123
        }
 
124
 
 
125
        strDesc = (LPSTR)++wstrName;
 
126
 
 
127
        // Obtain descriptions ....
 
128
        for(i=0;i<nAdapterCount;i++)
 
129
        {
 
130
            // store pointer to description
 
131
            niNT[i].strDesc=strDesc;
 
132
            strDesc += lstrlen(strDesc) +1;
 
133
 
 
134
            // ... and display adapter info
 
135
            printf("\n%d: %s\n",i+1,niNT[i].strDesc);
 
136
            wprintf(L"     Device: %s",niNT[i].wstrName);
 
137
        }
 
138
 
 
139
        if(i) {
 
140
            printf("\n\nExample config for bochsrc:\n");
 
141
            wprintf(L"ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",niNT[0].wstrName);
 
142
            printf("\n");
 
143
        }
 
144
 
 
145
    }
 
146
    else
 
147
    {
 
148
        // Windows 9x
 
149
        strName=(LPSTR)AdapterInfo;
 
150
 
 
151
        // Obtain Names
 
152
        nAdapterCount = 0;
 
153
        while ((*strName))
 
154
        {
 
155
            // store pointer to name
 
156
            ni9X[nAdapterCount].strName=strName;
 
157
            strName += lstrlen(strName) +1;
 
158
            nAdapterCount++;
 
159
        }
 
160
 
 
161
        strDesc = (LPSTR)++strName;
 
162
 
 
163
        // Obtain descriptions ....
 
164
        for(i=0;i<nAdapterCount;i++)
 
165
        {
 
166
            // store pointer to description
 
167
            ni9X[i].strDesc=strDesc;
 
168
            strDesc += lstrlen(strDesc) +1;
 
169
 
 
170
            // ... and display adapter info
 
171
            printf("\n%d: %s\n",i+1,ni9X[i].strDesc);
 
172
            printf("     Device: %s",ni9X[i].strName);
 
173
        }
 
174
 
 
175
        if(i)
 
176
        {
 
177
            printf("\n\nExample config for bochsrc:\n");
 
178
            printf("ne2k: ioaddr=0x300, irq=3, mac=b0:c4:20:00:00:00, ethmod=win32, ethdev=%s",ni9X[0].strName);
 
179
            printf("\n");
 
180
        }
 
181
 
 
182
        printf("\n");
 
183
    }
 
184
 
 
185
    myexit (0);
 
186
    return 0; /* shut up stupid compilers */
191
187
}