rtnl_link_get_kernel()
Wouter Verhelst
w at uter.be
Fri Jul 6 18:51:01 EDT 2012
On Wed, Jul 04, 2012 at 05:04:12AM -0400, Thomas Graf wrote:
> On Tue, Jul 03, 2012 at 11:32:15PM -0600, Wouter Verhelst wrote:
> > So I'm trying to use that (I don't need no steenking cache), but it's
> > not working.
> >
> > My code does this:
> >
> > (common.c)
> > static nl_sock* socket;
> >
> > struct nl_sock* get_socket() {
> > if(!socket) {
> > socket = nl_socket_alloc();
> > nl_socket_set_local_port(socket, 0);
>
> Setting the local port to 0 is not needed, generating a
> unique port is the default.
Right. I had done that because it didn't work, and because I thought
that was the required set-up, but clearly it's not necessary.
> > }
> > return socket;
> > }
> >
> > (actual code later on)
> >
> > struct nl_sock* socket = get_socket();
> > struct rtnl_link* link = rtnl_link_alloc();
> >
> > rtnl_link_get_kernel(socket, 0, "eth0", &link);
> >
> > but that returns -NLE_BAD_SOCK. What am I missing?
>
> Your socket is not connected, call nl_connect() and bind it
> to the NETLINK_ROUTE netlink protocol.
Yes, that works, thanks, and I'm now able to fiddle with the operational
status of the link (i.e., bring it up or down).
What I've not been able to do yet, however, is read the assigned IP
address(es) to a particular interface. There's rtnl_addr_get(), but
that wants a cache (which I'm not using). There's rtnl_link_inet_get_conf(),
but that doesn't seem to be dealing with IP addresses unless I'm
terribly mistaken.
What am I missing?
--
The volume of a pizza of thickness a and radius z can be described by
the following formula:
pi zz a
More information about the libnl
mailing list