00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifdef __linux__
00040
00041 #include <oasys/io/IPSocket.h>
00042 #include <oasys/io/NetUtils.h>
00043 #include <oasys/util/URL.h>
00044
00045 #include "EthernetScheme.h"
00046 #include "EndpointID.h"
00047
00048 namespace dtn {
00049
00050 template <>
00051 EthernetScheme* oasys::Singleton<EthernetScheme>::instance_ = 0;
00052
00053
00054
00055
00056
00057
00058 bool
00059 EthernetScheme::parse(const std::string& ssp, eth_addr_t* addr)
00060 {
00061
00062
00063
00064 const char* str = ssp.c_str();
00065 if (str[0] == '/' && str[1] == '/') {
00066 str = str + 2;
00067 }
00068
00069
00070
00071 int r = sscanf(str, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
00072 &addr->octet[0],
00073 &addr->octet[1],
00074 &addr->octet[2],
00075 &addr->octet[3],
00076 &addr->octet[4],
00077 &addr->octet[5]);
00078 if (r != 6) {
00079 return false;
00080 }
00081
00082 return true;
00083 }
00084
00092 bool
00093 EthernetScheme::validate(const std::string& ssp, bool is_pattern)
00094 {
00095 (void)is_pattern;
00096
00097
00098 eth_addr_t addr;
00099 return parse(ssp, &addr);
00100 }
00101
00107 bool
00108 EthernetScheme::match(const EndpointIDPattern& pattern,
00109 const EndpointID& eid)
00110 {
00111
00112 ASSERT(pattern.scheme() == this);
00113
00114 log_debug("/dtn/scheme/ethernet",
00115 "matching %s against %s.", pattern.ssp().c_str(), eid.ssp().c_str());
00116
00117 size_t patternlen = pattern.ssp().length();
00118
00119 if (pattern.ssp() == eid.ssp())
00120 return true;
00121
00122 if (patternlen >= 1 && pattern.ssp()[patternlen-1] == '*') {
00123 patternlen--;
00124
00125 if (pattern.ssp().substr(0, patternlen) ==
00126 eid.ssp().substr(0, patternlen))
00127 {
00128 return true;
00129 }
00130 }
00131
00132 return false;
00133 }
00134
00135 char*
00136 EthernetScheme::to_string(u_int8_t* addr, char* outstring)
00137 {
00138 sprintf(outstring,"eth://%02X:%02X:%02X:%02X:%02X:%02X",
00139 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
00140
00141 return outstring;
00142 }
00143
00144
00145 }
00146
00147 #endif