]>
Commit | Line | Data |
---|---|---|
e045e325 YW |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | /*** | |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <netinet/in.h> | |
22 | #include <string.h> | |
23 | ||
24 | #include "socket-protocol-list.h" | |
25 | #include "macro.h" | |
26 | ||
27 | static const struct socket_protocol_name* lookup_socket_protocol(register const char *str, register GPERF_LEN_TYPE len); | |
28 | ||
29 | #include "socket-protocol-from-name.h" | |
30 | #include "socket-protocol-to-name.h" | |
31 | ||
32 | const char *socket_protocol_to_name(int id) { | |
33 | ||
34 | if (id < 0) | |
35 | return NULL; | |
36 | ||
37 | if (id >= (int) ELEMENTSOF(socket_protocol_names)) | |
38 | return NULL; | |
39 | ||
40 | return socket_protocol_names[id]; | |
41 | } | |
42 | ||
43 | int socket_protocol_from_name(const char *name) { | |
44 | const struct socket_protocol_name *sc; | |
45 | ||
46 | assert(name); | |
47 | ||
48 | sc = lookup_socket_protocol(name, strlen(name)); | |
49 | if (!sc) | |
50 | return 0; | |
51 | ||
52 | return sc->id; | |
53 | } | |
54 | ||
55 | int socket_protocol_max(void) { | |
56 | return ELEMENTSOF(socket_protocol_names); | |
57 | } |