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