chiark / gitweb /
basic: introduce socket_protocol_{from,to}_name()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 23 Dec 2017 10:32:04 +0000 (19:32 +0900)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:40 +0000 (07:49 +0200)
And use them where they can be applicable.

src/basic/generate-socket-protocol-list.sh [new file with mode: 0644]
src/basic/meson.build
src/basic/socket-protocol-to-name.awk [new file with mode: 0644]

diff --git a/src/basic/generate-socket-protocol-list.sh b/src/basic/generate-socket-protocol-list.sh
new file mode 100644 (file)
index 0000000..18a540f
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh -eu
+
+$1 -dM -include netinet/in.h - </dev/null | \
+        awk '/^#define[ \t]+IPPROTO_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
+        sed -e 's/IPPROTO_//'
index 3ea5e059a3bae4ddabef4dd6aaf0c49fda96369f..5d9780e94678f2ffde2754d638dd8e16fd9e42bd 100644 (file)
 #         smack-util.c
 #         smack-util.h
 #         socket-label.c
+#         socket-protocol-list.c
+#         socket-protocol-list.h
 #         socket-util.c
 #         socket-util.h
 #         sparse-endian.h
@@ -404,12 +406,20 @@ errno_list_txt = custom_target(
         command : [generate_errno_list, cpp],
         capture : true)
 
+generate_socket_protocol_list = find_program('generate-socket-protocol-list.sh')
+socket_protocol_list_txt = custom_target(
+        'socket-protocol-list.txt',
+        output : 'socket-protocol-list.txt',
+        command : [generate_socket_protocol_list, cpp],
+        capture : true)
+
 generated_gperf_headers = []
 #if 0 /// elogind has only the cap and errno list.
 # foreach item : [['af',     af_list_txt,     'af',         ''],
 #                 ['arphrd', arphrd_list_txt, 'arphrd',     'ARPHRD_'],
 #                 ['cap',    cap_list_txt,    'capability', ''],
-#                 ['errno',  errno_list_txt,  'errno',      '']]
+#                 ['errno',  errno_list_txt,  'errno',      ''],
+#                 ['socket-protocol', socket_protocol_list_txt, 'socket_protocol',     'IPPROTO_']]
 #else
 foreach item : [['cap',    cap_list_txt,    'capability', ''],
                 ['errno',  errno_list_txt,  'errno',      '']]
diff --git a/src/basic/socket-protocol-to-name.awk b/src/basic/socket-protocol-to-name.awk
new file mode 100644 (file)
index 0000000..4848a76
--- /dev/null
@@ -0,0 +1,9 @@
+BEGIN{
+        print "static const char* const socket_protocol_names[] = { "
+}
+!/HOPOPTS/ {
+        printf "        [IPPROTO_%s] = \"%s\",\n", $1, tolower($1)
+}
+END{
+        print "};"
+}