Skip to content

Commit

Permalink
lkl-upstream: add lkl_ifname_to_ifindex()
Browse files Browse the repository at this point in the history
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
  • Loading branch information
thehajime committed Jun 11, 2018
1 parent ab1164d commit 2aa468e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ int lkl_set_ipv6_gateway(void* addr);
int lkl_if_set_ipv6_gateway(int ifindex, void *addr,
unsigned int netmask_len, void *gw_addr);

/**
* lkl_ifname_to_ifindex - obtain ifindex of an interface by name
*
* @name - string of an interface
* @returns - return an integer of ifindex if no error
*/
int lkl_ifname_to_ifindex(const char *name);

/**
* lkl_netdev - host network device handle, defined in lkl_host.h.
*/
Expand Down
18 changes: 18 additions & 0 deletions tools/lkl/lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ static inline int ifindex_to_name(int sock, struct lkl_ifreq *ifr, int ifindex)
return lkl_sys_ioctl(sock, LKL_SIOCGIFNAME, (long)ifr);
}

int lkl_ifname_to_ifindex(const char *name)
{
struct lkl_ifreq ifr;
int fd, ret;

fd = lkl_sys_socket(LKL_AF_INET, LKL_SOCK_DGRAM, 0);
if (fd < 0)
return fd;

strcpy(ifr.lkl_ifr_name, name);

ret = lkl_sys_ioctl(fd, LKL_SIOCGIFINDEX, (long)&ifr);
if (ret < 0)
return ret;

return ifr.lkl_ifr_ifindex;
}

int lkl_if_up(int ifindex)
{
struct lkl_ifreq ifr;
Expand Down

0 comments on commit 2aa468e

Please sign in to comment.