main.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <sys/select.h>
  18. #include <netdb.h>
  19. #include <netinet/in.h>
  20. #include <stdlib.h>
  21. #include <errno.h>
  22. #include <cassert>
  23. #include <iostream>
  24. #include <exceptions/exceptions.h>
  25. #if 0
  26. // TODO cc is not used yet. It should be eventually
  27. #include <cc/session.h>
  28. #include <config/ccsession.h>
  29. #endif
  30. #include <util/buffer.h>
  31. #include <log/dummylog.h>
  32. #include <dhcp6/spec_config.h>
  33. #include "dhcp6/dhcp6_srv.h"
  34. using namespace std;
  35. using namespace isc::util;
  36. using namespace isc;
  37. using namespace isc::dhcp;
  38. namespace {
  39. bool verbose_mode = false;
  40. void
  41. usage() {
  42. cerr << "Usage: b10-dhcp6 [-v]"
  43. << endl;
  44. cerr << "\t-v: verbose output" << endl;
  45. cerr << "\t-p number: specify non-standard port number 1-65535 (useful for testing only)" << endl;
  46. exit(EXIT_FAILURE);
  47. }
  48. } // end of anonymous namespace
  49. int
  50. main(int argc, char* argv[]) {
  51. int ch;
  52. int port_number = DHCP6_SERVER_PORT; // The default. Any other values are
  53. // useful for testing only.
  54. while ((ch = getopt(argc, argv, "vp:")) != -1) {
  55. switch (ch) {
  56. case 'v':
  57. verbose_mode = true;
  58. isc::log::denabled = true;
  59. break;
  60. case 'p':
  61. port_number = strtol(optarg, NULL, 10);
  62. if (port_number == 0) {
  63. cerr << "Failed to parse port number: [" << optarg
  64. << "], 1-65535 allowed." << endl;
  65. usage();
  66. }
  67. break;
  68. case ':':
  69. default:
  70. usage();
  71. }
  72. }
  73. cout << "My pid=" << getpid() << endl;
  74. if (argc - optind > 0) {
  75. usage();
  76. }
  77. int ret = EXIT_SUCCESS;
  78. // TODO remainder of auth to dhcp6 code copy. We need to enable this in
  79. // dhcp6 eventually
  80. #if 0
  81. Session* cc_session = NULL;
  82. Session* statistics_session = NULL;
  83. ModuleCCSession* config_session = NULL;
  84. #endif
  85. try {
  86. string specfile;
  87. if (getenv("B10_FROM_BUILD")) {
  88. specfile = string(getenv("B10_FROM_BUILD")) +
  89. "/src/bin/auth/dhcp6.spec";
  90. } else {
  91. specfile = string(DHCP6_SPECFILE_LOCATION);
  92. }
  93. cout << "[b10-dhcp6] Initiating DHCPv6 operation." << endl;
  94. Dhcpv6Srv* srv = new Dhcpv6Srv(port_number);
  95. srv->run();
  96. } catch (const std::exception& ex) {
  97. cerr << "[b10-dhcp6] Server failed: " << ex.what() << endl;
  98. ret = EXIT_FAILURE;
  99. }
  100. return (ret);
  101. }