Bug #3288 » test.c
1 |
#include <stdio.h>
|
---|---|
2 |
#include <stdint.h>
|
3 |
|
4 |
|
5 |
struct ipcp_hdr { |
6 |
uint8_t code; |
7 |
uint8_t id; |
8 |
uint16_t len; |
9 |
uint8_t options[0]; |
10 |
};
|
11 |
|
12 |
enum ipcp_options { |
13 |
IPCP_OPT_IPADDR = 3, |
14 |
IPCP_OPT_PRIMARY_DNS = 129, |
15 |
IPCP_OPT_SECONDARY_DNS = 131, |
16 |
};
|
17 |
|
18 |
struct ipcp_option_hdr { |
19 |
uint8_t type; |
20 |
uint8_t len; |
21 |
uint8_t data[0]; |
22 |
};
|
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\n", 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 |
|
48 |
|
49 |
|
50 |
void main(void) |
51 |
{
|
52 |
struct ipcp_hdr *ipcp; |
53 |
|
54 |
uint8_t pco_ipcp[] = {0x01, 0x5e, 0x00, 0x0a, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00 }; |
55 |
|
56 |
ipcp = (struct ipcp_hdr*) (pco_ipcp); /* 2=type + 1=len */ |
57 |
|
58 |
printf("Hello, ipcp\n"); |
59 |
ipcp_contains_option(ipcp, IPCP_OPT_PRIMARY_DNS); |
60 |
printf("I am done!\n"); |
61 |
|
62 |
|
63 |
|
64 |
}
|