diff options
-rw-r--r-- | networking/udhcp/dhcprelay.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index 97bdcb084..e3a816886 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -3,10 +3,10 @@ | |||
3 | * | 3 | * |
4 | * Licensed under GPL v2, see file LICENSE in this tarball for details. | 4 | * Licensed under GPL v2, see file LICENSE in this tarball for details. |
5 | * | 5 | * |
6 | * DHCP Relay for 'DHCPv4 Configuration of IPSec Tunnel Mode' support | 6 | * DHCP Relay for 'DHCPv4 Configuration of IPSec Tunnel Mode' support |
7 | * Copyright (C) 2002 Mario Strasser <mast@gmx.net>, | 7 | * Copyright (C) 2002 Mario Strasser <mast@gmx.net>, |
8 | * Zuercher Hochschule Winterthur, | 8 | * Zuercher Hochschule Winterthur, |
9 | * Netbeat AG | 9 | * Netbeat AG |
10 | * Upstream has GPL v2 or later | 10 | * Upstream has GPL v2 or later |
11 | */ | 11 | */ |
12 | 12 | ||
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | 22 | ||
23 | /* This list holds information about clients. The xid_* functions manipulate this list. */ | 23 | /* This list holds information about clients. The xid_* functions manipulate this list. */ |
24 | struct xid_item { | 24 | static struct xid_item { |
25 | u_int32_t xid; | 25 | u_int32_t xid; |
26 | struct sockaddr_in ip; | 26 | struct sockaddr_in ip; |
27 | int client; | 27 | int client; |
@@ -33,10 +33,10 @@ struct xid_item { | |||
33 | static struct xid_item * xid_add(u_int32_t xid, struct sockaddr_in *ip, int client) | 33 | static struct xid_item * xid_add(u_int32_t xid, struct sockaddr_in *ip, int client) |
34 | { | 34 | { |
35 | struct xid_item *item; | 35 | struct xid_item *item; |
36 | 36 | ||
37 | /* create new xid entry */ | 37 | /* create new xid entry */ |
38 | item = xmalloc(sizeof(struct xid_item)); | 38 | item = xmalloc(sizeof(struct xid_item)); |
39 | 39 | ||
40 | /* add xid entry */ | 40 | /* add xid entry */ |
41 | item->ip = *ip; | 41 | item->ip = *ip; |
42 | item->xid = xid; | 42 | item->xid = xid; |
@@ -133,15 +133,16 @@ static void dhcprelay_signal_handler(int sig) | |||
133 | static char ** get_client_devices(char *dev_list, int *client_number) | 133 | static char ** get_client_devices(char *dev_list, int *client_number) |
134 | { | 134 | { |
135 | char *s, *list, **client_dev; | 135 | char *s, *list, **client_dev; |
136 | int i, cn=1; | 136 | int i, cn; |
137 | 137 | ||
138 | /* copy list */ | 138 | /* copy list */ |
139 | list = xstrdup(dev_list); | 139 | list = xstrdup(dev_list); |
140 | if (list == NULL) return NULL; | 140 | if (list == NULL) return NULL; |
141 | 141 | ||
142 | /* get number of items */ | 142 | /* get number of items */ |
143 | for (s = dev_list; *s; s++) if (*s == ',') | 143 | for (s = dev_list, cn = 1; *s; s++) |
144 | cn++; | 144 | if (*s == ',') |
145 | cn++; | ||
145 | 146 | ||
146 | client_dev = xzalloc(cn * sizeof(*client_dev)); | 147 | client_dev = xzalloc(cn * sizeof(*client_dev)); |
147 | 148 | ||
@@ -166,16 +167,16 @@ static int init_sockets(char **client, int num_clients, | |||
166 | { | 167 | { |
167 | int i; | 168 | int i; |
168 | 169 | ||
169 | // talk to real server on bootps | 170 | /* talk to real server on bootps */ |
170 | fds[0] = listen_socket(htonl(INADDR_ANY), 67, server); | 171 | fds[0] = listen_socket(htonl(INADDR_ANY), 67, server); |
171 | if (fds[0] < 0) return -1; | 172 | if (fds[0] < 0) return -1; |
172 | *max_socket = fds[0]; | 173 | *max_socket = fds[0]; |
173 | 174 | ||
174 | // array starts at 1 since server is 0 | 175 | /* array starts at 1 since server is 0 */ |
175 | num_clients++; | 176 | num_clients++; |
176 | 177 | ||
177 | for (i=1; i < num_clients; i++) { | 178 | for (i=1; i < num_clients; i++) { |
178 | // listen for clients on bootps | 179 | /* listen for clients on bootps */ |
179 | fds[i] = listen_socket(htonl(INADDR_ANY), 67, client[i-1]); | 180 | fds[i] = listen_socket(htonl(INADDR_ANY), 67, client[i-1]); |
180 | if (fds[i] < 0) return -1; | 181 | if (fds[i] < 0) return -1; |
181 | if (fds[i] > *max_socket) *max_socket = fds[i]; | 182 | if (fds[i] > *max_socket) *max_socket = fds[i]; |
@@ -274,7 +275,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli | |||
274 | if (FD_ISSET(fds[0], &rfds)) { | 275 | if (FD_ISSET(fds[0], &rfds)) { |
275 | packlen = udhcp_get_packet(&dhcp_msg, fds[0]); | 276 | packlen = udhcp_get_packet(&dhcp_msg, fds[0]); |
276 | if (packlen > 0) { | 277 | if (packlen > 0) { |
277 | pass_back(&dhcp_msg, packlen, fds); | 278 | pass_back(&dhcp_msg, packlen, fds); |
278 | } | 279 | } |
279 | } | 280 | } |
280 | for (i = 1; i < num_sockets; i++) { | 281 | for (i = 1; i < num_sockets; i++) { |
@@ -318,7 +319,7 @@ int dhcprelay_main(int argc, char **argv) | |||
318 | signal(SIGTERM, dhcprelay_signal_handler); | 319 | signal(SIGTERM, dhcprelay_signal_handler); |
319 | signal(SIGQUIT, dhcprelay_signal_handler); | 320 | signal(SIGQUIT, dhcprelay_signal_handler); |
320 | signal(SIGINT, dhcprelay_signal_handler); | 321 | signal(SIGINT, dhcprelay_signal_handler); |
321 | 322 | ||
322 | num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket); | 323 | num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket); |
323 | if (num_sockets == -1) | 324 | if (num_sockets == -1) |
324 | bb_perror_msg_and_die("init_sockets() failed"); | 325 | bb_perror_msg_and_die("init_sockets() failed"); |