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
|
PIP_ADAPTER_ADDRESSES, PULONG);
static void
init(void)
{
HMODULE module;
if ((module = LoadLibrary("iphlpapi.dll")) != NULL)
GetAdaptersAddressesFuncPtr = (WINAPI ULONG (*)(ULONG, ULONG,
PVOID, PIP_ADAPTER_ADDRESSES, PULONG))
GetProcAddress(module, "GetAdaptersAddresses");
}
static OFMutableDictionary OF_GENERIC(OFString *, OFNetworkInterface) *
networkInterfacesFromGetAdaptersAddresses(void)
{
OFMutableDictionary *ret = [OFMutableDictionary dictionary];
OFStringEncoding encoding = [OFLocale encoding];
ULONG adapterAddressesSize = sizeof(IP_ADAPTER_ADDRESSES);
PIP_ADAPTER_ADDRESSES adapterAddresses;
if ((adapterAddresses = malloc(adapterAddressesSize)) == NULL)
return nil;
@try {
|
|
<
|
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
|
PIP_ADAPTER_ADDRESSES, PULONG);
static void
init(void)
{
HMODULE module;
if ((module = GetModuleHandle("iphlpapi.dll")) != NULL)
GetAdaptersAddressesFuncPtr = (WINAPI ULONG (*)(ULONG, ULONG,
PVOID, PIP_ADAPTER_ADDRESSES, PULONG))
GetProcAddress(module, "GetAdaptersAddresses");
}
static OFMutableDictionary OF_GENERIC(OFString *, OFNetworkInterface) *
networkInterfacesFromGetAdaptersAddresses(void)
{
OFMutableDictionary *ret = [OFMutableDictionary dictionary];
ULONG adapterAddressesSize = sizeof(IP_ADAPTER_ADDRESSES);
PIP_ADAPTER_ADDRESSES adapterAddresses;
if ((adapterAddresses = malloc(adapterAddressesSize)) == NULL)
return nil;
@try {
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
for (PIP_ADAPTER_ADDRESSES iter = adapterAddresses;
iter != NULL; iter = iter->Next) {
OFString *name;
OFMutableDictionary *interface;
OFNumber *index;
name = [OFString stringWithCString: iter->AdapterName
encoding: encoding];
if ((interface = [ret objectForKey: name]) == nil) {
interface = [OFMutableDictionary dictionary];
[ret setObject: interface forKey: name];
}
index = [OFNumber numberWithUnsignedInt: iter->IfIndex];
|
|
|
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
for (PIP_ADAPTER_ADDRESSES iter = adapterAddresses;
iter != NULL; iter = iter->Next) {
OFString *name;
OFMutableDictionary *interface;
OFNumber *index;
name = [OFString stringWithFormat: @"%lu",
iter->IfIndex];
if ((interface = [ret objectForKey: name]) == nil) {
interface = [OFMutableDictionary dictionary];
[ret setObject: interface forKey: name];
}
index = [OFNumber numberWithUnsignedInt: iter->IfIndex];
|
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
iter = iter->Next) {
OFMutableDictionary *interface;
OFString *name, *IPString;
OFNumber *index;
OFSocketAddress IPv4Address;
OFData *addresses;
name = [OFString stringWithCString: iter->AdapterName
encoding: encoding];
if ((interface = [ret objectForKey: name]) == nil) {
interface = [OFMutableDictionary dictionary];
[ret setObject: interface forKey: name];
}
index = [OFNumber numberWithUnsignedInt: iter->Index];
|
|
<
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
iter = iter->Next) {
OFMutableDictionary *interface;
OFString *name, *IPString;
OFNumber *index;
OFSocketAddress IPv4Address;
OFData *addresses;
name = [OFString stringWithFormat: @"%u", iter->Index];
if ((interface = [ret objectForKey: name]) == nil) {
interface = [OFMutableDictionary dictionary];
[ret setObject: interface forKey: name];
}
index = [OFNumber numberWithUnsignedInt: iter->Index];
|