diff -Naur busybox-1.7.1.org/applets/applets.c busybox-1.7.1/applets/applets.c --- busybox-1.7.1.org/applets/applets.c 2007-09-17 02:48:10.000000000 +0800 +++ busybox-1.7.1/applets/applets.c 2007-10-09 10:12:34.000000000 +0800 @@ -23,7 +23,7 @@ #warning Note that glibc is unsuitable for static linking anyway. #warning If you still want to do it, remove -Wl,--gc-sections #warning from top-level Makefile and remove this warning. -#error Aborting compilation. + #endif diff -Naur busybox-1.7.1.org/include/usage.h busybox-1.7.1/include/usage.h --- busybox-1.7.1.org/include/usage.h 2007-09-03 19:48:46.000000000 +0800 +++ busybox-1.7.1/include/usage.h 2007-10-09 10:12:34.000000000 +0800 @@ -3653,7 +3653,7 @@ #define udhcpc_trivial_usage \ "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \ - " [-p pidfile] [-r IP] [-s script]" + " [-p pidfile] [-r IP] [-s script] [-P CLIENT_PORT]" #define udhcpc_full_usage \ " -V,--vendorclass=CLASSID Set vendor class identifier" \ "\n -i,--interface=INTERFACE Interface to use (default: eth0)" \ @@ -3671,14 +3671,16 @@ "\n -q,--quit Quit after obtaining lease" \ "\n -R,--release Release IP on quit" \ "\n -v,--version Display version" \ + "\n -P,--client-port CLIENT_PORT Use CLIENT_PORT as DHCP Client port (default: 68)" \ #define udhcpd_trivial_usage \ - "[-fS] [configfile]" \ + "[-fS] [-P SERVER_PORT] [configfile]" \ #define udhcpd_full_usage \ "DHCP server" \ "\n -f Stay in foreground" \ - "\n -S Log to syslog too" + "\n -S Log to syslog too" \ + "\n -P SERVER_PORT Use SERVER_PORT as DHCP server port (default: 67)" \ #define umount_trivial_usage \ "[flags] FILESYSTEM|DIRECTORY" diff -Naur busybox-1.7.1.org/Makefile busybox-1.7.1/Makefile --- busybox-1.7.1.org/Makefile 2007-09-17 02:50:24.000000000 +0800 +++ busybox-1.7.1/Makefile 2007-10-09 10:12:34.000000000 +0800 @@ -570,7 +570,7 @@ quiet_cmd_busybox__ ?= LINK $@ cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \ -o $@ -Wl,-Map -Wl,$@.map \ - -Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \ + -Wl,--warn-common -Wl,--sort-common \ -Wl,--start-group $(busybox-all) -Wl,--end-group \ $(LDLIBS) diff -Naur busybox-1.7.1.org/networking/udhcp/clientpacket.c busybox-1.7.1/networking/udhcp/clientpacket.c --- busybox-1.7.1.org/networking/udhcp/clientpacket.c 2007-09-03 19:48:26.000000000 +0800 +++ busybox-1.7.1/networking/udhcp/clientpacket.c 2007-10-15 14:27:49.000000000 +0800 @@ -74,6 +74,12 @@ int send_discover(uint32_t xid, uint32_t requested) { struct dhcpMessage packet; + int SRV_PORT, CLT_PORT; + + SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1); + CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port); + + DEBUG("clientpacket.c: send_discover() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT); init_packet(&packet, DHCPDISCOVER); packet.xid = xid; @@ -82,8 +88,7 @@ add_requests(&packet); bb_info_msg("Sending discover..."); - return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, - SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); + return udhcp_raw_packet(&packet, INADDR_ANY, CLT_PORT, INADDR_BROADCAST, SRV_PORT, MAC_BCAST_ADDR, client_config.ifindex); } @@ -92,6 +97,12 @@ { struct dhcpMessage packet; struct in_addr addr; + int SRV_PORT, CLT_PORT; + + SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1); + CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port); + + DEBUG("clientpacket.c: send_selecting() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT); init_packet(&packet, DHCPREQUEST); packet.xid = xid; @@ -102,8 +113,7 @@ add_requests(&packet); addr.s_addr = requested; bb_info_msg("Sending select for %s...", inet_ntoa(addr)); - return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, - SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); + return udhcp_raw_packet(&packet, INADDR_ANY, CLT_PORT, INADDR_BROADCAST, SRV_PORT, MAC_BCAST_ADDR, client_config.ifindex); } @@ -111,6 +121,12 @@ int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) { struct dhcpMessage packet; + int SRV_PORT, CLT_PORT; + + SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1); + CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port); + + DEBUG("clientpacket.c: send_renew() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT); init_packet(&packet, DHCPREQUEST); packet.xid = xid; @@ -119,10 +135,10 @@ add_requests(&packet); bb_info_msg("Sending renew..."); if (server) - return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); + return udhcp_kernel_packet(&packet, ciaddr, CLT_PORT, server, SRV_PORT); - return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, - SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); + return udhcp_raw_packet(&packet, INADDR_ANY, CLT_PORT, INADDR_BROADCAST, + SRV_PORT, MAC_BCAST_ADDR, client_config.ifindex); } @@ -130,6 +146,12 @@ int send_release(uint32_t server, uint32_t ciaddr) { struct dhcpMessage packet; + int SRV_PORT, CLT_PORT; + + SRV_PORT=(client_port == NULL)?SERVER_PORT:(atoi(client_port) - 1); + CLT_PORT=(client_port == NULL)?CLIENT_PORT:atoi(client_port); + + DEBUG("clientpacket.c: send_release() - SRV_PORT= %d, CLT_PORT= %d\n", SRV_PORT, CLT_PORT); init_packet(&packet, DHCPRELEASE); packet.xid = random_xid(); @@ -139,7 +161,7 @@ add_simple_option(packet.options, DHCP_SERVER_ID, server); bb_info_msg("Sending release..."); - return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); + return udhcp_kernel_packet(&packet, ciaddr, CLT_PORT, server, SRV_PORT); } @@ -151,6 +173,8 @@ uint32_t source, dest; uint16_t check; + int CLT_PORT = (client_port == NULL)?CLIENT_PORT:atoi(client_port); + memset(&packet, 0, sizeof(struct udp_dhcp_packet)); bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet)); if (bytes < 0) { @@ -175,7 +199,7 @@ /* Make sure its the right packet for us, and that it passes sanity checks */ if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || packet.ip.ihl != sizeof(packet.ip) >> 2 - || packet.udp.dest != htons(CLIENT_PORT) + || packet.udp.dest != htons(CLT_PORT) || bytes > (int) sizeof(struct udp_dhcp_packet) || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) ) { diff -Naur busybox-1.7.1.org/networking/udhcp/dhcpc.c busybox-1.7.1/networking/udhcp/dhcpc.c --- busybox-1.7.1.org/networking/udhcp/dhcpc.c 2007-09-03 19:48:26.000000000 +0800 +++ busybox-1.7.1/networking/udhcp/dhcpc.c 2007-10-09 10:12:34.000000000 +0800 @@ -10,6 +10,7 @@ #include #include +#include // for atoi() /* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */ #define WANT_PIDFILE 1 @@ -179,6 +180,7 @@ OPT_t = 1 << 16, OPT_v = 1 << 17, OPT_S = 1 << 18, + OPT_P = 1 << 19, }; #if ENABLE_GETOPT_LONG static const char udhcpc_longopts[] ALIGN1 = @@ -201,6 +203,7 @@ "version\0" No_argument "v" "retries\0" Required_argument "t" "syslog\0" No_argument "S" + "client-port\0" Required_argument "P" ; #endif /* Default options. */ @@ -215,10 +218,10 @@ #if ENABLE_GETOPT_LONG applet_long_options = udhcpc_longopts; #endif - opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vS", + opt = getopt32(argv, "c:CV:fbH:h:F:i:np:qRr:s:T:t:vSP:", &str_c, &str_V, &str_h, &str_h, &str_F, &client_config.interface, &client_config.pidfile, &str_r, - &client_config.script, &str_T, &str_t + &client_config.script, &str_T, &str_t, &client_port ); if (opt & OPT_c) @@ -269,6 +272,14 @@ logmode |= LOGMODE_SYSLOG; } + if (opt & OPT_P) { + printf("Use %s as DHCP Client Port!\n",client_port); + } + + if (client_port == NULL) { + printf("Use %d as DHCP Client Port!\n",CLIENT_PORT); + } + if (read_interface(client_config.interface, &client_config.ifindex, NULL, client_config.arp)) return 1; @@ -310,10 +321,15 @@ tv.tv_usec = 0; if (listen_mode != LISTEN_NONE && sockfd < 0) { - if (listen_mode == LISTEN_KERNEL) - sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface); - else + if (listen_mode == LISTEN_KERNEL) { + if (client_port == NULL) { + sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface); + } else { + sockfd = listen_socket(/*INADDR_ANY,*/ atoi(client_port), client_config.interface); + } + } else { sockfd = raw_socket(client_config.ifindex); + } } max_fd = udhcp_sp_fd_set(&rfds, sockfd); diff -Naur busybox-1.7.1.org/networking/udhcp/dhcpd.c busybox-1.7.1/networking/udhcp/dhcpd.c --- busybox-1.7.1.org/networking/udhcp/dhcpd.c 2007-09-03 19:48:26.000000000 +0800 +++ busybox-1.7.1/networking/udhcp/dhcpd.c 2007-10-09 10:12:34.000000000 +0800 @@ -11,6 +11,7 @@ */ #include +#include // for atoi() #include "common.h" #include "dhcpd.h" #include "options.h" @@ -20,7 +21,6 @@ struct dhcpOfferedAddr *leases; struct server_config_t server_config; - int udhcpd_main(int argc, char **argv); int udhcpd_main(int argc, char **argv) { @@ -36,7 +36,7 @@ struct option_set *option; struct dhcpOfferedAddr *lease, static_lease; - opt = getopt32(argv, "fS"); + opt = getopt32(argv, "fSP:",&server_port); argv += optind; if (!(opt & 1)) { /* no -f */ @@ -49,6 +49,15 @@ logmode |= LOGMODE_SYSLOG; } + if (opt & 4) { /* -P */ + printf("Use %s for DHCP Server Port!\n",server_port); + } + + if ( server_port == NULL) + { + printf("Use %d for DHCP Server Port!\n",SERVER_PORT); + } + /* Would rather not do read_config before daemonization - * otherwise NOMMU machines will parse config twice */ read_config(argv[0] ? argv[0] : DHCPD_CONF_FILE); @@ -95,8 +104,10 @@ while (1) { /* loop until universe collapses */ if (server_socket < 0) { - server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT, - server_config.interface); + if ( server_port == NULL) + server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT, server_config.interface); + else + server_socket = listen_socket(/*INADDR_ANY,*/ atoi(server_port), server_config.interface); } max_sock = udhcp_sp_fd_set(&rfds, server_socket); diff -Naur busybox-1.7.1.org/networking/udhcp/options.c busybox-1.7.1/networking/udhcp/options.c --- busybox-1.7.1.org/networking/udhcp/options.c 2007-09-03 19:48:26.000000000 +0800 +++ busybox-1.7.1/networking/udhcp/options.c 2007-10-09 10:12:34.000000000 +0800 @@ -67,6 +67,8 @@ [OPTION_S32] = 4 }; +char *server_port = NULL; +char *client_port = NULL; /* get an option with bounds checking (warning, not aligned). */ uint8_t *get_option(struct dhcpMessage *packet, int code) diff -Naur busybox-1.7.1.org/networking/udhcp/options.h busybox-1.7.1/networking/udhcp/options.h --- busybox-1.7.1.org/networking/udhcp/options.h 2007-09-03 19:48:26.000000000 +0800 +++ busybox-1.7.1/networking/udhcp/options.h 2007-10-09 10:12:34.000000000 +0800 @@ -105,6 +105,8 @@ extern const struct dhcp_option dhcp_options[]; extern const unsigned char option_lengths[]; +extern char *server_port; +extern char *client_port; uint8_t *get_option(struct dhcpMessage *packet, int code); int end_option(uint8_t *optionptr); diff -Naur busybox-1.7.1.org/networking/udhcp/serverpacket.c busybox-1.7.1/networking/udhcp/serverpacket.c --- busybox-1.7.1.org/networking/udhcp/serverpacket.c 2007-09-03 19:48:26.000000000 +0800 +++ busybox-1.7.1/networking/udhcp/serverpacket.c 2007-10-15 14:50:07.000000000 +0800 @@ -30,8 +30,13 @@ { DEBUG("Forwarding packet to relay"); - return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT, - payload->giaddr, SERVER_PORT); + if (server_port == NULL) { + DEBUG("udhcp_kernel_packet(payload, server_config.server, %d, payload->giaddr, %d);",SERVER_PORT,SERVER_PORT); + return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT, payload->giaddr, SERVER_PORT); + } else { + DEBUG("udhcp_kernel_packet(payload, server_config.server, %d, payload->giaddr, %d);",atoi(server_port),atoi(server_port)); + return udhcp_kernel_packet(payload, server_config.server, atoi(server_port), payload->giaddr, atoi(server_port)); + } } @@ -40,6 +45,12 @@ { const uint8_t *chaddr; uint32_t ciaddr; + int SRV_PORT=0, CLT_PORT=0; + + SRV_PORT=(server_port == NULL)?SERVER_PORT:atoi(server_port); + CLT_PORT=(server_port == NULL)?CLIENT_PORT:(atoi(server_port) + 1); + + DEBUG("serverpacket.c: send_packet_to_client() - SRV_PORT=%d, CLT_PORT= %d",SRV_PORT, CLT_PORT); if (force_broadcast) { DEBUG("broadcasting packet to client (NAK)"); @@ -58,8 +69,8 @@ ciaddr = payload->yiaddr; chaddr = payload->chaddr; } - return udhcp_raw_packet(payload, server_config.server, SERVER_PORT, - ciaddr, CLIENT_PORT, chaddr, server_config.ifindex); + return udhcp_raw_packet(payload, server_config.server, SRV_PORT, + ciaddr, CLT_PORT, chaddr, server_config.ifindex); }