Change parser interface to allow stat
[petitboot] / test / parser / network.c
1 #include <string.h>
2 #include <types/types.h>
3 #include <talloc/talloc.h>
4 #include <sys/socket.h>
5 #include <linux/if.h>
6 #include "network.h"
7
8 struct interface {
9         int     ifindex;
10         char    name[IFNAMSIZ];
11         uint8_t hwaddr[HWADDR_SIZE];
12
13         enum {
14                 IFSTATE_NEW,
15                 IFSTATE_UP_WAITING_LINK,
16                 IFSTATE_CONFIGURED,
17                 IFSTATE_IGNORED,
18         } state;
19
20         struct list_item list;
21         struct process *udhcpc_process;
22         struct discover_device *dev;
23 };
24
25 static struct interface test = {
26         .name = "em1",
27         .hwaddr = {1,2,3,4,5,6},
28 };
29
30 static struct interface *find_interface_by_name(struct network *network,
31                                 const char *name)
32 {
33         (void)network;
34
35         if (!strcmp(test.name, name))
36                 return &test;
37
38         return NULL;
39 }
40
41 uint8_t *find_mac_by_name(void *ctx, struct network *network,
42                 const char *name)
43 {
44         struct interface *interface;
45         (void)network;
46
47         interface = find_interface_by_name(network, name);
48         if (!interface)
49                 return NULL;
50
51         return talloc_memdup(ctx, &interface->hwaddr,
52                              sizeof(uint8_t) * HWADDR_SIZE);
53 }