Massive cosmetic patch: update or add copyright headers, untabify, and
change all unsigned char to uint8_t.
This commit is contained in:
parent
147e2d0fd9
commit
a6fa236700
18
ndhc/arp.c
18
ndhc/arp.c
@ -1,13 +1,25 @@
|
||||
/* arp.c - arp ping checking
|
||||
* Time-stamp: <2011-03-30 23:34:21 nk>
|
||||
*
|
||||
* Copyright 2010-2011 Nicholas J. Kain <njkain@gmail.com>
|
||||
*
|
||||
* Originally derived from busybox's udhcpc variant, which in turn was...
|
||||
* Mostly stolen from: dhcpcd - DHCP client daemon
|
||||
* by Yoichi Hariguchi <yoichi@fore.com>
|
||||
*
|
||||
* 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 published by the Free Software Foundation
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
23
ndhc/arp.h
23
ndhc/arp.h
@ -1,3 +1,26 @@
|
||||
/* arp.h - functions to call the interface change daemon
|
||||
* Time-stamp: <2011-03-30 23:36:45 nk>
|
||||
*
|
||||
* Copyright 2010-2011 Nicholas J. Kain <njkain@gmail.com>
|
||||
*
|
||||
* Originally derived from busybox's udhcpc variant, which in turn was...
|
||||
* Mostly stolen from: dhcpcd - DHCP client daemon
|
||||
* by Yoichi Hariguchi <yoichi@fore.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef ARPPING_H_
|
||||
#define ARPPING_H_
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
/* dhcpmsg.c
|
||||
/* dhcpmsg.c - dhcp packet generation and sending functions
|
||||
* Time-stamp: <2011-03-30 23:57:43 nk>
|
||||
*
|
||||
* Packet generation and dispatching functions for the DHCP client.
|
||||
*
|
||||
* Nicholas J. Kain <njkain at gmail dot com> 2004-2010
|
||||
* Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* (c) 2001 Russ Dill <Russ.Dill@asu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -100,10 +99,10 @@ static void init_packet(struct dhcpMessage *packet, char type)
|
||||
add_option_string(packet->options, DHCP_OPTIONS_BUFSIZE,
|
||||
client_config.hostname);
|
||||
add_option_string(packet->options, DHCP_OPTIONS_BUFSIZE,
|
||||
(unsigned char *)&vendor_id);
|
||||
(uint8_t *)&vendor_id);
|
||||
}
|
||||
|
||||
#define MAC_BCAST_ADDR (unsigned char *) "\xff\xff\xff\xff\xff\xff"
|
||||
#define MAC_BCAST_ADDR (uint8_t *)"\xff\xff\xff\xff\xff\xff"
|
||||
/* Wrapper that broadcasts a raw dhcp packet on the bound interface. */
|
||||
static int bcast_raw_packet(struct dhcpMessage *packet)
|
||||
{
|
||||
|
@ -1,8 +1,29 @@
|
||||
#ifndef CLIENTPACKET_H_
|
||||
#define CLIENTPACKET_H_
|
||||
/* dhcpmsg.c - dhcp packet generation and sending functions
|
||||
* Time-stamp: <2011-03-30 23:53:52 nk>
|
||||
*
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* (c) 2001 Russ Dill <Russ.Dill@asu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef DHCPMSG_H_
|
||||
#define DHCPMSG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "packet.h" // for struct dhcpMessage
|
||||
#include "packet.h"
|
||||
|
||||
#define DHCP_SERVER_PORT 67
|
||||
#define DHCP_CLIENT_PORT 68
|
||||
@ -10,13 +31,13 @@
|
||||
|
||||
enum {
|
||||
DHCPDISCOVER = 1,
|
||||
DHCPOFFER = 2,
|
||||
DHCPREQUEST = 3,
|
||||
DHCPDECLINE = 4,
|
||||
DHCPACK = 5,
|
||||
DHCPNAK = 6,
|
||||
DHCPRELEASE = 7,
|
||||
DHCPINFORM = 8
|
||||
DHCPOFFER = 2,
|
||||
DHCPREQUEST = 3,
|
||||
DHCPDECLINE = 4,
|
||||
DHCPACK = 5,
|
||||
DHCPNAK = 6,
|
||||
DHCPRELEASE = 7,
|
||||
DHCPINFORM = 8
|
||||
};
|
||||
|
||||
uint32_t random_xid(void);
|
||||
|
12
ndhc/ndhc.c
12
ndhc/ndhc.c
@ -1,9 +1,7 @@
|
||||
/* ndhc.c
|
||||
/* ndhc.c - DHCP client
|
||||
* Time-stamp: <2011-03-30 23:58:05 nk>
|
||||
*
|
||||
* ndhc DHCP client, originally based on udhcpc
|
||||
*
|
||||
* Nicholas J. Kain <njkain at gmail dot com> 2004-2010
|
||||
* Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -302,7 +300,7 @@ int main(int argc, char **argv)
|
||||
if (client_config.clientid)
|
||||
free(client_config.clientid);
|
||||
client_config.clientid =
|
||||
alloc_dhcp_client_id_option(0, (unsigned char *)optarg, len);
|
||||
alloc_dhcp_client_id_option(0, (uint8_t *)optarg, len);
|
||||
break;
|
||||
case 'f':
|
||||
client_config.foreground = 1;
|
||||
@ -321,7 +319,7 @@ int main(int argc, char **argv)
|
||||
if (client_config.hostname)
|
||||
free(client_config.hostname);
|
||||
client_config.hostname =
|
||||
alloc_option(DHCP_HOST_NAME, (unsigned char *)optarg, len);
|
||||
alloc_option(DHCP_HOST_NAME, (uint8_t *)optarg, len);
|
||||
break;
|
||||
case 'i':
|
||||
client_config.interface = optarg;
|
||||
|
@ -1,11 +1,23 @@
|
||||
/*
|
||||
* Copyright 2011 Nicholas J. Kain <njkain@gmail.com>
|
||||
* Copyright 2006, 2007 Stefan Rompf <sux@loplof.de>
|
||||
/* netlink.c - netlink physical link notification handling and info retrieval
|
||||
*
|
||||
* 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 published by the Free Software Foundation
|
||||
* (c) 2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* (c) 2006-2007 Stefan Rompf <sux@loplof.de>
|
||||
*
|
||||
* This code was largely taken from Stefan Rompf's dhcpclient.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
@ -1,3 +1,25 @@
|
||||
/* netlink.h - netlink physical link notification handling and info retrieval
|
||||
*
|
||||
* (c) 2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* (c) 2006-2007 Stefan Rompf <sux@loplof.de>
|
||||
*
|
||||
* This code was largely taken from Stefan Rompf's dhcpclient.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef NK_NETLINK_H_
|
||||
#define NK_NETLINK_H_
|
||||
|
||||
|
@ -1,3 +1,24 @@
|
||||
/* packet.c - send and react to DHCP message packets
|
||||
* Time-stamp: <2011-03-30 23:57:14 nk>
|
||||
*
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* (c) 2001 Russ Dill <Russ.Dill@asu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
@ -27,13 +48,13 @@ int get_packet(struct dhcpMessage *packet, int fd)
|
||||
memset(packet, 0, DHCP_SIZE);
|
||||
bytes = safe_read(fd, (char *)packet, DHCP_SIZE);
|
||||
if (bytes == -1) {
|
||||
log_line("Read on listen socket failed: %s", strerror(errno));
|
||||
return -1;
|
||||
log_line("Read on listen socket failed: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ntohl(packet->cookie) != DHCP_MAGIC) {
|
||||
log_error("Packet with bad magic number, ignoring.");
|
||||
return -2;
|
||||
log_error("Packet with bad magic number, ignoring.");
|
||||
return -2;
|
||||
}
|
||||
log_line("Received a packet");
|
||||
|
||||
@ -47,21 +68,21 @@ uint16_t checksum(void *addr, int count)
|
||||
uint16_t *source = (uint16_t *)addr;
|
||||
|
||||
while (count > 1) {
|
||||
sum += *source++;
|
||||
count -= 2;
|
||||
sum += *source++;
|
||||
count -= 2;
|
||||
}
|
||||
|
||||
/* Add left-over byte, if any */
|
||||
if (count > 0) {
|
||||
/* Make sure that the left-over byte is added correctly both
|
||||
* with little and big endian hosts */
|
||||
uint16_t tmp = 0;
|
||||
*(uint8_t *)&tmp = *(uint8_t *)source;
|
||||
sum += tmp;
|
||||
/* Make sure that the left-over byte is added correctly both
|
||||
* with little and big endian hosts */
|
||||
uint16_t tmp = 0;
|
||||
*(uint8_t *)&tmp = *(uint8_t *)source;
|
||||
sum += tmp;
|
||||
}
|
||||
/* Fold 32-bit sum to 16 bits */
|
||||
while (sum >> 16)
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
|
||||
return ~sum;
|
||||
}
|
||||
@ -70,7 +91,7 @@ uint16_t checksum(void *addr, int count)
|
||||
* hardware address */
|
||||
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
int source_port, uint32_t dest_ip, int dest_port,
|
||||
unsigned char *dest_arp, int ifindex)
|
||||
uint8_t *dest_arp, int ifindex)
|
||||
{
|
||||
struct sockaddr_ll dest;
|
||||
struct ip_udp_dhcp_packet packet;
|
||||
@ -78,8 +99,8 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
unsigned int padding;
|
||||
|
||||
if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
|
||||
log_error("raw_packet: socket failed: %s", strerror(errno));
|
||||
goto out;
|
||||
log_error("raw_packet: socket failed: %s", strerror(errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
memset(&dest, 0, sizeof dest);
|
||||
@ -92,8 +113,8 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
dest.sll_halen = 6;
|
||||
memcpy(dest.sll_addr, dest_arp, 6);
|
||||
if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) < 0) {
|
||||
log_error("raw_packet: bind failed: %s", strerror(errno));
|
||||
goto out_fd;
|
||||
log_error("raw_packet: bind failed: %s", strerror(errno));
|
||||
goto out_fd;
|
||||
}
|
||||
|
||||
/* We were sending full-sized DHCP packets (zero padded),
|
||||
@ -131,9 +152,9 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
packet.ip.check = checksum(&packet.ip, sizeof packet.ip);
|
||||
|
||||
r = safe_sendto(fd, (const char *)&packet, IP_UPD_DHCP_SIZE - padding,
|
||||
0, (struct sockaddr *)&dest, sizeof dest);
|
||||
0, (struct sockaddr *)&dest, sizeof dest);
|
||||
if (r == -1)
|
||||
log_error("raw_packet: sendto failed: %s", strerror(errno));
|
||||
log_error("raw_packet: sendto failed: %s", strerror(errno));
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
@ -142,17 +163,17 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
|
||||
/* Let the kernel do all the work for packet generation */
|
||||
int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
int source_port, uint32_t dest_ip, int dest_port)
|
||||
int source_port, uint32_t dest_ip, int dest_port)
|
||||
{
|
||||
struct sockaddr_in client;
|
||||
int opt = 1, fd, result = -1;
|
||||
unsigned int padding;
|
||||
|
||||
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
|
||||
goto out;
|
||||
goto out;
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) == -1)
|
||||
goto out_fd;
|
||||
goto out_fd;
|
||||
|
||||
memset(&client, 0, sizeof(client));
|
||||
client.sin_family = AF_INET;
|
||||
@ -160,7 +181,7 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
client.sin_addr.s_addr = source_ip;
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1)
|
||||
goto out_fd;
|
||||
goto out_fd;
|
||||
|
||||
memset(&client, 0, sizeof(client));
|
||||
client.sin_family = AF_INET;
|
||||
@ -168,7 +189,7 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
client.sin_addr.s_addr = dest_ip;
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1)
|
||||
goto out_fd;
|
||||
goto out_fd;
|
||||
|
||||
ssize_t endloc = get_end_option_idx(payload->options,
|
||||
DHCP_OPTIONS_BUFSIZE);
|
||||
@ -179,7 +200,7 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
padding = DHCP_OPTIONS_BUFSIZE - 1 - endloc;
|
||||
result = safe_write(fd, (const char *)payload, DHCP_SIZE - padding);
|
||||
if (result == -1)
|
||||
log_error("kernel_packet: write failed: %s", strerror(errno));
|
||||
log_error("kernel_packet: write failed: %s", strerror(errno));
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
@ -216,9 +237,9 @@ void change_listen_mode(struct client_state_t *cs, int new_mode)
|
||||
|
||||
static void init_selecting_packet(struct client_state_t *cs,
|
||||
struct dhcpMessage *packet,
|
||||
unsigned char *message)
|
||||
uint8_t *message)
|
||||
{
|
||||
unsigned char *temp = NULL;
|
||||
uint8_t *temp = NULL;
|
||||
ssize_t optlen;
|
||||
/* Must be a DHCPOFFER to one of our xid's */
|
||||
if (*message == DHCPOFFER) {
|
||||
@ -240,9 +261,9 @@ static void init_selecting_packet(struct client_state_t *cs,
|
||||
|
||||
static void dhcp_ack_or_nak_packet(struct client_state_t *cs,
|
||||
struct dhcpMessage *packet,
|
||||
unsigned char *message)
|
||||
uint8_t *message)
|
||||
{
|
||||
unsigned char *temp = NULL;
|
||||
uint8_t *temp = NULL;
|
||||
ssize_t optlen;
|
||||
if (*message == DHCPACK) {
|
||||
if (!(temp = get_option_data(packet, DHCP_LEASE_TIME, &optlen))) {
|
||||
@ -279,7 +300,7 @@ static void dhcp_ack_or_nak_packet(struct client_state_t *cs,
|
||||
|
||||
void handle_packet(struct client_state_t *cs)
|
||||
{
|
||||
unsigned char *message = NULL;
|
||||
uint8_t *message = NULL;
|
||||
int len;
|
||||
struct dhcpMessage packet;
|
||||
ssize_t optlen;
|
||||
|
@ -1,3 +1,24 @@
|
||||
/* packet.h - send and react to DHCP message packets
|
||||
* Time-stamp: <2011-03-30 23:57:02 nk>
|
||||
*
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* (c) 2001 Russ Dill <Russ.Dill@asu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef PACKET_H_
|
||||
#define PACKET_H_
|
||||
|
||||
@ -40,16 +61,16 @@ struct udp_dhcp_packet {
|
||||
};
|
||||
|
||||
enum {
|
||||
IP_UPD_DHCP_SIZE = sizeof(struct ip_udp_dhcp_packet),
|
||||
UPD_DHCP_SIZE = sizeof(struct udp_dhcp_packet),
|
||||
DHCP_SIZE = sizeof(struct dhcpMessage),
|
||||
IP_UPD_DHCP_SIZE = sizeof(struct ip_udp_dhcp_packet),
|
||||
UPD_DHCP_SIZE = sizeof(struct udp_dhcp_packet),
|
||||
DHCP_SIZE = sizeof(struct dhcpMessage),
|
||||
};
|
||||
|
||||
int get_packet(struct dhcpMessage *packet, int fd);
|
||||
uint16_t checksum(void *addr, int count);
|
||||
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
int source_port, uint32_t dest_ip, int dest_port,
|
||||
unsigned char *dest_arp, int ifindex);
|
||||
uint8_t *dest_arp, int ifindex);
|
||||
int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
int source_port, uint32_t dest_ip, int dest_port);
|
||||
void change_listen_mode(struct client_state_t *cs, int new_mode);
|
||||
|
@ -1,10 +1,8 @@
|
||||
/*
|
||||
* socket.c -- DHCP server client/server socket creation
|
||||
/* socket.c - raw and kernel socket creation functions
|
||||
* Time-stamp: <2011-03-30 23:47:03 nk>
|
||||
*
|
||||
* Copyright (C) 2004-2010 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
* Copyright (C) 1999 Matthew Ramsay <matthewr@moreton.com.au>
|
||||
* Chris Trew <ctrew@moreton.com.au>
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
* Kernel BPF filter is (c) 2006, 2007 Stefan Rompf <sux@loplof.de>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -94,20 +92,12 @@ int raw_socket(int ifindex)
|
||||
|
||||
/*
|
||||
* Comment:
|
||||
*
|
||||
* I've selected not to see LL header, so BPF doesn't see it, too.
|
||||
* The filter may also pass non-IP and non-ARP packets, but we do
|
||||
* a more complete check when receiving the message in userspace.
|
||||
*
|
||||
* and filter shamelessly stolen from:
|
||||
*
|
||||
* http://www.flamewarmaster.de/software/dhcpclient/
|
||||
*
|
||||
* There are a few other interesting ideas on that page (look under
|
||||
* "Motivation"). Use of netlink events is most interesting. Think
|
||||
* of various network servers listening for events and reconfiguring.
|
||||
* That would obsolete sending HUP signals and/or make use of restarts.
|
||||
*
|
||||
* Copyright: 2006, 2007 Stefan Rompf <sux@loplof.de>.
|
||||
* License: GPL v2.
|
||||
*/
|
||||
|
@ -1,3 +1,23 @@
|
||||
/* socket.h - raw and kernel socket creation functions
|
||||
* Time-stamp: <2011-03-30 23:47:34 nk>
|
||||
*
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef SOCKET_H_
|
||||
#define SOCKET_H_
|
||||
|
||||
|
21
ndhc/sys.c
21
ndhc/sys.c
@ -1,3 +1,23 @@
|
||||
/* sys.c - linux-specific signal and epoll functions
|
||||
* Time-stamp: <2011-03-30 23:40:33 nk>
|
||||
*
|
||||
* (c) 2010-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -72,4 +92,3 @@ void epoll_del(struct client_state_t *cs, int fd)
|
||||
if (r == -1)
|
||||
suicide("epoll_del failed %s", strerror(errno));
|
||||
}
|
||||
|
||||
|
20
ndhc/sys.h
20
ndhc/sys.h
@ -1,3 +1,23 @@
|
||||
/* sys.h - linux-specific signal and epoll functions
|
||||
* Time-stamp: <2011-03-30 23:41:04 nk>
|
||||
*
|
||||
* (c) 2010-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef SYS_H_
|
||||
#define SYS_H_
|
||||
|
||||
|
@ -1,3 +1,23 @@
|
||||
/* timeout.c - callbacks to react to event timeouts
|
||||
* Time-stamp: <2011-03-30 23:42:13 nk>
|
||||
*
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -9,7 +29,6 @@
|
||||
#include "arp.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
#define DELAY_SEC (((RETRY_DELAY - (RETRY_DELAY / NUMPACKETS)) / NUMPACKETS) + 1)
|
||||
static void init_selecting_timeout(struct client_state_t *cs)
|
||||
{
|
||||
|
@ -1,3 +1,23 @@
|
||||
/* timeout.h - callbacks to react to event timeouts
|
||||
* Time-stamp: <2011-03-30 23:42:25 nk>
|
||||
*
|
||||
* (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef TIMEOUT_H_
|
||||
#define TIMEOUT_H_
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user