forked from Kron4ek/Wine-Builds
-
Notifications
You must be signed in to change notification settings - Fork 16
/
ndis.patch
529 lines (508 loc) · 20.6 KB
/
ndis.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
From 3e4aa0231f6279ba699c4a4097e3bb087de90f41 Mon Sep 17 00:00:00 2001
From: brunodev85 <root@DESKTOP-J1LK36I>
Date: Tue, 18 Jun 2024 13:51:04 -0300
Subject: [PATCH] iphlpapi: Add option to read adapters info from file
---
dlls/iphlpapi/iphlpapi_main.c | 459 ++++++++++++++++++++++++----------
1 file changed, 330 insertions(+), 129 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 9c7582b7..aaeb34d3 100755
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -44,9 +44,18 @@
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
#define CHARS_IN_GUID 39
+#define ADAPTER_INFO_PATH "/data/data/com.termux/files/usr/tmp/adapterinfo"
static const WCHAR *device_tcpip = L"\\DEVICE\\TCPIP_";
+struct adapter_info
+{
+ char name[32];
+ char ip_address[16];
+ char netmask[16];
+ char gateway[16];
+};
+
DWORD WINAPI AllocateAndGetIpAddrTableFromStack( MIB_IPADDRTABLE **table, BOOL sort, HANDLE heap, DWORD flags );
static const NPI_MODULEID *ip_module_id( USHORT family )
@@ -220,6 +229,61 @@ DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex)
return ERROR_NOT_SUPPORTED;
}
+static struct adapter_info* read_adapters_info_from_file( int *adapter_info_size )
+{
+ FILE *file;
+ struct adapter_info* adapters_info = NULL;
+ *adapter_info_size = 0;
+
+ file = fopen( ADAPTER_INFO_PATH, "r" );
+ if (file != NULL)
+ {
+ int col, index, list_size = 0;
+ char* value;
+ const size_t line_size = 128;
+ char *line = malloc( line_size );
+ struct adapter_info *adapter_info;
+
+ while (fgets( line, line_size, file ) != NULL)
+ {
+ index = list_size++;
+ adapters_info = realloc( adapters_info, list_size * sizeof(struct adapter_info) );
+ adapter_info = &adapters_info[index];
+
+ col = 0;
+ value = strtok( line, "," );
+ while (value)
+ {
+ switch (col)
+ {
+ case 0:
+ strcpy( adapter_info->name, value );
+ break;
+ case 1:
+ strcpy( adapter_info->ip_address, value );
+ break;
+ case 2:
+ strcpy( adapter_info->netmask, value );
+ break;
+ case 3:
+ strcpy( adapter_info->gateway, value );
+ break;
+ }
+
+ value = strtok( NULL, "," );
+ col++;
+ }
+ }
+
+ free( line );
+ fclose( file );
+
+ *adapter_info_size = list_size;
+ }
+
+ return adapters_info;
+}
+
static char *debugstr_ipv6(const struct sockaddr_in6 *sin, char *buf)
{
const IN6_ADDR *addr = &sin->sin6_addr;
@@ -595,140 +659,195 @@ static void ip_addr_string_init( IP_ADDR_STRING *s, const IN_ADDR *addr, const I
*/
DWORD WINAPI GetAdaptersInfo( IP_ADAPTER_INFO *info, ULONG *size )
{
- DWORD err, if_count, if_num = 0, uni_count, fwd_count, needed, wins_server_count;
- DWORD len, i, uni, fwd;
- NET_LUID *if_keys = NULL;
- struct nsi_ndis_ifinfo_rw *if_rw = NULL;
- struct nsi_ndis_ifinfo_static *if_stat = NULL;
- struct nsi_ipv4_unicast_key *uni_keys = NULL;
- struct nsi_ip_unicast_rw *uni_rw = NULL;
- struct nsi_ipv4_forward_key *fwd_keys = NULL;
- SOCKADDR_INET *wins_servers = NULL;
- IP_ADDR_STRING *extra_ip_addrs, *cursor;
- IN_ADDR gw, mask;
-
+ int adapter_info_size;
+ struct adapter_info *adapters_info;
+
TRACE( "info %p, size %p\n", info, size );
- if (!size) return ERROR_INVALID_PARAMETER;
-
- err = NsiAllocateAndGetTable( 1, &NPI_MS_NDIS_MODULEID, NSI_NDIS_IFINFO_TABLE,
- (void **)&if_keys, sizeof(*if_keys), (void **)&if_rw, sizeof(*if_rw),
- NULL, 0, (void **)&if_stat, sizeof(*if_stat), &if_count, 0 );
-
- if (err) return err;
- for (i = 0; i < if_count; i++)
+ if (!size) return ERROR_INVALID_PARAMETER;
+
+ adapters_info = read_adapters_info_from_file( &adapter_info_size );
+ if (adapters_info != NULL && adapter_info_size > 0)
{
- if (if_stat[i].type == IF_TYPE_SOFTWARE_LOOPBACK) continue;
- if_num++;
+ DWORD i, needed;
+ IN_ADDR addr, mask;
+
+ needed = adapter_info_size * sizeof(*info);
+ if (!info || *size < needed)
+ {
+ *size = needed;
+ return ERROR_BUFFER_OVERFLOW;
+ }
+
+ for (i = 0; i < adapter_info_size; i++)
+ {
+ TRACE( "file adapter %s %s %s %s\n", adapters_info[i].name, adapters_info[i].ip_address, adapters_info[i].netmask, adapters_info[i].gateway );
+
+ info->Next = info + 1;
+ info->ComboIndex = 0;
+ strcpy( info->AdapterName, "{00000000-0000-0000-0000-000000000000}" );
+ strcpy( info->Description, adapters_info[i].name );
+ info->AddressLength = 6;
+ memset(&info->Address, 0, 6);
+ info->Index = i;
+ info->Type = IF_TYPE_IEEE80211;
+ info->DhcpEnabled = FALSE; /* FIXME */
+ info->CurrentIpAddress = NULL;
+
+ addr.s_addr = inet_addr(adapters_info[i].ip_address);
+ mask.s_addr = inet_addr(adapters_info[i].netmask);
+ ip_addr_string_init( &info->IpAddressList, &addr, &mask, 0 );
+
+ addr.s_addr = inet_addr(adapters_info[i].gateway);
+ ip_addr_string_init( &info->GatewayList, &addr, &mask, 0 );
+ ip_addr_string_init( &info->DhcpServer, NULL, NULL, 0 );
+
+ info->HaveWins = FALSE;
+ ip_addr_string_init( &info->PrimaryWinsServer, NULL, NULL, 0 );
+ ip_addr_string_init( &info->SecondaryWinsServer, NULL, NULL, 0 );
+ info->LeaseObtained = 0;
+ info->LeaseExpires = 0;
+
+ info++;
+ }
+
+ free( adapters_info );
+ info[-1].Next = NULL;
+ return 0;
}
-
- if (!if_num)
+ else
{
- err = ERROR_NO_DATA;
- goto err;
- }
+ DWORD err, if_count, if_num = 0, uni_count, fwd_count, needed, wins_server_count;
+ DWORD len, i, uni, fwd;
+ NET_LUID *if_keys = NULL;
+ struct nsi_ndis_ifinfo_rw *if_rw = NULL;
+ struct nsi_ndis_ifinfo_static *if_stat = NULL;
+ struct nsi_ipv4_unicast_key *uni_keys = NULL;
+ struct nsi_ip_unicast_rw *uni_rw = NULL;
+ struct nsi_ipv4_forward_key *fwd_keys = NULL;
+ SOCKADDR_INET *wins_servers = NULL;
+ IP_ADDR_STRING *extra_ip_addrs, *cursor;
+ IN_ADDR gw, mask;
+
+ err = NsiAllocateAndGetTable( 1, &NPI_MS_NDIS_MODULEID, NSI_NDIS_IFINFO_TABLE,
+ (void **)&if_keys, sizeof(*if_keys), (void **)&if_rw, sizeof(*if_rw),
+ NULL, 0, (void **)&if_stat, sizeof(*if_stat), &if_count, 0 );
- err = NsiAllocateAndGetTable( 1, &NPI_MS_IPV4_MODULEID, NSI_IP_UNICAST_TABLE,
- (void **)&uni_keys, sizeof(*uni_keys), (void **)&uni_rw, sizeof(*uni_rw),
- NULL, 0, NULL, 0, &uni_count, 0 );
- if (err) goto err;
+ if (err) return err;
+ for (i = 0; i < if_count; i++)
+ {
+ if (if_stat[i].type == IF_TYPE_SOFTWARE_LOOPBACK) continue;
+ if_num++;
+ }
- /* Slightly overestimate the needed size by assuming that all
- unicast addresses require a separate IP_ADDR_STRING. */
+ if (!if_num)
+ {
+ err = ERROR_NO_DATA;
+ goto err;
+ }
- needed = if_num * sizeof(*info) + uni_count * sizeof(IP_ADDR_STRING);
- if (!info || *size < needed)
- {
- *size = needed;
- err = ERROR_BUFFER_OVERFLOW;
- goto err;
- }
+ err = NsiAllocateAndGetTable( 1, &NPI_MS_IPV4_MODULEID, NSI_IP_UNICAST_TABLE,
+ (void **)&uni_keys, sizeof(*uni_keys), (void **)&uni_rw, sizeof(*uni_rw),
+ NULL, 0, NULL, 0, &uni_count, 0 );
+ if (err) goto err;
- err = NsiAllocateAndGetTable( 1, &NPI_MS_IPV4_MODULEID, NSI_IP_FORWARD_TABLE,
- (void **)&fwd_keys, sizeof(*fwd_keys), NULL, 0,
- NULL, 0, NULL, 0, &fwd_count, 0 );
- if (err) goto err;
+ /* Slightly overestimate the needed size by assuming that all
+ unicast addresses require a separate IP_ADDR_STRING. */
- wins_server_count = get_wins_servers( &wins_servers );
+ needed = if_num * sizeof(*info) + uni_count * sizeof(IP_ADDR_STRING);
+ if (!info || *size < needed)
+ {
+ *size = needed;
+ err = ERROR_BUFFER_OVERFLOW;
+ goto err;
+ }
- extra_ip_addrs = (IP_ADDR_STRING *)(info + if_num);
- for (i = 0; i < if_count; i++)
- {
- if (if_stat[i].type == IF_TYPE_SOFTWARE_LOOPBACK) continue;
-
- info->Next = info + 1;
- info->ComboIndex = 0;
- ConvertGuidToStringA( &if_stat[i].if_guid, info->AdapterName, sizeof(info->AdapterName) );
- len = WideCharToMultiByte( CP_ACP, 0, if_stat[i].descr.String, if_stat[i].descr.Length / sizeof(WCHAR),
- info->Description, sizeof(info->Description) - 1, NULL, NULL );
- info->Description[len] = '\0';
- info->AddressLength = if_rw[i].phys_addr.Length;
- if (info->AddressLength > sizeof(info->Address)) info->AddressLength = 0;
- memcpy( info->Address, if_rw[i].phys_addr.Address, info->AddressLength );
- memset( info->Address + info->AddressLength, 0, sizeof(info->Address) - info->AddressLength );
- info->Index = if_stat[i].if_index;
- info->Type = if_stat[i].type;
- info->DhcpEnabled = TRUE; /* FIXME */
- info->CurrentIpAddress = NULL;
-
- cursor = NULL;
- for (uni = 0; uni < uni_count; uni++)
+ err = NsiAllocateAndGetTable( 1, &NPI_MS_IPV4_MODULEID, NSI_IP_FORWARD_TABLE,
+ (void **)&fwd_keys, sizeof(*fwd_keys), NULL, 0,
+ NULL, 0, NULL, 0, &fwd_count, 0 );
+ if (err) goto err;
+
+ wins_server_count = get_wins_servers( &wins_servers );
+
+ extra_ip_addrs = (IP_ADDR_STRING *)(info + if_num);
+ for (i = 0; i < if_count; i++)
{
- if (uni_keys[uni].luid.Value != if_keys[i].Value) continue;
- if (!cursor) cursor = &info->IpAddressList;
- else
+ if (if_stat[i].type == IF_TYPE_SOFTWARE_LOOPBACK) continue;
+
+ info->Next = info + 1;
+ info->ComboIndex = 0;
+ ConvertGuidToStringA( &if_stat[i].if_guid, info->AdapterName, sizeof(info->AdapterName) );
+ len = WideCharToMultiByte( CP_ACP, 0, if_stat[i].descr.String, if_stat[i].descr.Length / sizeof(WCHAR),
+ info->Description, sizeof(info->Description) - 1, NULL, NULL );
+ info->Description[len] = '\0';
+ info->AddressLength = if_rw[i].phys_addr.Length;
+ if (info->AddressLength > sizeof(info->Address)) info->AddressLength = 0;
+ memcpy( info->Address, if_rw[i].phys_addr.Address, info->AddressLength );
+ memset( info->Address + info->AddressLength, 0, sizeof(info->Address) - info->AddressLength );
+ info->Index = if_stat[i].if_index;
+ info->Type = if_stat[i].type;
+ info->DhcpEnabled = TRUE; /* FIXME */
+ info->CurrentIpAddress = NULL;
+
+ cursor = NULL;
+ for (uni = 0; uni < uni_count; uni++)
{
- cursor->Next = extra_ip_addrs++;
- cursor = cursor->Next;
+ if (uni_keys[uni].luid.Value != if_keys[i].Value) continue;
+ if (!cursor) cursor = &info->IpAddressList;
+ else
+ {
+ cursor->Next = extra_ip_addrs++;
+ cursor = cursor->Next;
+ }
+ ConvertLengthToIpv4Mask( uni_rw[uni].on_link_prefix, &mask.s_addr );
+ ip_addr_string_init( cursor, &uni_keys[uni].addr, &mask, 0 );
}
- ConvertLengthToIpv4Mask( uni_rw[uni].on_link_prefix, &mask.s_addr );
- ip_addr_string_init( cursor, &uni_keys[uni].addr, &mask, 0 );
- }
- if (!cursor)
- {
- mask.s_addr = INADDR_ANY;
- ip_addr_string_init( &info->IpAddressList, &mask, &mask, 0 );
- }
-
- gw.s_addr = INADDR_ANY;
- mask.s_addr = INADDR_NONE;
- for (fwd = 0; fwd < fwd_count; fwd++)
- { /* find the first router on this interface */
- if (fwd_keys[fwd].luid.Value == if_keys[i].Value &&
- fwd_keys[fwd].next_hop.s_addr != INADDR_ANY &&
- !fwd_keys[fwd].prefix_len)
+ if (!cursor)
{
- gw = fwd_keys[fwd].next_hop;
- break;
+ mask.s_addr = INADDR_ANY;
+ ip_addr_string_init( &info->IpAddressList, &mask, &mask, 0 );
}
- }
- ip_addr_string_init( &info->GatewayList, &gw, &mask, 0 );
-
- ip_addr_string_init( &info->DhcpServer, NULL, NULL, 0 );
- info->HaveWins = !!wins_server_count;
- ip_addr_string_init( &info->PrimaryWinsServer, NULL, NULL, 0 );
- ip_addr_string_init( &info->SecondaryWinsServer, NULL, NULL, 0 );
- if (info->HaveWins)
- {
+ gw.s_addr = INADDR_ANY;
mask.s_addr = INADDR_NONE;
- ip_addr_string_init( &info->PrimaryWinsServer, &wins_servers[0].Ipv4.sin_addr, &mask, 0 );
- if (wins_server_count > 1)
- ip_addr_string_init( &info->SecondaryWinsServer, &wins_servers[1].Ipv4.sin_addr, &mask, 0 );
- }
+ for (fwd = 0; fwd < fwd_count; fwd++)
+ { /* find the first router on this interface */
+ if (fwd_keys[fwd].luid.Value == if_keys[i].Value &&
+ fwd_keys[fwd].next_hop.s_addr != INADDR_ANY &&
+ !fwd_keys[fwd].prefix_len)
+ {
+ gw = fwd_keys[fwd].next_hop;
+ break;
+ }
+ }
+ ip_addr_string_init( &info->GatewayList, &gw, &mask, 0 );
- info->LeaseObtained = 0;
- info->LeaseExpires = 0;
+ ip_addr_string_init( &info->DhcpServer, NULL, NULL, 0 );
- info++;
- }
- info[-1].Next = NULL;
+ info->HaveWins = !!wins_server_count;
+ ip_addr_string_init( &info->PrimaryWinsServer, NULL, NULL, 0 );
+ ip_addr_string_init( &info->SecondaryWinsServer, NULL, NULL, 0 );
+ if (info->HaveWins)
+ {
+ mask.s_addr = INADDR_NONE;
+ ip_addr_string_init( &info->PrimaryWinsServer, &wins_servers[0].Ipv4.sin_addr, &mask, 0 );
+ if (wins_server_count > 1)
+ ip_addr_string_init( &info->SecondaryWinsServer, &wins_servers[1].Ipv4.sin_addr, &mask, 0 );
+ }
+
+ info->LeaseObtained = 0;
+ info->LeaseExpires = 0;
+
+ info++;
+ }
+ info[-1].Next = NULL;
err:
- heap_free( wins_servers );
- NsiFreeTable( fwd_keys, NULL, NULL, NULL );
- NsiFreeTable( uni_keys, uni_rw, NULL, NULL );
- NsiFreeTable( if_keys, if_rw, NULL, if_stat );
- return err;
+ heap_free( wins_servers );
+ NsiFreeTable( fwd_keys, NULL, NULL, NULL );
+ NsiFreeTable( uni_keys, uni_rw, NULL, NULL );
+ NsiFreeTable( if_keys, if_rw, NULL, if_stat );
+ return err;
+ }
}
static void address_entry_free( void *ptr, ULONG offset, void *ctxt )
@@ -1288,27 +1407,109 @@ static DWORD adapters_addresses_alloc( ULONG family, ULONG flags, IP_ADAPTER_ADD
ULONG WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses( ULONG family, ULONG flags, void *reserved,
IP_ADAPTER_ADDRESSES *aa, ULONG *size )
{
- IP_ADAPTER_ADDRESSES *info;
- DWORD err, needed;
-
+ int adapter_info_size;
+ struct adapter_info *adapters_info;
+
TRACE( "(%ld, %08lx, %p, %p, %p)\n", family, flags, reserved, aa, size );
- if (!size) return ERROR_INVALID_PARAMETER;
-
- err = adapters_addresses_alloc( family, flags, &info );
- if (err) return err;
-
- needed = adapters_addresses_size( info );
- if (!aa || *size < needed)
+ if (!size) return ERROR_INVALID_PARAMETER;
+
+ adapters_info = read_adapters_info_from_file( &adapter_info_size );
+ if (adapters_info != NULL && adapter_info_size > 0)
{
- *size = needed;
- err = ERROR_BUFFER_OVERFLOW;
+ DWORD i, needed;
+ const int dns_suffix_len = 7;
+ const int adapter_name_len = 39;
+ const int friendly_name_len = 64;
+ const int aa_len = sizeof(*aa) + dns_suffix_len + adapter_name_len + friendly_name_len;
+
+ needed = adapter_info_size * (aa_len + sizeof(IP_ADAPTER_UNICAST_ADDRESS) + sizeof(SOCKADDR_IN) + sizeof(IP_ADAPTER_GATEWAY_ADDRESS) + sizeof(SOCKADDR_IN));
+ if (!aa || *size < needed)
+ {
+ *size = needed;
+ return ERROR_BUFFER_OVERFLOW;
+ }
+
+ for (i = 0; i < adapter_info_size; i++)
+ {
+ WCHAR *friendly_name = heap_alloc_zero( friendly_name_len );
+
+ TRACE( "file adapter %s %s %s %s\n", adapters_info[i].name, adapters_info[i].ip_address, adapters_info[i].netmask, adapters_info[i].gateway );
+
+ MultiByteToWideChar( CP_ACP, 0, adapters_info[i].name, -1, friendly_name, friendly_name_len );
+
+ aa->Next = aa + 1;
+ aa->Length = aa_len;
+ aa->IfIndex = i;
+ aa->DnsSuffix = (WCHAR *)L"box";
+ aa->AdapterName = (CHAR *)"{00000000-0000-0000-0000-000000000000}";
+
+ aa->Description = friendly_name;
+ aa->FriendlyName = friendly_name;
+ aa->PhysicalAddressLength = 6;
+ memset(&aa->PhysicalAddress, 0, 6);
+ aa->Mtu = 1;
+ aa->IfType = IF_TYPE_IEEE80211;
+ aa->OperStatus = 1;
+ aa->TransmitLinkSpeed = 144400000;
+ aa->ReceiveLinkSpeed = 144400000;
+ aa->ConnectionType = NET_IF_CONNECTION_DEDICATED;
+
+ if (!(flags & GAA_FLAG_SKIP_UNICAST))
+ {
+ IP_ADAPTER_UNICAST_ADDRESS *addr;
+
+ addr = heap_alloc_zero( sizeof(*addr) + sizeof(SOCKADDR_IN) );
+ addr->Next = NULL;
+ addr->Length = sizeof(*addr);
+ addr->Address.lpSockaddr = (SOCKADDR *)(addr + 1);
+ addr->Address.iSockaddrLength = sizeof(SOCKADDR_IN);
+ addr->Address.lpSockaddr->sa_family = AF_INET;
+ ((SOCKADDR_IN *)addr->Address.lpSockaddr)->sin_addr.s_addr = inet_addr( adapters_info[i].ip_address );
+ aa->FirstUnicastAddress = addr;
+ }
+
+ if (flags & GAA_FLAG_INCLUDE_GATEWAYS)
+ {
+ IP_ADAPTER_GATEWAY_ADDRESS *gw;
+
+ gw = heap_alloc_zero( sizeof(*gw) + sizeof(SOCKADDR_IN) );
+ gw->Next = NULL;
+ gw->Length = sizeof(*gw);
+ gw->Address.lpSockaddr = (SOCKADDR *)(gw + 1);
+ gw->Address.iSockaddrLength = sizeof(SOCKADDR_IN);
+ gw->Address.lpSockaddr->sa_family = AF_INET;
+ ((SOCKADDR_IN *)gw->Address.lpSockaddr)->sin_addr.s_addr = inet_addr( adapters_info[i].gateway );
+ aa->FirstGatewayAddress = gw;
+ }
+
+ aa++;
+ }
+
+ free( adapters_info );
+ aa[-1].Next = NULL;
+ return 0;
}
- else
- adapters_addresses_copy( aa, info );
+ else
+ {
+ IP_ADAPTER_ADDRESSES *info;
+ DWORD err, needed;
+
+ err = adapters_addresses_alloc( family, flags, &info );
+ if (err) return err;
- adapters_addresses_free( info );
- return err;
+ needed = adapters_addresses_size( info );
+ if (!aa || *size < needed)
+ {
+ *size = needed;
+ err = ERROR_BUFFER_OVERFLOW;
+ }
+ else
+ adapters_addresses_copy( aa, info );
+
+ adapters_addresses_free( info );
+ return err;
+ }
}
/******************************************************************