aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/options.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-03-15 08:29:22 +0000
committerEric Andersen <andersen@codepoet.org>2004-03-15 08:29:22 +0000
commitc7bda1ce659294d6e22c06e087f6f265983c7578 (patch)
tree4c6d2217f4d8306c59cf1096f8664e1cfd167213 /networking/udhcp/options.c
parent8854004b41065b3d081af7f3df13a100b0c8bfbe (diff)
downloadbusybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.tar.gz
busybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.tar.bz2
busybox-w32-c7bda1ce659294d6e22c06e087f6f265983c7578.zip
Remove trailing whitespace. Update copyright to include 2004.
Diffstat (limited to 'networking/udhcp/options.c')
-rw-r--r--networking/udhcp/options.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 1bdf25708..d75bc5aff 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * options.c -- DHCP server option packet tools 2 * options.c -- DHCP server option packet tools
3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 3 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
4 */ 4 */
5 5
6#include <stdlib.h> 6#include <stdlib.h>
7#include <string.h> 7#include <string.h>
8 8
@@ -64,7 +64,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
64 int i, length; 64 int i, length;
65 uint8_t *optionptr; 65 uint8_t *optionptr;
66 int over = 0, done = 0, curr = OPTION_FIELD; 66 int over = 0, done = 0, curr = OPTION_FIELD;
67 67
68 optionptr = packet->options; 68 optionptr = packet->options;
69 i = 0; 69 i = 0;
70 length = 308; 70 length = 308;
@@ -79,7 +79,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
79 return NULL; 79 return NULL;
80 } 80 }
81 return optionptr + i + 2; 81 return optionptr + i + 2;
82 } 82 }
83 switch (optionptr[i + OPT_CODE]) { 83 switch (optionptr[i + OPT_CODE]) {
84 case DHCP_PADDING: 84 case DHCP_PADDING:
85 i++; 85 i++;
@@ -114,10 +114,10 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
114 114
115 115
116/* return the position of the 'end' option (no bounds checking) */ 116/* return the position of the 'end' option (no bounds checking) */
117int end_option(uint8_t *optionptr) 117int end_option(uint8_t *optionptr)
118{ 118{
119 int i = 0; 119 int i = 0;
120 120
121 while (optionptr[i] != DHCP_END) { 121 while (optionptr[i] != DHCP_END) {
122 if (optionptr[i] == DHCP_PADDING) i++; 122 if (optionptr[i] == DHCP_PADDING) i++;
123 else i += optionptr[i + OPT_LEN] + 2; 123 else i += optionptr[i + OPT_LEN] + 2;
@@ -131,7 +131,7 @@ int end_option(uint8_t *optionptr)
131int add_option_string(uint8_t *optionptr, uint8_t *string) 131int add_option_string(uint8_t *optionptr, uint8_t *string)
132{ 132{
133 int end = end_option(optionptr); 133 int end = end_option(optionptr);
134 134
135 /* end position + string length + option code/length + end option */ 135 /* end position + string length + option code/length + end option */
136 if (end + string[OPT_LEN] + 2 + 1 >= 308) { 136 if (end + string[OPT_LEN] + 2 + 1 >= 308) {
137 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]); 137 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]);
@@ -162,12 +162,12 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
162 if (dhcp_options[i].code == code) { 162 if (dhcp_options[i].code == code) {
163 length = option_lengths[dhcp_options[i].flags & TYPE_MASK]; 163 length = option_lengths[dhcp_options[i].flags & TYPE_MASK];
164 } 164 }
165 165
166 if (!length) { 166 if (!length) {
167 DEBUG(LOG_ERR, "Could not add option 0x%02x", code); 167 DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
168 return 0; 168 return 0;
169 } 169 }
170 170
171 option[OPT_CODE] = code; 171 option[OPT_CODE] = code;
172 option[OPT_LEN] = length; 172 option[OPT_LEN] = length;
173 173
@@ -202,7 +202,7 @@ void attach_option(struct option_set **opt_list, struct dhcp_option *option, cha
202 DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); 202 DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name);
203 if (option->flags & OPTION_LIST) { 203 if (option->flags & OPTION_LIST) {
204 if (existing->data[OPT_LEN] + length <= 255) { 204 if (existing->data[OPT_LEN] + length <= 255) {
205 existing->data = realloc(existing->data, 205 existing->data = realloc(existing->data,
206 existing->data[OPT_LEN] + length + 2); 206 existing->data[OPT_LEN] + length + 2);
207 memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length); 207 memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length);
208 existing->data[OPT_LEN] += length; 208 existing->data[OPT_LEN] += length;
@@ -210,19 +210,19 @@ void attach_option(struct option_set **opt_list, struct dhcp_option *option, cha
210 } /* else, ignore the new data */ 210 } /* else, ignore the new data */
211 } else { 211 } else {
212 DEBUG(LOG_INFO, "Attaching option %s to list", option->name); 212 DEBUG(LOG_INFO, "Attaching option %s to list", option->name);
213 213
214 /* make a new option */ 214 /* make a new option */
215 new = xmalloc(sizeof(struct option_set)); 215 new = xmalloc(sizeof(struct option_set));
216 new->data = xmalloc(length + 2); 216 new->data = xmalloc(length + 2);
217 new->data[OPT_CODE] = option->code; 217 new->data[OPT_CODE] = option->code;
218 new->data[OPT_LEN] = length; 218 new->data[OPT_LEN] = length;
219 memcpy(new->data + 2, buffer, length); 219 memcpy(new->data + 2, buffer, length);
220 220
221 curr = opt_list; 221 curr = opt_list;
222 while (*curr && (*curr)->data[OPT_CODE] < option->code) 222 while (*curr && (*curr)->data[OPT_CODE] < option->code)
223 curr = &(*curr)->next; 223 curr = &(*curr)->next;
224 224
225 new->next = *curr; 225 new->next = *curr;
226 *curr = new; 226 *curr = new;
227 } 227 }
228} 228}