1
0
Fork 0
mirror of https://github.com/albfan/miraclecast.git synced 2025-03-09 23:38:56 +00:00

dhcp: sync with gdhcp

Copy over recent changes to gdhcp from ConnMan. We should really start
exporting sd-dhcp from libsystemd so we can finally drop this alltogether.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
David Herrmann 2014-08-13 08:45:15 +02:00
parent eecf576fa9
commit 7c87510b34
4 changed files with 209 additions and 187 deletions

View file

@ -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
@ -34,8 +34,8 @@
#include <linux/if.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "gdhcp.h"
#include "common.h"
@ -173,10 +173,7 @@ uint8_t *dhcpv6_get_option(struct dhcpv6_packet *packet, uint16_t pkt_len,
if (opt_code == code) {
if (option_len)
*option_len = opt_len;
if (rem < 0)
goto bad_packet;
else
found = optionptr + 2 + 2;
found = optionptr + 2 + 2;
count++;
}
@ -372,34 +369,6 @@ void dhcpv6_init_header(struct dhcpv6_packet *packet, uint8_t type)
packet->transaction_id[2] = id & 0xff;
}
static bool 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)
return;
if (check_vendor(vendor, "MSFT 98"))
packet->flags |= htons(BROADCAST_FLAG);
}
int dhcp_recv_l3_packet(struct dhcp_packet *packet, int fd)
{
int n;
@ -413,8 +382,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;
}
@ -557,6 +524,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;