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:
parent
54fc755c56
commit
ef859a2702
1
defs.h
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user