Whitespace and indentation normalization.

This commit is contained in:
Nicholas J. Kain
2010-11-12 14:33:17 -05:00
parent 2262845be6
commit f4a00f3826
10 changed files with 1183 additions and 1198 deletions

5
README
View File

@@ -10,10 +10,7 @@ C99-compliant C compiler (for C99 struct subobject init)
CMake (tested: 2.8) CMake (tested: 2.8)
Tested with glibc 2.2.x and 2.3.x. dietlibc is not compatible. I have not yet Tested with glibc. dietlibc is not compatible. I have not tested uclibc.
tested uclibc.
I may bother to port to other operating systems, but don't count on it.
INTRODUCTION INTRODUCTION
------------ ------------

View File

@@ -1,7 +1,7 @@
/* ifchd.c - interface change daemon /* ifchd.c - interface change daemon
* Time-stamp: <2010-11-12 12:04:25 njk> * Time-stamp: <2010-11-12 14:27:47 njk>
* *
* (C) 2004 Nicholas J. Kain <njk@aerifal.cx> * (C) 2004-2010 Nicholas J. Kain <njkain at gmail dot com>
* *
* 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
@@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/ */
#include <unistd.h> #include <unistd.h>
@@ -654,7 +653,7 @@ static void dispatch_work(void)
idle_time[i] = time(NULL); idle_time[i] = time(NULL);
memset(buf, '\0', sizeof(buf)); memset(buf, '\0', sizeof(buf));
dispatch_work_read_again: read_again:
ret = (int) read(sks[i], buf, MAX_BUF / 2 - 1); ret = (int) read(sks[i], buf, MAX_BUF / 2 - 1);
/* Check to see if peer closed socket */ /* Check to see if peer closed socket */
@@ -666,7 +665,7 @@ dispatch_work_read_again:
if (ret == -1) { if (ret == -1) {
if (errno == EINTR) if (errno == EINTR)
goto dispatch_work_read_again; goto read_again;
log_line("dispatch_work: read returned %s.\n", strerror(errno)); log_line("dispatch_work: read returned %s.\n", strerror(errno));
close(sks[i]); close(sks[i]);
new_sk(i, -1); new_sk(i, -1);
@@ -747,7 +746,7 @@ int main(int argc, char** argv) {
printf( printf(
"ifchd %s, if change daemon. Licensed under GNU GPL.\n", IFCHD_VERSION); "ifchd %s, if change daemon. Licensed under GNU GPL.\n", IFCHD_VERSION);
printf( printf(
"Copyright (C) 2004 Nicholas J. Kain\n" "Copyright (C) 2004-2010 Nicholas J. Kain\n"
"Usage: ifchd [OPTIONS]\n" "Usage: ifchd [OPTIONS]\n"
" -d, --detach detach from TTY and daemonize\n" " -d, --detach detach from TTY and daemonize\n"
" -n, --nodetach stay attached to TTY\n" " -n, --nodetach stay attached to TTY\n"
@@ -772,7 +771,7 @@ int main(int argc, char** argv) {
printf( printf(
"ifchd %s, if change daemon. Licensed under GNU GPL.\n", IFCHD_VERSION); "ifchd %s, if change daemon. Licensed under GNU GPL.\n", IFCHD_VERSION);
printf( printf(
"Copyright (C) 2004 Nicholas J. Kain\n" "Copyright (C) 2004-2010 Nicholas J. Kain\n"
"This is free software; see the source for copying conditions. There is NO\n" "This is free software; see the source for copying conditions. There is NO\n"
"WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); "WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@@ -1,7 +1,7 @@
/* linux.c - ifchd Linux-specific functions /* linux.c - ifchd Linux-specific functions
* Time-stamp: <2010-11-12 08:45:42 njk> * Time-stamp: <2010-11-12 14:29:32 njk>
* *
* (C) 2004 Nicholas J. Kain <njk@aerifal.cx> * (C) 2004-2010 Nicholas J. Kain <njkain at gmail dot com>
* *
* 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
@@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/ */
#include <unistd.h> #include <unistd.h>

View File

@@ -1,7 +1,7 @@
/* linux.h - ifchd Linux-specific functions include /* linux.h - ifchd Linux-specific functions include
* Time-stamp: <2010-11-12 09:03:29 njk> * Time-stamp: <2010-11-12 14:31:33 njk>
* *
* (C) 2004 Nicholas J. Kain <njk@aerifal.cx> * (C) 2004-2010 Nicholas J. Kain <njkain at gmail dot com>
* *
* 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
@@ -16,11 +16,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/ */
#ifndef NJK_IFCHD_LINUX_H_ #ifndef NJK_IFCHD_LINUX_H_
#define NJK_IFCHD_LINUX_H_ 1 #define NJK_IFCHD_LINUX_H_
void clear_if_data(int idx); void clear_if_data(int idx);
void initialize_if_data(void); void initialize_if_data(void);
void add_permitted_if(char *s); void add_permitted_if(char *s);

View File

@@ -2,6 +2,7 @@
* *
* Packet generation and dispatching functions for the DHCP client. * 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 * 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
@@ -62,7 +63,6 @@ unsigned long random_xid(void)
return rand(); return rand();
} }
/* initialize a packet with the proper defaults */ /* initialize a packet with the proper defaults */
static void init_packet(struct dhcpMessage *packet, char type) static void init_packet(struct dhcpMessage *packet, char type)
{ {
@@ -80,7 +80,6 @@ static void init_packet(struct dhcpMessage *packet, char type)
add_option_string(packet->options, (unsigned char *)&vendor_id); add_option_string(packet->options, (unsigned char *)&vendor_id);
} }
/* Add a paramater request list for stubborn DHCP servers. Pull the data /* Add a paramater request list for stubborn DHCP servers. Pull the data
* from the struct in options.c. Don't do bounds checking here because it * from the struct in options.c. Don't do bounds checking here because it
* goes towards the head of the packet. */ * goes towards the head of the packet. */
@@ -95,10 +94,8 @@ static void add_requests(struct dhcpMessage *packet)
packet->options[end + OPT_DATA + len++] = options[i].code; packet->options[end + OPT_DATA + len++] = options[i].code;
packet->options[end + OPT_LEN] = len; packet->options[end + OPT_LEN] = len;
packet->options[end + OPT_DATA + len] = DHCP_END; packet->options[end + OPT_DATA + len] = DHCP_END;
} }
/* Broadcast a DHCP discover packet to the network, with an optionally /* Broadcast a DHCP discover packet to the network, with an optionally
* requested IP */ * requested IP */
int send_discover(unsigned long xid, unsigned long requested) int send_discover(unsigned long xid, unsigned long requested)
@@ -116,7 +113,6 @@ int send_discover(unsigned long xid, unsigned long requested)
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
} }
/* Broadcasts a DHCP request message */ /* Broadcasts a DHCP request message */
int send_selecting(unsigned long xid, unsigned long server, int send_selecting(unsigned long xid, unsigned long server,
unsigned long requested) unsigned long requested)
@@ -137,7 +133,6 @@ int send_selecting(unsigned long xid, unsigned long server,
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
} }
/* Unicasts or broadcasts a DHCP renew message */ /* Unicasts or broadcasts a DHCP renew message */
int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
{ {
@@ -158,7 +153,6 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
return ret; return ret;
} }
/* Unicasts a DHCP release message */ /* Unicasts a DHCP release message */
int send_release(unsigned long server, unsigned long ciaddr) int send_release(unsigned long server, unsigned long ciaddr)
{ {
@@ -175,7 +169,6 @@ int send_release(unsigned long server, unsigned long ciaddr)
return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
} }
/* return -1 on errors that are fatal for the socket, /* return -1 on errors that are fatal for the socket,
* -2 for those that aren't */ * -2 for those that aren't */
int get_raw_packet(struct dhcpMessage *payload, int fd) int get_raw_packet(struct dhcpMessage *payload, int fd)
@@ -293,6 +286,4 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
} }
log_line("oooooh!!! got some!"); log_line("oooooh!!! got some!");
return len - (sizeof(packet.ip) + sizeof(packet.udp)); return len - (sizeof(packet.ip) + sizeof(packet.udp));
} }

View File

@@ -2,8 +2,8 @@
* *
* ndhc DHCP client * ndhc DHCP client
* *
* Nicholas J. Kain <njkain at gmail dot com> 2004-2010
* Russ Dill <Russ.Dill@asu.edu> July 2001 * Russ Dill <Russ.Dill@asu.edu> July 2001
* Nicholas Kain <njk@-N0SPaM-.kain.us> 2004
* *
* 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
@@ -588,4 +588,3 @@ int main(int argc, char **argv)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@@ -1,7 +1,7 @@
/* /*
* options.c -- DHCP server option packet tools * options.c -- DHCP server option packet tools
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
* Fixes and hardening: Nicholas Kain <njk@-n0xZpam-.kain.us> * Fixes and hardening: Nicholas J. Kain <njkain at gmail dot com>
*/ */
#include <stdio.h> #include <stdio.h>

View File

@@ -13,7 +13,6 @@
#include "dhcpd.h" #include "dhcpd.h"
#include "options.h" #include "options.h"
void init_header(struct dhcpMessage *packet, char type) void init_header(struct dhcpMessage *packet, char type)
{ {
memset(packet, 0, sizeof(struct dhcpMessage)); memset(packet, 0, sizeof(struct dhcpMessage));
@@ -36,7 +35,6 @@ void init_header(struct dhcpMessage *packet, char type)
add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type); add_simple_option(packet->options, DHCP_MESSAGE_TYPE, type);
} }
/* read a packet from socket fd, return -1 on read error, -2 on packet error */ /* read a packet from socket fd, return -1 on read error, -2 on packet error */
int get_packet(struct dhcpMessage *packet, int fd) int get_packet(struct dhcpMessage *packet, int fd)
{ {
@@ -106,7 +104,6 @@ uint16_t checksum(void *addr, int count)
return ~sum; return ~sum;
} }
/* Constuct a ip/udp header for a packet, and specify the source and dest /* Constuct a ip/udp header for a packet, and specify the source and dest
* hardware address */ * hardware address */
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
@@ -164,7 +161,6 @@ out:
return result; return result;
} }
/* Let the kernel do all the work for packet generation */ /* Let the kernel do all the work for packet generation */
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)
@@ -200,4 +196,3 @@ out_fd:
out: out:
return result; return result;
} }

View File

@@ -3,7 +3,7 @@
* Functions to call the interface change daemon * Functions to call the interface change daemon
* *
* Russ Dill <Russ.Dill@asu.edu> July 2001 * Russ Dill <Russ.Dill@asu.edu> July 2001
* Nicholas Kain <njk@nozspamz.aerifal.cx> 2004 * Nicholas J. Kain <njkain at gmail dot com> 2004-2010
* *
* 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
@@ -40,18 +40,22 @@
#include "log.h" #include "log.h"
#include "script.h" #include "script.h"
static int snprintip(char *dest, size_t size, unsigned char *ip) { static int snprintip(char *dest, size_t size, unsigned char *ip)
{
if (!dest) return -1; if (!dest) return -1;
return snprintf(dest, size, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); return snprintf(dest, size, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
} }
static int sprintip(char *dest, size_t size, char *pre, unsigned char *ip) { static int sprintip(char *dest, size_t size, char *pre, unsigned char *ip)
{
if (!dest) return -1; if (!dest) return -1;
return snprintf(dest, size, "%s%d.%d.%d.%d", pre, ip[0], ip[1], ip[2], ip[3]); return snprintf(dest, size, "%s%d.%d.%d.%d",
pre, ip[0], ip[1], ip[2], ip[3]);
} }
/* Fill dest with the text of option 'option'. */ /* Fill dest with the text of option 'option'. */
static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p, unsigned int maxlen) static void fill_options(char *dest, unsigned char *option,
struct dhcp_option *type_p, unsigned int maxlen)
{ {
int type, optlen; int type, optlen;
uint16_t val_u16; uint16_t val_u16;
@@ -78,26 +82,32 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
dest += sprintip(dest, maxlen - (dest - odest), "", option); dest += sprintip(dest, maxlen - (dest - odest), "", option);
break; break;
case OPTION_BOOLEAN: case OPTION_BOOLEAN:
dest += snprintf(dest, maxlen - (dest - odest), *option ? "yes " : "no "); dest += snprintf(dest, maxlen - (dest - odest),
*option ? "yes " : "no ");
break; break;
case OPTION_U8: case OPTION_U8:
dest += snprintf(dest, maxlen - (dest - odest), "%u ", *option); dest += snprintf(dest, maxlen - (dest - odest),
"%u ", *option);
break; break;
case OPTION_U16: case OPTION_U16:
memcpy(&val_u16, option, 2); memcpy(&val_u16, option, 2);
dest += snprintf(dest, maxlen - (dest - odest), "%u ", ntohs(val_u16)); dest += snprintf(dest, maxlen - (dest - odest),
"%u ", ntohs(val_u16));
break; break;
case OPTION_S16: case OPTION_S16:
memcpy(&val_s16, option, 2); memcpy(&val_s16, option, 2);
dest += snprintf(dest, maxlen - (dest - odest), "%d ", ntohs(val_s16)); dest += snprintf(dest, maxlen - (dest - odest),
"%d ", ntohs(val_s16));
break; break;
case OPTION_U32: case OPTION_U32:
memcpy(&val_u32, option, 4); memcpy(&val_u32, option, 4);
dest += snprintf(dest, maxlen - (dest - odest), "%lu ", (unsigned long) ntohl(val_u32)); dest += snprintf(dest, maxlen - (dest - odest),
"%lu ", (unsigned long) ntohl(val_u32));
break; break;
case OPTION_S32: case OPTION_S32:
memcpy(&val_s32, option, 4); memcpy(&val_s32, option, 4);
dest += snprintf(dest, maxlen - (dest - odest), "%ld ", (long) ntohl(val_s32)); dest += snprintf(dest, maxlen - (dest - odest),
"%ld ", (long) ntohl(val_s32));
break; break;
case OPTION_STRING: case OPTION_STRING:
if ( (maxlen - (dest - odest)) < (unsigned)len) return; if ( (maxlen - (dest - odest)) < (unsigned)len) return;
@@ -113,8 +123,7 @@ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *
static int open_ifch(void) { static int open_ifch(void) {
int sockfd, ret; int sockfd, ret;
struct sockaddr_un address = struct sockaddr_un address = {
{
.sun_family = AF_UNIX, .sun_family = AF_UNIX,
.sun_path = "ifchange" .sun_path = "ifchange"
}; };
@@ -169,7 +178,8 @@ static void deconfig_if(void)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
static void translate_option(int sockfd, struct dhcpMessage *packet, int opt) { static void translate_option(int sockfd, struct dhcpMessage *packet, int opt)
{
char buf[256], buf2[256]; char buf[256], buf2[256];
unsigned char *p; unsigned char *p;
int i; int i;

View File

@@ -1,14 +1,11 @@
/* /*
* socket.c -- DHCP server client/server socket creation * socket.c -- DHCP server client/server socket creation
* *
* udhcp client/server * 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> * Copyright (C) 1999 Matthew Ramsay <matthewr@moreton.com.au>
* Chris Trew <ctrew@moreton.com.au> * Chris Trew <ctrew@moreton.com.au>
* *
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
*
* Cleanup and fixes, Nicholas Kain <njk@n0sPaM.kain.us> 2004
*
* 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
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@@ -152,4 +149,3 @@ out_fd:
out: out:
return -1; return -1;
} }