]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/ip-protocol-list.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <netinet/in.h>
6 #include "alloc-util.h"
7 #include "ip-protocol-list.h"
9 #include "parse-util.h"
10 #include "string-util.h"
12 static const struct ip_protocol_name
* lookup_ip_protocol(register const char *str
, register GPERF_LEN_TYPE len
);
14 #include "ip-protocol-from-name.h"
15 #include "ip-protocol-to-name.h"
17 const char *ip_protocol_to_name(int id
) {
22 if ((size_t) id
>= ELEMENTSOF(ip_protocol_names
))
25 return ip_protocol_names
[id
];
28 int ip_protocol_from_name(const char *name
) {
29 const struct ip_protocol_name
*sc
;
33 sc
= lookup_ip_protocol(name
, strlen(name
));
40 int parse_ip_protocol(const char *s
) {
41 _cleanup_free_
char *str
= NULL
;
49 /* Do not use strdupa() here, as the input string may come from *
50 * command line or config files. */
55 i
= ip_protocol_from_name(ascii_strlower(str
));
59 r
= safe_atoi(str
, &i
);
63 if (!ip_protocol_to_name(i
))