summaryrefslogtreecommitdiff
path: root/gdhcp/common.c
diff options
context:
space:
mode:
authorZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 10:37:39 +0800
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 10:37:39 +0800
commit1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch)
tree6e991827d28537f7f40f20786c2354fd04a9fdad /gdhcp/common.c
parentfbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff)
downloadconnman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.gz
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.bz2
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.zip
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'gdhcp/common.c')
-rw-r--r--gdhcp/common.c70
1 files changed, 24 insertions, 46 deletions
diff --git a/gdhcp/common.c b/gdhcp/common.c
index 0c433ddc..e1111505 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -1,7 +1,7 @@
/*
* DHCP library with GLib integration
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -170,12 +170,9 @@ uint8_t *dhcpv6_get_option(struct dhcpv6_packet *packet, uint16_t pkt_len,
break;
if (opt_code == code) {
- if (option_len != NULL)
+ if (option_len)
*option_len = opt_len;
- if (rem < 0)
- goto bad_packet;
- else
- found = optionptr + 2 + 2;
+ found = optionptr + 2 + 2;
count++;
}
@@ -185,15 +182,15 @@ uint8_t *dhcpv6_get_option(struct dhcpv6_packet *packet, uint16_t pkt_len,
optionptr += len;
}
- if (option_count != NULL)
+ if (option_count)
*option_count = count;
return found;
bad_packet:
- if (option_len != NULL)
+ if (option_len)
*option_len = 0;
- if (option_count != NULL)
+ if (option_count)
*option_count = 0;
return NULL;
}
@@ -371,34 +368,6 @@ void dhcpv6_init_header(struct dhcpv6_packet *packet, uint8_t type)
packet->transaction_id[2] = id & 0xff;
}
-static gboolean check_vendor(uint8_t *option_vendor, const char *vendor)
-{
- uint8_t vendor_length = sizeof(vendor) - 1;
-
- if (option_vendor[OPT_LEN - OPT_DATA] != vendor_length)
- return FALSE;
-
- if (memcmp(option_vendor, vendor, vendor_length) != 0)
- return FALSE;
-
- return TRUE;
-}
-
-static void check_broken_vendor(struct dhcp_packet *packet)
-{
- uint8_t *vendor;
-
- if (packet->op != BOOTREQUEST)
- return;
-
- vendor = dhcp_get_option(packet, DHCP_VENDOR);
- if (vendor == NULL)
- return;
-
- if (check_vendor(vendor, "MSFT 98") == TRUE)
- packet->flags |= htons(BROADCAST_FLAG);
-}
-
int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd)
{
int n;
@@ -412,8 +381,6 @@ int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd)
if (packet->cookie != htonl(DHCP_MAGIC))
return -EPROTO;
- check_broken_vendor(packet);
-
return n;
}
@@ -496,7 +463,7 @@ int dhcpv6_send_packet(int index, struct dhcpv6_packet *dhcp_pkt, int len)
control_buf_len = CMSG_SPACE(sizeof(struct in6_pktinfo));
control_buf = g_try_malloc0(control_buf_len);
- if (control_buf == NULL) {
+ if (!control_buf) {
close(fd);
return -ENOMEM;
}
@@ -525,8 +492,17 @@ int dhcpv6_send_packet(int index, struct dhcpv6_packet *dhcp_pkt, int len)
m.msg_controllen = cmsg->cmsg_len;
ret = sendmsg(fd, &m, 0);
- if (ret < 0)
- perror("DHCPv6 msg send failed");
+ if (ret < 0) {
+ char *msg = "DHCPv6 msg send failed";
+
+ if (errno == EADDRNOTAVAIL) {
+ char *str = g_strdup_printf("%s (index %d)",
+ msg, index);
+ perror(str);
+ g_free(str);
+ } else
+ perror(msg);
+ }
g_free(control_buf);
close(fd);
@@ -553,6 +529,8 @@ int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
if (fd < 0)
return -errno;
+ dhcp_pkt->flags |= htons(BROADCAST_FLAG);
+
memset(&dest, 0, sizeof(dest));
memset(&packet, 0, sizeof(packet));
packet.data = *dhcp_pkt;
@@ -718,16 +696,16 @@ char *get_interface_name(int index)
return g_strdup(ifr.ifr_name);
}
-gboolean interface_is_up(int index)
+bool interface_is_up(int index)
{
int sk, err;
struct ifreq ifr;
- gboolean ret = FALSE;
+ bool ret = false;
sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sk < 0) {
perror("Open socket error");
- return FALSE;
+ return false;
}
memset(&ifr, 0, sizeof(ifr));
@@ -746,7 +724,7 @@ gboolean interface_is_up(int index)
}
if (ifr.ifr_flags & IFF_UP)
- ret = TRUE;
+ ret = true;
done:
close(sk);