summaryrefslogtreecommitdiff
path: root/gdhcp
diff options
context:
space:
mode:
authorMartin Xu <martin.xu@intel.com>2010-11-12 17:07:31 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2010-11-13 23:35:38 +0100
commit5dcabcf4a70d58a862990ba3235882c4e47ebcc4 (patch)
tree16d9240c1af02db72ac28fc9eb370d742302ebe8 /gdhcp
parent18151aa9ff937fe04abea3af39fbbe442565dc31 (diff)
downloadconnman-5dcabcf4a70d58a862990ba3235882c4e47ebcc4.tar.gz
connman-5dcabcf4a70d58a862990ba3235882c4e47ebcc4.tar.bz2
connman-5dcabcf4a70d58a862990ba3235882c4e47ebcc4.zip
gdhcp: Move get_interface_name and interface_is_up to common.c
This is needed for the dhcp server implementation.
Diffstat (limited to 'gdhcp')
-rw-r--r--gdhcp/client.c64
-rw-r--r--gdhcp/common.c69
-rw-r--r--gdhcp/common.h8
3 files changed, 76 insertions, 65 deletions
diff --git a/gdhcp/client.c b/gdhcp/client.c
index b9a0e7fc..e3ae0dbb 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -33,7 +33,6 @@
#include <netpacket/packet.h>
#include <net/ethernet.h>
-#include <net/if_arp.h>
#include <linux/if.h>
#include <linux/filter.h>
@@ -268,70 +267,7 @@ static int send_release(GDHCPClient *dhcp_client,
server, SERVER_PORT);
}
-static 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;
-}
-
-static 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);
-}
static void get_interface_mac_address(int index, uint8_t *mac_address)
{
diff --git a/gdhcp/common.c b/gdhcp/common.c
index fc95881e..00817af8 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -22,11 +22,15 @@
#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>
@@ -417,3 +421,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;
+}
diff --git a/gdhcp/common.h b/gdhcp/common.h
index 5b6fe581..3aab3d21 100644
--- a/gdhcp/common.h
+++ b/gdhcp/common.h
@@ -47,10 +47,14 @@ do { \
#define EXTEND_FOR_BUGGY_SERVERS 80
-static const uint8_t MAC_BCAST_ADDR[6] __attribute__((aligned(2))) = {
+static const uint8_t MAC_BCAST_ADDR[ETH_ALEN] __attribute__((aligned(2))) = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
+static const uint8_t MAC_ANY_ADDR[ETH_ALEN] __attribute__((aligned(2))) = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
/* DHCP packet */
#define DHCP_MAGIC 0x63825363
#define DHCP_OPTIONS_BUFSIZE 308
@@ -171,3 +175,5 @@ int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
uint32_t dest_ip, int dest_port);
int dhcp_l3_socket(int port, const char *interface);
int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd);
+char *get_interface_name(int index);
+gboolean interface_is_up(int index);