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