|
1 #ifndef CONFIG_H |
|
2 #define CONFIG_H |
|
3 |
|
4 #include <sys/socket.h> |
|
5 #include <sys/un.h> |
|
6 |
|
7 #define ADDR_TEXT_LEN 128 |
|
8 #define ADDR_TEXT_LEN_STR "128" |
|
9 #define PORT_TEXT_LEN 32 |
|
10 #define PORT_TEXT_LEN_STR "32" |
|
11 #define PATH_TEXT_LEN 108 /* from sys/un.h */ |
|
12 #define PATH_TEXT_LEN_STR "108" /* from sys/un.h */ |
|
13 |
|
14 struct config_endpoint { |
|
15 // one of AF_LOCAL, AF_INET, AF_INET6 |
|
16 int family; |
|
17 |
|
18 // buffers to store the extracted textual addres/port into |
|
19 // these /should/ be long enough |
|
20 union { |
|
21 // PF_INET - may be a numeric IPv4 address, numeric IPv6 address, or hostname |
|
22 struct { |
|
23 const char *addr; |
|
24 const char *port; |
|
25 } inet; |
|
26 |
|
27 // PF_LOCAL |
|
28 struct { |
|
29 const char *path; |
|
30 } local; |
|
31 |
|
32 } af; |
|
33 |
|
34 struct { |
|
35 char addr[ADDR_TEXT_LEN]; |
|
36 char port[PORT_TEXT_LEN]; |
|
37 char default_port[PORT_TEXT_LEN]; |
|
38 char path[PATH_TEXT_LEN]; |
|
39 } _data; |
|
40 }; |
|
41 |
|
42 void endpoint_init (struct config_endpoint *endpoint, unsigned short default_port); |
|
43 int endpoint_parse (struct config_endpoint *endpoint, const char *addr_spec); |
|
44 |
|
45 /* |
|
46 * Parse a host:port string. |
|
47 * |
|
48 * Valid formats: |
|
49 * host |
|
50 * host:port |
|
51 * [host] |
|
52 * [host]:port |
|
53 * |
|
54 * The contents of the given hostport string *will* be modified. |
|
55 * |
|
56 * The value of *port will be set to NULL if no port was given. |
|
57 * |
|
58 * Returns 0 and sets *host if succesfull, nonzero otherwise. |
|
59 * |
|
60 */ |
|
61 int parse_hostport (char *hostport, char **host, char **port); |
|
62 |
|
63 #endif /* CONFIG_H */ |
|
64 |