#include <config.h>
#endif
+#include <stdio.h>
#include <errno.h>
#include <unistd.h>
+#include <sys/ioctl.h>
#include <stdint.h>
#include <string.h>
#include <endian.h>
+#include <net/if_arp.h>
+#include <linux/if.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
{ OPTION_IP, 0x01 }, /* subnet-mask */
{ OPTION_IP | OPTION_LIST, 0x03 }, /* routers */
{ OPTION_IP | OPTION_LIST, 0x06 }, /* domain-name-servers */
+ { OPTION_STRING, 0x0c }, /* hostname */
{ OPTION_STRING, 0x0f }, /* domain-name */
{ OPTION_IP | OPTION_LIST, 0x2a }, /* ntp-servers */
{ OPTION_U32, 0x33 }, /* dhcp-lease-time */
/* Options below will not be exposed to user */
{ OPTION_IP, 0x32 }, /* requested-ip */
{ OPTION_U8, 0x35 }, /* message-type */
+ { OPTION_U32, 0x36 }, /* server-id */
{ OPTION_U16, 0x39 }, /* max-size */
{ OPTION_STRING, 0x3c }, /* vendor */
{ OPTION_STRING, 0x3d }, /* client-id */
return fd;
}
+
+char *get_interface_name(int index)
+{
+ struct ifreq ifr;
+ int sk, err;
+
+ if (index < 0)
+ return NULL;
+
+ sk = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sk < 0) {
+ perror("Open socket error");
+ return NULL;
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = index;
+
+ err = ioctl(sk, SIOCGIFNAME, &ifr);
+ if (err < 0) {
+ perror("Get interface name error");
+ close(sk);
+ return NULL;
+ }
+
+ close(sk);
+
+ return g_strdup(ifr.ifr_name);
+}
+
+gboolean interface_is_up(int index)
+{
+ int sk, err;
+ struct ifreq ifr;
+ gboolean ret = FALSE;
+
+ sk = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sk < 0) {
+ perror("Open socket error");
+ return FALSE;
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = index;
+
+ err = ioctl(sk, SIOCGIFNAME, &ifr);
+ if (err < 0) {
+ perror("Get interface name error");
+ goto done;
+ }
+
+ err = ioctl(sk, SIOCGIFFLAGS, &ifr);
+ if (err < 0) {
+ perror("Get interface flags error");
+ goto done;
+ }
+
+ if (ifr.ifr_flags & IFF_UP)
+ ret = TRUE;
+
+done:
+ close(sk);
+
+ return ret;
+}