Commit f40cbec0 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add kernel_interface_ipv4.

parent 02baf1c0
...@@ -37,6 +37,7 @@ struct kernel_route { ...@@ -37,6 +37,7 @@ struct kernel_route {
int kernel_setup(int setup); int kernel_setup(int setup);
int kernel_setup_socket(int setup); int kernel_setup_socket(int setup);
int kernel_setup_interface(int setup, const char *ifname, int ifindex); int kernel_setup_interface(int setup, const char *ifname, int ifindex);
int kernel_interface_ipv4(const char *ifname, int ifindex, char *addr_r);
int kernel_interface_mtu(const char *ifname, int ifindex); int kernel_interface_mtu(const char *ifname, int ifindex);
int kernel_interface_wireless(const char *ifname, int ifindex); int kernel_interface_wireless(const char *ifname, int ifindex);
int kernel_route(int operation, const unsigned char *dest, unsigned short plen, int kernel_route(int operation, const unsigned char *dest, unsigned short plen,
......
...@@ -500,6 +500,29 @@ kernel_setup_interface(int setup, const char *ifname, int ifindex) ...@@ -500,6 +500,29 @@ kernel_setup_interface(int setup, const char *ifname, int ifindex)
return 1; return 1;
} }
int
kernel_interface_ipv4(const char *ifname, int ifindex, char *addr_r)
{
struct ifreq req;
int s, rc;
s = socket(PF_INET, SOCK_DGRAM, 0);
if(s < 0)
return -1;
memset(&req, 0, sizeof(req));
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
req.ifr_addr.sa_family = AF_INET;
rc = ioctl(s, SIOCGIFADDR, &req);
if(rc < 0) {
close(s);
return -1;
}
memcpy(addr_r, &((struct sockaddr_in*)&req.ifr_addr)->sin_addr, 4);
return 1;
}
int int
kernel_interface_mtu(const char *ifname, int ifindex) kernel_interface_mtu(const char *ifname, int ifindex)
{ {
......
...@@ -220,6 +220,29 @@ kernel_setup_interface(int setup, const char *ifname, int ifindex) ...@@ -220,6 +220,29 @@ kernel_setup_interface(int setup, const char *ifname, int ifindex)
return 1; return 1;
} }
int
kernel_interface_ipv4(const char *ifname, int ifindex, char *addr_r)
{
struct ifreq req;
int s, rc;
s = socket(PF_INET, SOCK_DGRAM, 0);
if(s < 0)
return -1;
memset(&req, 0, sizeof(req));
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
req.ifr_addr.sa_family = AF_INET;
rc = ioctl(s, SIOCGIFADDR, &req);
if(rc < 0) {
close(s);
return -1;
}
memcpy(addr_r, &((struct sockaddr_in*)&req.ifr_addr)->sin_addr, 4);
return 1;
}
int int
kernel_interface_mtu(const char *ifname, int ifindex) kernel_interface_mtu(const char *ifname, int ifindex)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment