Massive cosmetic patch: update or add copyright headers, untabify, and

change all unsigned char to uint8_t.
This commit is contained in:
Nicholas J. Kain 2011-03-30 23:59:22 -04:00
parent 147e2d0fd9
commit a6fa236700
15 changed files with 300 additions and 83 deletions

View File

@ -1,13 +1,25 @@
/* arp.c - arp ping checking /* arp.c - arp ping checking
* Time-stamp: <2011-03-30 23:34:21 nk>
*
* Copyright 2010-2011 Nicholas J. Kain <njkain@gmail.com> * Copyright 2010-2011 Nicholas J. Kain <njkain@gmail.com>
* *
* Originally derived from busybox's udhcpc variant, which in turn was... * Originally derived from busybox's udhcpc variant, which in turn was...
* Mostly stolen from: dhcpcd - DHCP client daemon * Mostly stolen from: dhcpcd - DHCP client daemon
* by Yoichi Hariguchi <yoichi@fore.com> * by Yoichi Hariguchi <yoichi@fore.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or modify
* modify it under the terms of the GNU General Public License * it under the terms of the GNU General Public License as published by
* version 2 as published by the Free Software Foundation * 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 <unistd.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -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_ #ifndef ARPPING_H_
#define ARPPING_H_ #define ARPPING_H_

View File

@ -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. * (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
* * (c) 2001 Russ Dill <Russ.Dill@asu.edu>
* Nicholas J. Kain <njkain at gmail dot com> 2004-2010
* Russ Dill <Russ.Dill@asu.edu> July 2001
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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, add_option_string(packet->options, DHCP_OPTIONS_BUFSIZE,
client_config.hostname); client_config.hostname);
add_option_string(packet->options, DHCP_OPTIONS_BUFSIZE, 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. */ /* Wrapper that broadcasts a raw dhcp packet on the bound interface. */
static int bcast_raw_packet(struct dhcpMessage *packet) static int bcast_raw_packet(struct dhcpMessage *packet)
{ {

View File

@ -1,8 +1,29 @@
#ifndef CLIENTPACKET_H_ /* dhcpmsg.c - dhcp packet generation and sending functions
#define CLIENTPACKET_H_ * 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 <stdint.h>
#include "packet.h" // for struct dhcpMessage #include "packet.h"
#define DHCP_SERVER_PORT 67 #define DHCP_SERVER_PORT 67
#define DHCP_CLIENT_PORT 68 #define DHCP_CLIENT_PORT 68

View File

@ -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 * (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
*
* Nicholas J. Kain <njkain at gmail dot com> 2004-2010
* Russ Dill <Russ.Dill@asu.edu> July 2001
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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) if (client_config.clientid)
free(client_config.clientid); free(client_config.clientid);
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; break;
case 'f': case 'f':
client_config.foreground = 1; client_config.foreground = 1;
@ -321,7 +319,7 @@ int main(int argc, char **argv)
if (client_config.hostname) if (client_config.hostname)
free(client_config.hostname); free(client_config.hostname);
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; break;
case 'i': case 'i':
client_config.interface = optarg; client_config.interface = optarg;

View File

@ -1,11 +1,23 @@
/* /* netlink.c - netlink physical link notification handling and info retrieval
* Copyright 2011 Nicholas J. Kain <njkain@gmail.com>
* Copyright 2006, 2007 Stefan Rompf <sux@loplof.de>
* *
* This program is free software; you can redistribute it and/or * (c) 2011 Nicholas J. Kain <njkain at gmail dot com>
* modify it under the terms of the GNU General Public License * (c) 2006-2007 Stefan Rompf <sux@loplof.de>
* version 2 as published by the Free Software Foundation
* *
* 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> #include <arpa/inet.h>

View File

@ -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_ #ifndef NK_NETLINK_H_
#define NK_NETLINK_H_ #define NK_NETLINK_H_

View File

@ -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 <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -70,7 +91,7 @@ uint16_t checksum(void *addr, int count)
* hardware address */ * hardware address */
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int raw_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,
unsigned char *dest_arp, int ifindex) uint8_t *dest_arp, int ifindex)
{ {
struct sockaddr_ll dest; struct sockaddr_ll dest;
struct ip_udp_dhcp_packet packet; struct ip_udp_dhcp_packet packet;
@ -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, static void init_selecting_packet(struct client_state_t *cs,
struct dhcpMessage *packet, struct dhcpMessage *packet,
unsigned char *message) uint8_t *message)
{ {
unsigned char *temp = NULL; uint8_t *temp = NULL;
ssize_t optlen; ssize_t optlen;
/* Must be a DHCPOFFER to one of our xid's */ /* Must be a DHCPOFFER to one of our xid's */
if (*message == DHCPOFFER) { 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, static void dhcp_ack_or_nak_packet(struct client_state_t *cs,
struct dhcpMessage *packet, struct dhcpMessage *packet,
unsigned char *message) uint8_t *message)
{ {
unsigned char *temp = NULL; uint8_t *temp = NULL;
ssize_t optlen; ssize_t optlen;
if (*message == DHCPACK) { if (*message == DHCPACK) {
if (!(temp = get_option_data(packet, DHCP_LEASE_TIME, &optlen))) { 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) void handle_packet(struct client_state_t *cs)
{ {
unsigned char *message = NULL; uint8_t *message = NULL;
int len; int len;
struct dhcpMessage packet; struct dhcpMessage packet;
ssize_t optlen; ssize_t optlen;

View File

@ -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_ #ifndef PACKET_H_
#define PACKET_H_ #define PACKET_H_
@ -49,7 +70,7 @@ int get_packet(struct dhcpMessage *packet, int fd);
uint16_t checksum(void *addr, int count); uint16_t checksum(void *addr, int count);
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int raw_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,
unsigned char *dest_arp, int ifindex); uint8_t *dest_arp, int ifindex);
int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, 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);
void change_listen_mode(struct client_state_t *cs, int new_mode); void change_listen_mode(struct client_state_t *cs, int new_mode);

View File

@ -1,10 +1,8 @@
/* /* socket.c - raw and kernel socket creation functions
* socket.c -- DHCP server client/server socket creation * Time-stamp: <2011-03-30 23:47:03 nk>
* *
* Copyright (C) 2004-2010 Nicholas J. Kain <njkain at gmail dot com> * (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 * Kernel BPF filter is (c) 2006, 2007 Stefan Rompf <sux@loplof.de>.
* Copyright (C) 1999 Matthew Ramsay <matthewr@moreton.com.au>
* Chris Trew <ctrew@moreton.com.au>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -94,20 +92,12 @@ int raw_socket(int ifindex)
/* /*
* Comment: * Comment:
*
* I've selected not to see LL header, so BPF doesn't see it, too. * 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 * The filter may also pass non-IP and non-ARP packets, but we do
* a more complete check when receiving the message in userspace. * a more complete check when receiving the message in userspace.
*
* and filter shamelessly stolen from: * and filter shamelessly stolen from:
*
* http://www.flamewarmaster.de/software/dhcpclient/ * 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>. * Copyright: 2006, 2007 Stefan Rompf <sux@loplof.de>.
* License: GPL v2. * License: GPL v2.
*/ */

View File

@ -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_ #ifndef SOCKET_H_
#define SOCKET_H_ #define SOCKET_H_

View File

@ -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 <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -72,4 +92,3 @@ void epoll_del(struct client_state_t *cs, int fd)
if (r == -1) if (r == -1)
suicide("epoll_del failed %s", strerror(errno)); suicide("epoll_del failed %s", strerror(errno));
} }

View File

@ -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_ #ifndef SYS_H_
#define SYS_H_ #define SYS_H_

View File

@ -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 <unistd.h>
#include <stdlib.h> #include <stdlib.h>
@ -9,7 +29,6 @@
#include "arp.h" #include "arp.h"
#include "log.h" #include "log.h"
#define DELAY_SEC (((RETRY_DELAY - (RETRY_DELAY / NUMPACKETS)) / NUMPACKETS) + 1) #define DELAY_SEC (((RETRY_DELAY - (RETRY_DELAY / NUMPACKETS)) / NUMPACKETS) + 1)
static void init_selecting_timeout(struct client_state_t *cs) static void init_selecting_timeout(struct client_state_t *cs)
{ {

View File

@ -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_ #ifndef TIMEOUT_H_
#define TIMEOUT_H_ #define TIMEOUT_H_