Whitespace and indentation normalization.
This commit is contained in:
5
README
5
README
@@ -10,10 +10,7 @@ C99-compliant C compiler (for C99 struct subobject init)
|
||||
|
||||
CMake (tested: 2.8)
|
||||
|
||||
Tested with glibc 2.2.x and 2.3.x. dietlibc is not compatible. I have not yet
|
||||
tested uclibc.
|
||||
|
||||
I may bother to port to other operating systems, but don't count on it.
|
||||
Tested with glibc. dietlibc is not compatible. I have not tested uclibc.
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -654,7 +653,7 @@ static void dispatch_work(void)
|
||||
idle_time[i] = time(NULL);
|
||||
memset(buf, '\0', sizeof(buf));
|
||||
|
||||
dispatch_work_read_again:
|
||||
read_again:
|
||||
ret = (int) read(sks[i], buf, MAX_BUF / 2 - 1);
|
||||
|
||||
/* Check to see if peer closed socket */
|
||||
@@ -666,7 +665,7 @@ dispatch_work_read_again:
|
||||
|
||||
if (ret == -1) {
|
||||
if (errno == EINTR)
|
||||
goto dispatch_work_read_again;
|
||||
goto read_again;
|
||||
log_line("dispatch_work: read returned %s.\n", strerror(errno));
|
||||
close(sks[i]);
|
||||
new_sk(i, -1);
|
||||
@@ -747,7 +746,7 @@ int main(int argc, char** argv) {
|
||||
printf(
|
||||
"ifchd %s, if change daemon. Licensed under GNU GPL.\n", IFCHD_VERSION);
|
||||
printf(
|
||||
"Copyright (C) 2004 Nicholas J. Kain\n"
|
||||
"Copyright (C) 2004-2010 Nicholas J. Kain\n"
|
||||
"Usage: ifchd [OPTIONS]\n"
|
||||
" -d, --detach detach from TTY and daemonize\n"
|
||||
" -n, --nodetach stay attached to TTY\n"
|
||||
@@ -772,7 +771,7 @@ int main(int argc, char** argv) {
|
||||
printf(
|
||||
"ifchd %s, if change daemon. Licensed under GNU GPL.\n", IFCHD_VERSION);
|
||||
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"
|
||||
"WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -154,9 +153,9 @@ static int set_if_flag(int idx, short flag)
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
out1:
|
||||
out1:
|
||||
close(fd);
|
||||
out0:
|
||||
out0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* 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
|
||||
* 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
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NJK_IFCHD_LINUX_H_
|
||||
#define NJK_IFCHD_LINUX_H_ 1
|
||||
#define NJK_IFCHD_LINUX_H_
|
||||
void clear_if_data(int idx);
|
||||
void initialize_if_data(void);
|
||||
void add_permitted_if(char *s);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -62,7 +63,6 @@ unsigned long random_xid(void)
|
||||
return rand();
|
||||
}
|
||||
|
||||
|
||||
/* initialize a packet with the proper defaults */
|
||||
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 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
|
||||
* 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_LEN] = len;
|
||||
packet->options[end + OPT_DATA + len] = DHCP_END;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Broadcast a DHCP discover packet to the network, with an optionally
|
||||
* requested IP */
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/* Broadcasts a DHCP request message */
|
||||
int send_selecting(unsigned long xid, unsigned long server,
|
||||
unsigned long requested)
|
||||
@@ -137,7 +133,6 @@ int send_selecting(unsigned long xid, unsigned long server,
|
||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
||||
}
|
||||
|
||||
|
||||
/* Unicasts or broadcasts a DHCP renew message */
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/* Unicasts a DHCP release message */
|
||||
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 -1 on errors that are fatal for the socket,
|
||||
* -2 for those that aren't */
|
||||
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!");
|
||||
return len - (sizeof(packet.ip) + sizeof(packet.udp));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
*
|
||||
* ndhc DHCP client
|
||||
*
|
||||
* Nicholas J. Kain <njkain at gmail dot com> 2004-2010
|
||||
* 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
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* options.c -- DHCP server option packet tools
|
||||
* 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>
|
||||
@@ -17,33 +17,33 @@
|
||||
/* supported options are easily added here */
|
||||
struct dhcp_option options[] = {
|
||||
/* name[10] flags code */
|
||||
{"subnet", OPTION_IP | OPTION_REQ, 0x01},
|
||||
{"timezone", OPTION_S32, 0x02},
|
||||
{"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
|
||||
{"timesvr", OPTION_IP | OPTION_LIST, 0x04},
|
||||
{"namesvr", OPTION_IP | OPTION_LIST, 0x05},
|
||||
{"dns", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06},
|
||||
{"logsvr", OPTION_IP | OPTION_LIST, 0x07},
|
||||
{"subnet" , OPTION_IP | OPTION_REQ, 0x01},
|
||||
{"timezone" , OPTION_S32, 0x02},
|
||||
{"router" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03},
|
||||
{"timesvr" , OPTION_IP | OPTION_LIST, 0x04},
|
||||
{"namesvr" , OPTION_IP | OPTION_LIST, 0x05},
|
||||
{"dns" , OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06},
|
||||
{"logsvr" , OPTION_IP | OPTION_LIST, 0x07},
|
||||
{"cookiesvr", OPTION_IP | OPTION_LIST, 0x08},
|
||||
{"lprsvr", OPTION_IP | OPTION_LIST, 0x09},
|
||||
{"hostname", OPTION_STRING | OPTION_REQ, 0x0c},
|
||||
{"bootsize", OPTION_U16, 0x0d},
|
||||
{"domain", OPTION_STRING | OPTION_REQ, 0x0f},
|
||||
{"swapsvr", OPTION_IP, 0x10},
|
||||
{"rootpath", OPTION_STRING, 0x11},
|
||||
{"ipttl", OPTION_U8, 0x17},
|
||||
{"mtu", OPTION_U16, 0x1a},
|
||||
{"lprsvr" , OPTION_IP | OPTION_LIST, 0x09},
|
||||
{"hostname" , OPTION_STRING | OPTION_REQ, 0x0c},
|
||||
{"bootsize" , OPTION_U16, 0x0d},
|
||||
{"domain" , OPTION_STRING | OPTION_REQ, 0x0f},
|
||||
{"swapsvr" , OPTION_IP, 0x10},
|
||||
{"rootpath" , OPTION_STRING, 0x11},
|
||||
{"ipttl" , OPTION_U8, 0x17},
|
||||
{"mtu" , OPTION_U16, 0x1a},
|
||||
{"broadcast", OPTION_IP | OPTION_REQ, 0x1c},
|
||||
{"ntpsrv", OPTION_IP | OPTION_LIST, 0x2a},
|
||||
{"wins", OPTION_IP | OPTION_LIST, 0x2c},
|
||||
{"ntpsrv" , OPTION_IP | OPTION_LIST, 0x2a},
|
||||
{"wins" , OPTION_IP | OPTION_LIST, 0x2c},
|
||||
{"requestip", OPTION_IP, 0x32},
|
||||
{"lease", OPTION_U32, 0x33},
|
||||
{"dhcptype", OPTION_U8, 0x35},
|
||||
{"serverid", OPTION_IP, 0x36},
|
||||
{"message", OPTION_STRING, 0x38},
|
||||
{"tftp", OPTION_STRING, 0x42},
|
||||
{"bootfile", OPTION_STRING, 0x43},
|
||||
{"", 0x00, 0x00}
|
||||
{"lease" , OPTION_U32, 0x33},
|
||||
{"dhcptype" , OPTION_U8, 0x35},
|
||||
{"serverid" , OPTION_IP, 0x36},
|
||||
{"message" , OPTION_STRING, 0x38},
|
||||
{"tftp" , OPTION_STRING, 0x42},
|
||||
{"bootfile" , OPTION_STRING, 0x43},
|
||||
{"" , 0x00, 0x00}
|
||||
};
|
||||
|
||||
/* Lengths of the different option types */
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "dhcpd.h"
|
||||
#include "options.h"
|
||||
|
||||
|
||||
void init_header(struct dhcpMessage *packet, char type)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/* read a packet from socket fd, return -1 on read error, -2 on packet error */
|
||||
int get_packet(struct dhcpMessage *packet, int fd)
|
||||
{
|
||||
@@ -106,7 +104,6 @@ uint16_t checksum(void *addr, int count)
|
||||
return ~sum;
|
||||
}
|
||||
|
||||
|
||||
/* Constuct a ip/udp header for a packet, and specify the source and dest
|
||||
* hardware address */
|
||||
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
@@ -158,13 +155,12 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
log_error("write on socket failed: %s",
|
||||
strerror(errno));
|
||||
}
|
||||
out_fd:
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
@@ -195,9 +191,8 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip,
|
||||
goto out_fd;
|
||||
|
||||
result = write(fd, payload, sizeof(struct dhcpMessage));
|
||||
out_fd:
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Functions to call the interface change daemon
|
||||
*
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -40,18 +40,22 @@
|
||||
#include "log.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;
|
||||
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;
|
||||
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'. */
|
||||
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;
|
||||
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);
|
||||
break;
|
||||
case OPTION_BOOLEAN:
|
||||
dest += snprintf(dest, maxlen - (dest - odest), *option ? "yes " : "no ");
|
||||
dest += snprintf(dest, maxlen - (dest - odest),
|
||||
*option ? "yes " : "no ");
|
||||
break;
|
||||
case OPTION_U8:
|
||||
dest += snprintf(dest, maxlen - (dest - odest), "%u ", *option);
|
||||
dest += snprintf(dest, maxlen - (dest - odest),
|
||||
"%u ", *option);
|
||||
break;
|
||||
case OPTION_U16:
|
||||
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;
|
||||
case OPTION_S16:
|
||||
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;
|
||||
case OPTION_U32:
|
||||
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;
|
||||
case OPTION_S32:
|
||||
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;
|
||||
case OPTION_STRING:
|
||||
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) {
|
||||
int sockfd, ret;
|
||||
struct sockaddr_un address =
|
||||
{
|
||||
struct sockaddr_un address = {
|
||||
.sun_family = AF_UNIX,
|
||||
.sun_path = "ifchange"
|
||||
};
|
||||
@@ -134,7 +143,7 @@ static void sockwrite(int fd, const void *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
|
||||
sockwrite_again:
|
||||
sockwrite_again:
|
||||
ret = write(fd, buf, count);
|
||||
if (ret == -1) {
|
||||
if (errno == EAGAIN)
|
||||
@@ -169,7 +178,8 @@ static void deconfig_if(void)
|
||||
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];
|
||||
unsigned char *p;
|
||||
int i;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
/*
|
||||
* 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>
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -83,9 +80,9 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr,
|
||||
log_line("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
|
||||
ret = 0;
|
||||
out_fd:
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -121,9 +118,9 @@ int listen_socket(unsigned int ip, int port, char *inf)
|
||||
goto out_fd;
|
||||
|
||||
return fd;
|
||||
out_fd:
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
out:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -147,9 +144,8 @@ int raw_socket(int ifindex)
|
||||
}
|
||||
|
||||
return fd;
|
||||
out_fd:
|
||||
out_fd:
|
||||
close(fd);
|
||||
out:
|
||||
out:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user