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:
1
defs.h
1
defs.h
@ -396,6 +396,7 @@ enum sock_proto {
|
|||||||
SOCK_PROTO_NETLINK,
|
SOCK_PROTO_NETLINK,
|
||||||
};
|
};
|
||||||
extern enum sock_proto get_proto_by_name(const char *);
|
extern enum sock_proto get_proto_by_name(const char *);
|
||||||
|
extern int get_family_by_proto(enum sock_proto proto);
|
||||||
|
|
||||||
enum iov_decode {
|
enum iov_decode {
|
||||||
IOV_DECODE_ADDR,
|
IOV_DECODE_ADDR,
|
||||||
|
@ -507,6 +507,15 @@ get_proto_by_name(const char *const name)
|
|||||||
return SOCK_PROTO_UNKNOWN;
|
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 *
|
static const char *
|
||||||
get_sockaddr_by_inode_uncached(struct tcb *tcp, const unsigned long inode,
|
get_sockaddr_by_inode_uncached(struct tcb *tcp, const unsigned long inode,
|
||||||
const enum sock_proto proto)
|
const enum sock_proto proto)
|
||||||
|
Reference in New Issue
Block a user