-static int add_rtattr(struct nlmsghdr *n, size_t max_length, int type, const void *data, size_t data_length) {
- size_t length;
- struct rtattr *rta;
-
- length = RTA_LENGTH(data_length);
-
- if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(length) > max_length)
- return -E2BIG;
-
- rta = NLMSG_TAIL(n);
- rta->rta_type = type;
- rta->rta_len = length;
- memcpy(RTA_DATA(rta), data, data_length);
- n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(length);
-
- return 0;
-}
-
-static ssize_t sendto_loop(int fd, const void *buf, size_t buf_len, int flags, const struct sockaddr *sa, socklen_t sa_len) {
-
- for (;;) {
- ssize_t l;
-
- if ((l = sendto(fd, buf, buf_len, flags, sa, sa_len)) >= 0)
- return l;
-
- if (errno != EINTR)
- return -errno;
- }
-}
-
-static ssize_t recvfrom_loop(int fd, void *buf, size_t buf_len, int flags, struct sockaddr *sa, socklen_t *sa_len) {
-
- for (;;) {
- ssize_t l;
-
- if ((l = recvfrom(fd, buf, buf_len, flags, sa, sa_len)) >= 0)
- return l;
-
- if (errno != EINTR)
- return -errno;
- }
-}
-
-static int add_adresses(int fd, int if_loopback, unsigned *requests) {
- union {
- struct sockaddr sa;
- struct sockaddr_nl nl;
- } sa;
- union {
- struct nlmsghdr header;
- uint8_t buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
- NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
- RTA_LENGTH(sizeof(struct in6_addr))];
- } request;
-
- struct ifaddrmsg *ifaddrmsg;
- uint32_t ipv4_address = htonl(INADDR_LOOPBACK);