mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 02:21:44 +03:00
sd-netlink: introduce netlink_message_read_in_addr_union()
This commit is contained in:
parent
47a277f18b
commit
f29b6b371e
@ -862,11 +862,12 @@ int sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short typ
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_in_addr(sd_netlink_message *m, unsigned short type, struct in_addr *data) {
|
||||
int r;
|
||||
int netlink_message_read_in_addr_union(sd_netlink_message *m, unsigned short type, int family, union in_addr_union *data) {
|
||||
void *attr_data;
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(IN_SET(family, AF_INET, AF_INET6), -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
|
||||
if (r < 0)
|
||||
@ -875,35 +876,35 @@ int sd_netlink_message_read_in_addr(sd_netlink_message *m, unsigned short type,
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(struct in_addr))
|
||||
else if ((size_t) r < FAMILY_ADDRESS_SIZE(family))
|
||||
return -EIO;
|
||||
|
||||
if (data)
|
||||
memcpy(data, attr_data, sizeof(struct in_addr));
|
||||
memcpy(data, attr_data, FAMILY_ADDRESS_SIZE(family));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_in6_addr(sd_netlink_message *m, unsigned short type, struct in6_addr *data) {
|
||||
int sd_netlink_message_read_in_addr(sd_netlink_message *m, unsigned short type, struct in_addr *data) {
|
||||
union in_addr_union u;
|
||||
int r;
|
||||
void *attr_data;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
r = netlink_message_read_in_addr_union(m, type, AF_INET, &u);
|
||||
if (r >= 0 && data)
|
||||
*data = u.in;
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return r;
|
||||
}
|
||||
|
||||
r = netlink_message_read_internal(m, type, &attr_data, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
else if ((size_t) r < sizeof(struct in6_addr))
|
||||
return -EIO;
|
||||
int sd_netlink_message_read_in6_addr(sd_netlink_message *m, unsigned short type, struct in6_addr *data) {
|
||||
union in_addr_union u;
|
||||
int r;
|
||||
|
||||
if (data)
|
||||
memcpy(data, attr_data, sizeof(struct in6_addr));
|
||||
r = netlink_message_read_in_addr_union(m, type, AF_INET6, &u);
|
||||
if (r >= 0 && data)
|
||||
*data = u.in6;
|
||||
|
||||
return 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int sd_netlink_message_read_strv(sd_netlink_message *m, unsigned short container_type, unsigned short type_id, char ***ret) {
|
||||
|
@ -90,5 +90,7 @@ int rtnl_log_create_error(int r);
|
||||
int netlink_message_append_in_addr_union(sd_netlink_message *m, unsigned short type, int family, const union in_addr_union *data);
|
||||
int netlink_message_append_sockaddr_union(sd_netlink_message *m, unsigned short type, const union sockaddr_union *data);
|
||||
|
||||
int netlink_message_read_in_addr_union(sd_netlink_message *m, unsigned short type, int family, union in_addr_union *data);
|
||||
|
||||
void rtattr_append_attribute_internal(struct rtattr *rta, unsigned short type, const void *data, size_t data_length);
|
||||
int rtattr_append_attribute(struct rtattr **rta, unsigned short type, const void *data, size_t data_length);
|
||||
|
Loading…
Reference in New Issue
Block a user