-
Notifications
You must be signed in to change notification settings - Fork 2
/
wpad_dhcp_mac.c
36 lines (31 loc) · 992 Bytes
/
wpad_dhcp_mac.c
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
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCDynamicStoreCopyDHCPInfo.h>
#include <TargetConditionals.h>
#include "net_adapter.h"
#include "util.h"
char *wpad_dhcp_adapter_mac(uint8_t bind_ip[4], net_adapter_s *adapter, int32_t timeout_sec) {
#if !TARGET_OS_IPHONE
CFDictionaryRef dhcp_info = NULL;
CFDataRef dhcp_wpad_url = NULL;
char *wpad = NULL;
// Get DHCP info for the primary adapter
dhcp_info = SCDynamicStoreCopyDHCPInfo(NULL, NULL);
if (!dhcp_info)
return NULL;
// Get the WPAD url from the DHCP server
dhcp_wpad_url = DHCPInfoGetOptionData(dhcp_info, 252);
if (dhcp_wpad_url)
wpad = strdup((const char *)CFDataGetBytePtr(dhcp_wpad_url));
CFRelease(dhcp_info);
return wpad;
#else
UNUSED(bind_ip);
UNUSED(adapter);
UNUSED(timeout_sec);
return NULL;
#endif
}