2

I am using Netlink to create a network interface without specifying the name. Netlink chooses a name for the new interface (like for example "vlan0"), but I do not know how to figure this name out.

My function calls are (in pseudo code):

link = rtnl_link_alloc();
rtnl_link_set_type(link, kind));
rtnl_link_add(sk, link, NLM_F_CREATE));

The interface is created without errors but calling rtnl_link_get_name(link) or rtnl_link_get_ifindex(link) but fail after the call to rtnl_link_add().

So how can I determine the name of the new interface?

J. Doe
  • 146
  • 4
  • You should probably provide something more than pseudocode (also see [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve)). According to [`rtnetlink (7)` man page](http://man7.org/linux/man-pages/man7/rtnetlink.7.html), it looks like it is available in the `ifinfomsg` or `nlmsghdr` structs when `rta_type` is `IFLA_IFNAME`. With a few useful symbols, it looks like sample code is available at [Howto get a list of network interfaces in Linux, Part 3](https://iijean.blogspot.com/2010/03/howto-get-list-of-network-interfaces-in.html). – jww Dec 24 '17 at 20:42

0 Answers0