diff options
author | Paul Fox <pgf@brightstareng.com> | 2005-09-22 19:03:24 +0000 |
---|---|---|
committer | Paul Fox <pgf@brightstareng.com> | 2005-09-22 19:03:24 +0000 |
commit | b6f71645f452572640a0529fb091f71cf8a30c3e (patch) | |
tree | 37b9519c4a5cc1199dfb1563d61447d32cff3a60 | |
parent | 28de951b022d39516de271ce0ba53560aa3c5555 (diff) | |
download | busybox-w32-b6f71645f452572640a0529fb091f71cf8a30c3e.tar.gz busybox-w32-b6f71645f452572640a0529fb091f71cf8a30c3e.tar.bz2 busybox-w32-b6f71645f452572640a0529fb091f71cf8a30c3e.zip |
move a couple of functions from common code (options.c) to udhcpd private
code (files.c) to make udhcpc a little smaller.
-rw-r--r-- | networking/udhcp/files.c | 48 | ||||
-rw-r--r-- | networking/udhcp/files.h | 3 | ||||
-rw-r--r-- | networking/udhcp/options.c | 48 | ||||
-rw-r--r-- | networking/udhcp/options.h | 2 |
4 files changed, 51 insertions, 50 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 73a3bbc6e..33cd25aff 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -15,8 +15,8 @@ | |||
15 | #include "static_leases.h" | 15 | #include "static_leases.h" |
16 | 16 | ||
17 | #include "dhcpd.h" | 17 | #include "dhcpd.h" |
18 | #include "files.h" | ||
19 | #include "options.h" | 18 | #include "options.h" |
19 | #include "files.h" | ||
20 | #include "common.h" | 20 | #include "common.h" |
21 | 21 | ||
22 | /* | 22 | /* |
@@ -93,6 +93,52 @@ static int read_yn(const char *line, void *arg) | |||
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | /* find option 'code' in opt_list */ | ||
97 | struct option_set *find_option(struct option_set *opt_list, char code) | ||
98 | { | ||
99 | while (opt_list && opt_list->data[OPT_CODE] < code) | ||
100 | opt_list = opt_list->next; | ||
101 | |||
102 | if (opt_list && opt_list->data[OPT_CODE] == code) return opt_list; | ||
103 | else return NULL; | ||
104 | } | ||
105 | |||
106 | |||
107 | /* add an option to the opt_list */ | ||
108 | void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length) | ||
109 | { | ||
110 | struct option_set *existing, *new, **curr; | ||
111 | |||
112 | /* add it to an existing option */ | ||
113 | if ((existing = find_option(*opt_list, option->code))) { | ||
114 | DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); | ||
115 | if (option->flags & OPTION_LIST) { | ||
116 | if (existing->data[OPT_LEN] + length <= 255) { | ||
117 | existing->data = realloc(existing->data, | ||
118 | existing->data[OPT_LEN] + length + 2); | ||
119 | memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length); | ||
120 | existing->data[OPT_LEN] += length; | ||
121 | } /* else, ignore the data, we could put this in a second option in the future */ | ||
122 | } /* else, ignore the new data */ | ||
123 | } else { | ||
124 | DEBUG(LOG_INFO, "Attaching option %s to list", option->name); | ||
125 | |||
126 | /* make a new option */ | ||
127 | new = xmalloc(sizeof(struct option_set)); | ||
128 | new->data = xmalloc(length + 2); | ||
129 | new->data[OPT_CODE] = option->code; | ||
130 | new->data[OPT_LEN] = length; | ||
131 | memcpy(new->data + 2, buffer, length); | ||
132 | |||
133 | curr = opt_list; | ||
134 | while (*curr && (*curr)->data[OPT_CODE] < option->code) | ||
135 | curr = &(*curr)->next; | ||
136 | |||
137 | new->next = *curr; | ||
138 | *curr = new; | ||
139 | } | ||
140 | } | ||
141 | |||
96 | /* read a dhcp option and add it to opt_list */ | 142 | /* read a dhcp option and add it to opt_list */ |
97 | static int read_opt(const char *const_line, void *arg) | 143 | static int read_opt(const char *const_line, void *arg) |
98 | { | 144 | { |
diff --git a/networking/udhcp/files.h b/networking/udhcp/files.h index 279738adf..4af61b005 100644 --- a/networking/udhcp/files.h +++ b/networking/udhcp/files.h | |||
@@ -14,4 +14,7 @@ int read_config(const char *file); | |||
14 | void write_leases(void); | 14 | void write_leases(void); |
15 | void read_leases(const char *file); | 15 | void read_leases(const char *file); |
16 | 16 | ||
17 | struct option_set *find_option(struct option_set *opt_list, char code); | ||
18 | void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length); | ||
19 | |||
17 | #endif | 20 | #endif |
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index 000f86c79..e81d0a757 100644 --- a/networking/udhcp/options.c +++ b/networking/udhcp/options.c | |||
@@ -7,8 +7,8 @@ | |||
7 | #include <string.h> | 7 | #include <string.h> |
8 | 8 | ||
9 | #include "dhcpd.h" | 9 | #include "dhcpd.h" |
10 | #include "files.h" | ||
11 | #include "options.h" | 10 | #include "options.h" |
11 | #include "files.h" | ||
12 | #include "common.h" | 12 | #include "common.h" |
13 | 13 | ||
14 | 14 | ||
@@ -171,49 +171,3 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) | |||
171 | return 0; | 171 | return 0; |
172 | } | 172 | } |
173 | 173 | ||
174 | |||
175 | /* find option 'code' in opt_list */ | ||
176 | struct option_set *find_option(struct option_set *opt_list, char code) | ||
177 | { | ||
178 | while (opt_list && opt_list->data[OPT_CODE] < code) | ||
179 | opt_list = opt_list->next; | ||
180 | |||
181 | if (opt_list && opt_list->data[OPT_CODE] == code) return opt_list; | ||
182 | else return NULL; | ||
183 | } | ||
184 | |||
185 | |||
186 | /* add an option to the opt_list */ | ||
187 | void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length) | ||
188 | { | ||
189 | struct option_set *existing, *new, **curr; | ||
190 | |||
191 | /* add it to an existing option */ | ||
192 | if ((existing = find_option(*opt_list, option->code))) { | ||
193 | DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); | ||
194 | if (option->flags & OPTION_LIST) { | ||
195 | if (existing->data[OPT_LEN] + length <= 255) { | ||
196 | existing->data = realloc(existing->data, | ||
197 | existing->data[OPT_LEN] + length + 2); | ||
198 | memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length); | ||
199 | existing->data[OPT_LEN] += length; | ||
200 | } /* else, ignore the data, we could put this in a second option in the future */ | ||
201 | } /* else, ignore the new data */ | ||
202 | } else { | ||
203 | DEBUG(LOG_INFO, "Attaching option %s to list", option->name); | ||
204 | |||
205 | /* make a new option */ | ||
206 | new = xmalloc(sizeof(struct option_set)); | ||
207 | new->data = xmalloc(length + 2); | ||
208 | new->data[OPT_CODE] = option->code; | ||
209 | new->data[OPT_LEN] = length; | ||
210 | memcpy(new->data + 2, buffer, length); | ||
211 | |||
212 | curr = opt_list; | ||
213 | while (*curr && (*curr)->data[OPT_CODE] < option->code) | ||
214 | curr = &(*curr)->next; | ||
215 | |||
216 | new->next = *curr; | ||
217 | *curr = new; | ||
218 | } | ||
219 | } | ||
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h index fbe54c884..4948bac00 100644 --- a/networking/udhcp/options.h +++ b/networking/udhcp/options.h | |||
@@ -34,7 +34,5 @@ uint8_t *get_option(struct dhcpMessage *packet, int code); | |||
34 | int end_option(uint8_t *optionptr); | 34 | int end_option(uint8_t *optionptr); |
35 | int add_option_string(uint8_t *optionptr, uint8_t *string); | 35 | int add_option_string(uint8_t *optionptr, uint8_t *string); |
36 | int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data); | 36 | int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data); |
37 | struct option_set *find_option(struct option_set *opt_list, char code); | ||
38 | void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length); | ||
39 | 37 | ||
40 | #endif | 38 | #endif |