1
|
#include <stdio.h>
|
2
|
#include <stdint.h>
|
3
|
#include <arpa/inet.h>
|
4
|
|
5
|
struct ipcp_hdr {
|
6
|
uint8_t code;
|
7
|
uint8_t id;
|
8
|
uint16_t len;
|
9
|
uint8_t options[0];
|
10
|
} __attribute__ ((packed));
|
11
|
|
12
|
enum ipcp_options {
|
13
|
IPCP_OPT_IPADDR = 3,
|
14
|
IPCP_OPT_PRIMARY_DNS = 129,
|
15
|
IPCP_OPT_SECONDARY_DNS = 131,
|
16
|
} __attribute__ ((packed));
|
17
|
|
18
|
struct ipcp_option_hdr {
|
19
|
uint8_t type;
|
20
|
uint8_t len;
|
21
|
uint8_t data[0];
|
22
|
} __attribute__ ((packed));
|
23
|
|
24
|
/* determine if IPCP contains given option */
|
25
|
static struct ipcp_option_hdr *ipcp_contains_option(struct ipcp_hdr *ipcp, enum ipcp_options opt)
|
26
|
{
|
27
|
uint8_t *cur = ipcp->options;
|
28
|
|
29
|
printf("ipcp->code=%x\n", ipcp->code);
|
30
|
printf("ipcp->id=%x\n", ipcp->id);
|
31
|
printf("ipcp->len=%x (%u)\n", ipcp->len, ipcp->len);
|
32
|
|
33
|
/* iterate over Options and check if protocol contained */
|
34
|
while (cur + 2 <= ((uint8_t *)ipcp) + ipcp->len) {
|
35
|
struct ipcp_option_hdr *cur_opt = (struct ipcp_option_hdr *) cur;
|
36
|
printf("\n");
|
37
|
printf("cur_opt->type=%x\n", cur_opt->type);
|
38
|
printf("cur_opt->len=%x\n", cur_opt->len);
|
39
|
|
40
|
if (cur_opt->type == opt)
|
41
|
return cur_opt;
|
42
|
cur += cur_opt->len;
|
43
|
}
|
44
|
return NULL;
|
45
|
}
|
46
|
|
47
|
void main(void)
|
48
|
{
|
49
|
struct ipcp_hdr *ipcp;
|
50
|
|
51
|
uint8_t pco_ipcp[] = {0x80, 0x21, 0x0a, 0x01, 0x0a, 0x00, 0x0a, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x80, 0x21, 0x0a, 0x01, 0x0b, 0x00, 0x0a};
|
52
|
|
53
|
ipcp = (struct ipcp_hdr*) (pco_ipcp + 3); /* 2=type + 1=len */
|
54
|
|
55
|
/* Fix endieness of length field! */
|
56
|
ipcp->len = ntohs(ipcp->len);
|
57
|
|
58
|
|
59
|
printf("Hello, ipcp\n");
|
60
|
ipcp_contains_option(ipcp, IPCP_OPT_PRIMARY_DNS);
|
61
|
printf("Primary DNS done\n\n\n");
|
62
|
ipcp_contains_option(ipcp, IPCP_OPT_SECONDARY_DNS);
|
63
|
printf("Secondary DNS done\n\n\n");
|
64
|
|
65
|
|
66
|
|
67
|
}
|