netlink.c revision 8041b5bada31db152de80e45b3047ed32cef6880
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of nss-myhostname.
Copyright 2008-2011 Lennart Poettering
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
nss-myhostname is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with nss-myhostname; If not, see
***/
#include <inttypes.h>
#include <linux/rtnetlink.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <inttypes.h>
#include <stdlib.h>
#include "netlink.h"
/* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
return -1;
return 1;
return -1;
return 1;
return -1;
return 1;
return 0;
}
struct {
} req;
unsigned n_list = 0;
if (fd < 0)
return -errno;
r = -errno;
goto finish;
}
r = -errno;
goto finish;
}
for (;;) {
struct nlmsghdr *p;
struct {
} resp;
msg.msg_namelen = 0;
if (bytes < 0) {
r = -errno;
goto finish;
}
r = -EIO;
goto finish;
}
continue;
struct rtattr *a;
size_t l;
r = -EIO;
goto finish;
}
continue;
if (p->nlmsg_type == NLMSG_DONE) {
r = 0;
goto finish;
}
if (p->nlmsg_type == NLMSG_ERROR) {
nlmsgerr = NLMSG_DATA(p);
goto finish;
}
if (p->nlmsg_type != RTM_NEWADDR)
continue;
ifaddrmsg = NLMSG_DATA(p);
continue;
continue;
continue;
l = NLMSG_PAYLOAD(p, sizeof(struct ifaddrmsg));
while (RTA_OK(a, l)) {
if (a->rta_type == IFA_ADDRESS)
a = RTA_NEXT(a, l);
}
if (local)
if (!address)
continue;
if (!list) {
r = -ENOMEM;
goto finish;
}
n_list++;
}
}
if (r < 0)
else {
}
return r;
}