From: Tomek Mrugalski Date: Mon, 21 May 2012 16:32:47 +0000 (+0300) Subject: [1503] Initial support for port number in b10-dhcp4 added. X-Git-Tag: trac2351_base~226^2~63^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2be06486e504e522f9ef39586fe7fb5947c33872;p=thirdparty%2Fkea.git [1503] Initial support for port number in b10-dhcp4 added. --- diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index ee402955ad..2c0a91184e 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -37,6 +37,7 @@ #include #include +#include using namespace std; using namespace isc::util; @@ -53,33 +54,45 @@ usage() { cerr << "Usage: b10-dhcp4 [-v]" << endl; cerr << "\t-v: verbose output" << endl; - exit(1); + cerr << "\t-p number: specify non-standard port number 1-65535 (useful for testing only)" << endl; + exit(EXIT_FAILURE); } } // end of anonymous namespace int main(int argc, char* argv[]) { int ch; + int port_number = DHCP4_SERVER_PORT; // the default. any other values are + // useful for testing only - while ((ch = getopt(argc, argv, ":v")) != -1) { + while ((ch = getopt(argc, argv, "vp:")) != -1) { switch (ch) { case 'v': verbose_mode = true; isc::log::denabled = true; break; + case 'p': + port_number = strtol(optarg, NULL, 10); + if (port_number == 0) { + cerr << "Failed to parse port number: [" << optarg + << "], 1-65535 allowed." << endl; + usage(); + } + break; case ':': default: usage(); } } - cout << "My pid=" << getpid() << endl; + cout << "My pid=" << getpid() << ", binding to port " << port_number + << ", verbose " << (verbose_mode?"yes":"no") << endl; if (argc - optind > 0) { usage(); } - int ret = 0; + int ret = EXIT_SUCCESS; // TODO remainder of auth to dhcp4 code copy. We need to enable this in // dhcp4 eventually @@ -99,13 +112,13 @@ main(int argc, char* argv[]) { cout << "[b10-dhcp4] Initiating DHCPv4 server operation." << endl; - Dhcpv4Srv* srv = new Dhcpv4Srv(); + Dhcpv4Srv* srv = new Dhcpv4Srv(port_number); srv->run(); } catch (const std::exception& ex) { cerr << "[b10-dhcp4] Server failed: " << ex.what() << endl; - ret = 1; + ret = EXIT_FAILURE; } return (ret);