From: Eugene Syromyatnikov Date: Mon, 27 Aug 2018 10:49:20 +0000 (+0200) Subject: socketutils: introduce get_family_by_proto X-Git-Tag: v4.25~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef859a27029fe2977f954d270a701fabaae28024;p=strace socketutils: introduce get_family_by_proto 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. --- diff --git a/defs.h b/defs.h index 22ab1970..394f509e 100644 --- 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, diff --git a/socketutils.c b/socketutils.c index dd8451e4..aa0752c3 100644 --- a/socketutils.c +++ b/socketutils.c @@ -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)