* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <sys/time.h>
#include <sys/file.h>
#include <unistd.h>
#include <getopt.h>
#include "options.h"
#include "clientpacket.h"
#include "clientsocket.h"
-#include "script.h"
#include "socket.h"
#include "signalpipe.h"
" " DEFAULT_SCRIPT ")\n"
" -T, --timeout=seconds Try to get the lease for the amount of\n"
" seconds (default: 3)\n"
+" -t, --retries=NUM Send up to NUM request packets\n"
" -v, --version Display version\n"
);
exit(0);
state = RENEW_REQUESTED;
break;
case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
- run_script(NULL, "deconfig");
+ udhcp_run_script(NULL, "deconfig");
case REQUESTING:
case RELEASED:
change_mode(LISTEN_RAW);
LOG(LOG_INFO, "Unicasting a release of %s to %s",
inet_ntoa(temp_addr), buffer);
send_release(server_addr, requested_ip); /* unicast */
- run_script(NULL, "deconfig");
+ udhcp_run_script(NULL, "deconfig");
}
LOG(LOG_INFO, "Entering released state");
static void client_background(void)
{
- background(client_config.pidfile);
+ udhcp_background(client_config.pidfile);
client_config.foreground = 1; /* Do not fork again. */
client_config.background_if_no_lease = 0;
}
{"script", required_argument, 0, 's'},
{"timeout", required_argument, 0, 'T'},
{"version", no_argument, 0, 'v'},
- {"retries", required_argument, 0, 't'},
+ {"retries", required_argument, 0, 't'},
{0, 0, 0, 0}
};
client_config.retries = atoi(optarg);
break;
case 'v':
- printf("udhcpcd, version %s\n\n", VERSION);
+ printf("version %s\n\n", BB_VER);
return 0;
break;
default:
}
/* Start the log, sanitize fd's, and write a pid file */
- start_log_and_pid("udhcpc", client_config.pidfile);
+ udhcp_start_log_and_pid("udhcpc", client_config.pidfile);
if (read_interface(client_config.interface, &client_config.ifindex,
NULL, client_config.arp) < 0)
}
if (!client_config.vendorclass) {
- client_config.vendorclass = xmalloc(sizeof("udhcp "VERSION) + 2);
+ client_config.vendorclass = xmalloc(sizeof("udhcp "BB_VER) + 2);
client_config.vendorclass[OPT_CODE] = DHCP_VENDOR;
- client_config.vendorclass[OPT_LEN] = sizeof("udhcp "VERSION) - 1;
+ client_config.vendorclass[OPT_LEN] = sizeof("udhcp "BB_VER) - 1;
client_config.vendorclass[OPT_DATA] = 1;
memcpy(&client_config.vendorclass[OPT_DATA],
- "udhcp "VERSION, sizeof("udhcp "VERSION) - 1);
+ "udhcp "BB_VER, sizeof("udhcp "BB_VER) - 1);
}
udhcp_sp_setup();
state = INIT_SELECTING;
- run_script(NULL, "deconfig");
+ udhcp_run_script(NULL, "deconfig");
change_mode(LISTEN_RAW);
for (;;) {
timeout = now + client_config.timeout;
packet_num++;
} else {
- run_script(NULL, "leasefail");
+ udhcp_run_script(NULL, "leasefail");
if (client_config.background_if_no_lease) {
LOG(LOG_INFO, "No lease, forking to background.");
client_background();
packet_num++;
} else {
/* timed out, go back to init state */
- if (state == RENEW_REQUESTED) run_script(NULL, "deconfig");
+ if (state == RENEW_REQUESTED) udhcp_run_script(NULL, "deconfig");
state = INIT_SELECTING;
timeout = now;
packet_num = 0;
/* timed out, enter init state */
state = INIT_SELECTING;
LOG(LOG_INFO, "Lease lost, entering init state");
- run_script(NULL, "deconfig");
+ udhcp_run_script(NULL, "deconfig");
timeout = now;
packet_num = 0;
change_mode(LISTEN_RAW);
/* a packet is ready, read it */
if (listen_mode == LISTEN_KERNEL)
- len = get_packet(&packet, fd);
+ len = udhcp_get_packet(&packet, fd);
else len = get_raw_packet(&packet, fd);
if (len == -1 && errno != EINTR) {
start = now;
timeout = t1 + start;
requested_ip = packet.yiaddr;
- run_script(&packet,
+ udhcp_run_script(&packet,
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
state = BOUND;
} else if (*message == DHCPNAK) {
/* return to init state */
LOG(LOG_INFO, "Received DHCP NAK");
- run_script(&packet, "nak");
+ udhcp_run_script(&packet, "nak");
if (state != REQUESTING)
- run_script(NULL, "deconfig");
+ udhcp_run_script(NULL, "deconfig");
state = INIT_SELECTING;
timeout = now;
requested_ip = 0;