00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <oasys/io/NetUtils.h>
00019 #include "IPConvergenceLayer.h"
00020
00021 namespace dtn {
00022
00029 bool
00030 IPConvergenceLayer::parse_nexthop(const char* nexthop,
00031 in_addr_t* addr, u_int16_t* port)
00032 {
00033 const char* host;
00034 std::string tmp;
00035
00036 *addr = INADDR_NONE;
00037 *port = 0;
00038
00039
00040
00041
00042
00043
00044
00045 const char* colon = strchr(nexthop, ':');
00046 if (colon != NULL) {
00047 char* endstr;
00048 u_int32_t portval = strtoul(colon + 1, &endstr, 10);
00049
00050 if (*endstr != '\0' || portval > 65535) {
00051 log_warn("invalid port %s in next hop '%s'",
00052 colon + 1, nexthop);
00053 return false;
00054 }
00055
00056 *port = (u_int16_t)portval;
00057
00058 tmp.assign(nexthop, colon - nexthop);
00059 host = tmp.c_str();
00060 } else {
00061 host = nexthop;
00062 }
00063
00064
00065 if (oasys::gethostbyname(host, addr) != 0) {
00066 log_warn("can't lookup hostname '%s' in next hop %s",
00067 host, nexthop);
00068 return false;
00069 }
00070
00071 return true;
00072 }
00073
00074
00075 }