aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Lehmann <aaronl@vitelius.com>2002-08-21 12:44:54 +0000
committerAaron Lehmann <aaronl@vitelius.com>2002-08-21 12:44:54 +0000
commita95e99e6f34fb95b3285a7dbecdedf9e1eb5b9c1 (patch)
treec5413b0b8abcb511c0fe267c410a425b9cd0c32b
parentd9768d7cb97bbf6d065919907370cb8fbc9f9fa5 (diff)
downloadbusybox-w32-a95e99e6f34fb95b3285a7dbecdedf9e1eb5b9c1.tar.gz
busybox-w32-a95e99e6f34fb95b3285a7dbecdedf9e1eb5b9c1.tar.bz2
busybox-w32-a95e99e6f34fb95b3285a7dbecdedf9e1eb5b9c1.zip
Cleanups. These SHOULD make the binary a lot smaller. But they don't.
CURSE GCC
-rw-r--r--networking/udhcpc.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/networking/udhcpc.c b/networking/udhcpc.c
index 0a2ba21b6..5f9b5c488 100644
--- a/networking/udhcpc.c
+++ b/networking/udhcpc.c
@@ -176,7 +176,7 @@ enum {
176# define LOG_ERR "error" 176# define LOG_ERR "error"
177# define LOG_INFO "info" 177# define LOG_INFO "info"
178# define LOG_DEBUG "debug" 178# define LOG_DEBUG "debug"
179# define LOG(level, str, args...) do { printf("%s, ", level); printf(str, ## args); printf("\n"); } while(0) 179# define LOG(level, str, args...) do { printf("%s, " str "\n", level, ## args); } while(0)
180# define OPEN_LOG(name) do {;} while(0) 180# define OPEN_LOG(name) do {;} while(0)
181#define CLOSE_LOG() do {;} while(0) 181#define CLOSE_LOG() do {;} while(0)
182#endif 182#endif
@@ -280,7 +280,7 @@ static const struct dhcp_option options[] = {
280}; 280};
281 281
282/* Lengths of the different option types */ 282/* Lengths of the different option types */
283static const int option_lengths[] = { 283static const unsigned char option_lengths[] = {
284 [OPTION_IP] = 4, 284 [OPTION_IP] = 4,
285 [OPTION_IP_PAIR] = 8, 285 [OPTION_IP_PAIR] = 8,
286 [OPTION_BOOLEAN] = 1, 286 [OPTION_BOOLEAN] = 1,
@@ -558,7 +558,7 @@ static void add_requests(struct dhcpMessage *packet)
558} 558}
559 559
560/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ 560/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
561static int send_discover(unsigned long xid, unsigned long requested) 561static inline int send_discover(unsigned long xid, unsigned long requested)
562{ 562{
563 struct dhcpMessage packet; 563 struct dhcpMessage packet;
564 564
@@ -568,13 +568,13 @@ static int send_discover(unsigned long xid, unsigned long requested)
568 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); 568 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
569 569
570 add_requests(&packet); 570 add_requests(&packet);
571 LOG(LOG_DEBUG, "Sending discover..."); 571 DEBUG(LOG_DEBUG, "Sending discover...");
572 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 572 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
573 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 573 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
574} 574}
575 575
576/* Broadcasts a DHCP request message */ 576/* Broadcasts a DHCP request message */
577static int send_selecting(unsigned long xid, unsigned long server, unsigned long requested) 577static inline int send_selecting(unsigned long xid, unsigned long server, unsigned long requested)
578{ 578{
579 struct dhcpMessage packet; 579 struct dhcpMessage packet;
580 struct in_addr addr; 580 struct in_addr addr;
@@ -587,7 +587,7 @@ static int send_selecting(unsigned long xid, unsigned long server, unsigned long
587 587
588 add_requests(&packet); 588 add_requests(&packet);
589 addr.s_addr = requested; 589 addr.s_addr = requested;
590 LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); 590 DEBUG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr));
591 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 591 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
592 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 592 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
593} 593}
@@ -597,19 +597,17 @@ static int send_selecting(unsigned long xid, unsigned long server, unsigned long
597static int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) 597static int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
598{ 598{
599 struct dhcpMessage packet; 599 struct dhcpMessage packet;
600 int ret = 0;
601 600
602 init_packet(&packet, DHCPREQUEST); 601 init_packet(&packet, DHCPREQUEST);
603 packet.xid = xid; 602 packet.xid = xid;
604 packet.ciaddr = ciaddr; 603 packet.ciaddr = ciaddr;
605 604
606 add_requests(&packet); 605 add_requests(&packet);
607 LOG(LOG_DEBUG, "Sending renew..."); 606 DEBUG(LOG_DEBUG, "Sending renew...");
608 if (server) 607 if (server)
609 ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 608 return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
610 else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 609 return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
611 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 610 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
612 return ret;
613} 611}
614 612
615/* Create a random xid */ 613/* Create a random xid */
@@ -739,7 +737,7 @@ static int sprintip(char *dest, char *pre, unsigned char *ip) {
739 737
740 738
741/* Fill dest with the text of option 'option'. */ 739/* Fill dest with the text of option 'option'. */
742static void fill_options(char *dest, unsigned char *option, const struct dhcp_option *type_p) 740extern inline void fill_options(char *dest, unsigned char *option, const struct dhcp_option *type_p)
743{ 741{
744 int type, optlen; 742 int type, optlen;
745 u_int16_t val_u16; 743 u_int16_t val_u16;
@@ -917,7 +915,7 @@ static void release_requested(int sig)
917 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested_ip); 915 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested_ip);
918 add_simple_option(packet.options, DHCP_SERVER_ID, server_addr); 916 add_simple_option(packet.options, DHCP_SERVER_ID, server_addr);
919 917
920 LOG(LOG_DEBUG, "Sending release..."); 918 DEBUG(LOG_DEBUG, "Sending release...");
921 kernel_packet(&packet, requested_ip, CLIENT_PORT, server_addr, SERVER_PORT); 919 kernel_packet(&packet, requested_ip, CLIENT_PORT, server_addr, SERVER_PORT);
922 run_script(NULL, "deconfig"); 920 run_script(NULL, "deconfig");
923 } 921 }
@@ -978,7 +976,7 @@ static void terminate(int sig)
978} 976}
979 977
980 978
981static int read_interface(char *interface, int *ifindex, u_int32_t *addr, unsigned char *arp) 979extern inline int read_interface(char *interface, int *ifindex, u_int32_t *addr, unsigned char *arp)
982{ 980{
983 int l_fd; 981 int l_fd;
984 struct ifreq ifr; 982 struct ifreq ifr;
@@ -1024,7 +1022,7 @@ static int read_interface(char *interface, int *ifindex, u_int32_t *addr, unsign
1024} 1022}
1025 1023
1026 1024
1027static int listen_socket(unsigned int ip, int port, char *inf) 1025extern inline int listen_socket(unsigned int ip, int port, char *inf)
1028{ 1026{
1029 struct ifreq interface; 1027 struct ifreq interface;
1030 int l_fd; 1028 int l_fd;
@@ -1129,7 +1127,7 @@ static int get_packet(struct dhcpMessage *packet, int l_fd)
1129 return bytes; 1127 return bytes;
1130} 1128}
1131 1129
1132static int get_raw_packet(struct dhcpMessage *payload, int l_fd) 1130extern inline int get_raw_packet(struct dhcpMessage *payload, int l_fd)
1133{ 1131{
1134 int bytes; 1132 int bytes;
1135 struct udp_dhcp_packet packet; 1133 struct udp_dhcp_packet packet;
@@ -1198,7 +1196,6 @@ static int get_raw_packet(struct dhcpMessage *payload, int l_fd)
1198 } 1196 }
1199 DEBUG(LOG_INFO, "oooooh!!! got some!"); 1197 DEBUG(LOG_INFO, "oooooh!!! got some!");
1200 return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); 1198 return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
1201
1202} 1199}
1203 1200
1204 1201
@@ -1239,7 +1236,8 @@ int udhcpc_main(int argc, char *argv[])
1239 1236
1240 switch (c) { 1237 switch (c) {
1241 case 'c': 1238 case 'c':
1242 len = strlen(optarg) > 255 ? 255 : strlen(optarg); 1239 len = strlen(optarg);
1240 if (len > 255) len = 255;
1243 if (client_config.clientid) free(client_config.clientid); 1241 if (client_config.clientid) free(client_config.clientid);
1244 client_config.clientid = xmalloc(len + 2); 1242 client_config.clientid = xmalloc(len + 2);
1245 client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID; 1243 client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
@@ -1251,7 +1249,8 @@ int udhcpc_main(int argc, char *argv[])
1251 client_config.foreground = 1; 1249 client_config.foreground = 1;
1252 break; 1250 break;
1253 case 'H': 1251 case 'H':
1254 len = strlen(optarg) > 255 ? 255 : strlen(optarg); 1252 len = strlen(optarg);
1253 if (len > 255) len = 255;
1255 if (client_config.hostname) free(client_config.hostname); 1254 if (client_config.hostname) free(client_config.hostname);
1256 client_config.hostname = xmalloc(len + 2); 1255 client_config.hostname = xmalloc(len + 2);
1257 client_config.hostname[OPT_CODE] = DHCP_HOST_NAME; 1256 client_config.hostname[OPT_CODE] = DHCP_HOST_NAME;