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.
This commit is contained in:
Eugene Syromyatnikov 2018-08-27 12:49:20 +02:00 committed by Dmitry V. Levin
parent 54fc755c56
commit ef859a2702
2 changed files with 10 additions and 0 deletions

1
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,

@ -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)