]> git.sur5r.net Git - ngadmin/blob - lib/src/libconf.c
e26a7224e23ba964210d635e20cffc843c060c91
[ngadmin] / lib / src / libconf.c
1
2 #include <ngadmin.h>
3
4 #include <attr.h>
5 #include <protocol.h>
6
7 #include "lib.h"
8 #include "network.h"
9
10
11 static const struct timeval default_timeout = {.tv_sec = 4, .tv_usec = 0};
12
13
14 struct ngadmin* ngadmin_init (const char *iface)
15 {
16         struct ngadmin *nga;
17         
18         
19         /* allocate main structure */
20         nga = malloc(sizeof(struct ngadmin));
21         memset(nga, 0, sizeof(struct ngadmin));
22         
23         strncpy(nga->iface, iface, IFNAMSIZ - 1);
24         
25         if (startNetwork(nga) < 0) {
26                 free(nga);
27                 return NULL;
28         }
29         
30         nga->timeout = default_timeout;
31         if (updateTimeout(nga) < 0) {
32                 free(nga);
33                 return NULL;
34         }
35         
36         
37         return nga;
38 }
39
40
41 int ngadmin_close (struct ngadmin *nga)
42 {
43         if (nga == NULL)
44                 return ERR_INVARG;
45                 
46         stopNetwork(nga);
47         free(nga->swi_tab);
48         free(nga);
49         
50         return ERR_OK;
51 }
52
53
54 int ngadmin_forceInterface (struct ngadmin *nga)
55 {
56         if (nga == NULL)
57                 return ERR_INVARG;
58         
59         return forceInterface(nga) == 0 ? ERR_OK : ERR_NET;
60 }
61
62
63 int ngadmin_setKeepBroadcasting (struct ngadmin *nga, bool value)
64 {
65         if (nga == NULL)
66                 return ERR_INVARG;
67         
68         nga->keepbroad = value;
69         
70         return ERR_OK;
71 }
72
73
74 int ngadmin_useGlobalBroadcast (struct ngadmin *nga, bool value)
75 {
76         if (nga == NULL)
77                 return ERR_INVARG;
78         
79         nga->globalbroad = value;
80         
81         return ERR_OK;
82 }
83
84
85 int ngadmin_setPassword (struct ngadmin *nga, const char *pass)
86 {
87         if (nga == NULL)
88                 return ERR_INVARG;
89         
90         strncpy(nga->password, pass, PASSWORD_MAX);
91         
92         return ERR_OK;
93 }
94
95
96 int ngadmin_setTimeout (struct ngadmin *nga, const struct timeval *tv)
97 {
98         int ret = ERR_OK;
99         
100         
101         if (nga == NULL || tv == NULL)
102                 return ERR_INVARG;
103         
104         nga->timeout = *tv;
105         if (updateTimeout(nga) < 0)
106                 ret = ERR_NET;
107         
108         
109         return ret;
110 }
111
112