]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ankh/examples/dhcp/main.c
Update
[l4.git] / l4 / pkg / ankh / examples / dhcp / main.c
1 #include <l4/ankh/client-c.h>
2 #include <l4/ankh/netboot.h>
3 #include <l4/ankh/session.h>
4 #include <getopt.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <pthread-l4.h>
9 #include <arpa/inet.h>
10
11 #define GETOPT_LIST_END { 0, 0, 0, 0 }
12
13 enum options
14 {
15         BUF_SIZE,
16         SHM_NAME,
17 };
18
19 static int bufsize = 1024;
20 static char *shm_name = "";
21
22
23 int main(int argc, char **argv)
24 {
25         if (l4ankh_init())
26           return 1;
27         l4_cap_idx_t c = pthread_l4_cap(pthread_self());
28
29         static struct option long_opts[] = {
30                 {"bufsize", 1, 0, BUF_SIZE },
31                 {"shm", 1, 0, SHM_NAME },
32                 GETOPT_LIST_END
33         };
34
35         while (1) {
36                 int optind = 0;
37                 int opt = getopt_long(argc, argv, "b:s:", long_opts, &optind);
38                 printf("getopt: %d\n", opt);
39
40                 if (opt == -1)
41                         break;
42
43                 switch(opt) {
44                         case BUF_SIZE:
45                                 printf("buf size: %d\n", atoi(optarg));
46                                 bufsize = atoi(optarg);
47                                 break;
48                         case SHM_NAME:
49                                 printf("shm name: %s\n", optarg);
50                                 shm_name = strdup(optarg);
51                                 break;
52                         default:
53                                 break;
54                 }
55         }
56
57     netboot_init(shm_name, bufsize, c, c);
58         dhcp();
59         print_network_configuration();
60
61         free(shm_name);
62
63         return 0;
64 }