X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gdhcp%2Fcommon.c;h=ff25dfe811b853361762d4dc92c2ab0862a39271;hb=eb16a6becb8ab1dd4be3696ab446ab91830f6fc5;hp=784844b52fadfa383813244ccf12151c3f0d0a31;hpb=0c5c862749c05193cf4c513628328c6db02b5222;p=framework%2Fconnectivity%2Fconnman.git diff --git a/gdhcp/common.c b/gdhcp/common.c index 784844b..ff25dfe 100644 --- a/gdhcp/common.c +++ b/gdhcp/common.c @@ -22,11 +22,15 @@ #include #endif +#include #include #include +#include #include #include #include +#include +#include #include #include @@ -37,15 +41,18 @@ static const DHCPOption client_options[] = { { 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 */ + { OPTION_STRING, 0xfc }, /* UNOFFICIAL proxy-pac */ { OPTION_UNKNOWN, 0x00 }, }; @@ -415,3 +422,68 @@ int dhcp_l3_socket(int port, const char *interface) 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; +}