]> granicus.if.org Git - strace/commitdiff
socketutils: introduce get_family_by_proto
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 27 Aug 2018 10:49:20 +0000 (12:49 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 2 Sep 2018 17:44:26 +0000 (17:44 +0000)
Add a helper function that returns address family based on the internal
notion of the socket protocol using protocols table.

* defs.h (get_family_by_proto): New declaration.
* socketutils.c (get_family_by_proto): New function.

defs.h
socketutils.c

diff --git a/defs.h b/defs.h
index 22ab1970ac4e7e08d87d5e56065cdc83cd91cf38..394f509e880b5b8d9cf1aadb42b7cdb506ef7e0a 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -396,6 +396,7 @@ enum sock_proto {
        SOCK_PROTO_NETLINK,
 };
 extern enum sock_proto get_proto_by_name(const char *);
+extern int get_family_by_proto(enum sock_proto proto);
 
 enum iov_decode {
        IOV_DECODE_ADDR,
index dd8451e44f4b8eb7983dbfad38b4163a15447165..aa0752c377f76c323c3e8a676b8684e2a3c4e3d2 100644 (file)
@@ -507,6 +507,15 @@ get_proto_by_name(const char *const name)
        return SOCK_PROTO_UNKNOWN;
 }
 
+int
+get_family_by_proto(enum sock_proto proto)
+{
+       if ((size_t) proto < ARRAY_SIZE(protocols))
+               return protocols[proto].family;
+
+       return AF_UNSPEC;
+}
+
 static const char *
 get_sockaddr_by_inode_uncached(struct tcb *tcp, const unsigned long inode,
                               const enum sock_proto proto)