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 #ifdef __linux__
00022
00023 #include <oasys/io/IPSocket.h>
00024 #include <oasys/io/NetUtils.h>
00025
00026 #include "EthernetScheme.h"
00027 #include "EndpointID.h"
00028
00029 namespace dtn {
00030
00031 template <>
00032 EthernetScheme* oasys::Singleton<EthernetScheme>::instance_ = 0;
00033
00034
00035
00036
00037
00038
00039 bool
00040 EthernetScheme::parse(const std::string& ssp, eth_addr_t* addr)
00041 {
00042
00043
00044
00045 const char* str = ssp.c_str();
00046 if (str[0] == '/' && str[1] == '/') {
00047 str = str + 2;
00048 }
00049
00050
00051
00052 int r = sscanf(str, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx",
00053 &addr->octet[0],
00054 &addr->octet[1],
00055 &addr->octet[2],
00056 &addr->octet[3],
00057 &addr->octet[4],
00058 &addr->octet[5]);
00059 if (r != 6) {
00060 return false;
00061 }
00062
00063 return true;
00064 }
00065
00073 bool
00074 EthernetScheme::validate(const URI& uri, bool is_pattern)
00075 {
00076 (void)is_pattern;
00077
00078
00079 eth_addr_t addr;
00080 return parse(uri.ssp(), &addr);
00081 }
00082
00088 bool
00089 EthernetScheme::match(const EndpointIDPattern& pattern,
00090 const EndpointID& eid)
00091 {
00092
00093 ASSERT(pattern.scheme() == this);
00094
00095 log_debug_p("/dtn/scheme/ethernet",
00096 "matching %s against %s.", pattern.ssp().c_str(), eid.ssp().c_str());
00097
00098 size_t patternlen = pattern.ssp().length();
00099
00100 if (pattern.ssp() == eid.ssp())
00101 return true;
00102
00103 if (patternlen >= 1 && pattern.ssp()[patternlen-1] == '*') {
00104 patternlen--;
00105
00106 if (pattern.ssp().substr(0, patternlen) ==
00107 eid.ssp().substr(0, patternlen))
00108 {
00109 return true;
00110 }
00111 }
00112
00113 return false;
00114 }
00115
00116 EndpointID::singleton_info_t
00117 EthernetScheme::is_singleton(const URI& uri)
00118 {
00119 (void)uri;
00120 return EndpointID::SINGLETON;
00121 }
00122
00123 char*
00124 EthernetScheme::to_string(u_int8_t* addr, char* outstring)
00125 {
00126 sprintf(outstring,"eth://%02X:%02X:%02X:%02X:%02X:%02X",
00127 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
00128
00129 return outstring;
00130 }
00131
00132
00133 }
00134
00135 #endif