]>
Commit | Line | Data |
---|---|---|
e045e325 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
e045e325 YW |
2 | |
3 | #include <netinet/in.h> | |
4 | #include <string.h> | |
5 | ||
6 | #include "socket-protocol-list.h" | |
7 | #include "macro.h" | |
8 | ||
9 | static const struct socket_protocol_name* lookup_socket_protocol(register const char *str, register GPERF_LEN_TYPE len); | |
10 | ||
11 | #include "socket-protocol-from-name.h" | |
12 | #include "socket-protocol-to-name.h" | |
13 | ||
14 | const char *socket_protocol_to_name(int id) { | |
15 | ||
16 | if (id < 0) | |
17 | return NULL; | |
18 | ||
19 | if (id >= (int) ELEMENTSOF(socket_protocol_names)) | |
20 | return NULL; | |
21 | ||
22 | return socket_protocol_names[id]; | |
23 | } | |
24 | ||
25 | int socket_protocol_from_name(const char *name) { | |
26 | const struct socket_protocol_name *sc; | |
27 | ||
28 | assert(name); | |
29 | ||
30 | sc = lookup_socket_protocol(name, strlen(name)); | |
31 | if (!sc) | |
32 | return 0; | |
33 | ||
34 | return sc->id; | |
35 | } | |
36 | ||
37 | int socket_protocol_max(void) { | |
38 | return ELEMENTSOF(socket_protocol_names); | |
39 | } |