39 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
40 #define EADDRINUSE WSAEADDRINUSE
52 const std::string IPNDAgent::TAG =
"IPNDAgent";
57 _virtual_mcast_iface(
"__virtual_multicast_interface__"),
59 _state(false), _port(port)
70 _destinations.insert(address);
81 if (_interfaces.find(net) != _interfaces.end())
return;
84 _interfaces.insert(net);
92 if ((addr.family() != AF_INET) && (addr.family() != AF_INET6))
return;
95 if (addr.isLocal())
return;
107 for (std::set<ibrcommon::vaddress>::const_iterator it_addr = _destinations.begin(); it_addr != _destinations.end(); ++it_addr)
110 msock->
join(*it_addr, iface);
112 if (e.
error() == EADDRINUSE) {
114 }
else if (e.
error() == 92) {
131 _socket.add(msock, iface);
141 for (ibrcommon::socketset::iterator it = ifsocks.begin(); it != ifsocks.end(); ++it)
144 if (msock == NULL)
continue;
148 _socket.remove(msock);
170 for (ibrcommon::socketset::iterator it = ifsocks.begin(); it != ifsocks.end(); ++it)
173 if (msock == NULL)
continue;
176 _socket.remove(msock);
192 std::list<ibrcommon::vaddress> addrs = iface.getAddresses();
194 for (std::list<ibrcommon::vaddress>::const_iterator it = addrs.begin(); it != addrs.end(); ++it)
205 stringstream ss; ss << beacon;
206 const std::string data = ss.str();
213 for (ibrcommon::socketset::const_iterator iter = fds.begin(); iter != fds.end(); ++iter)
219 for (std::set<ibrcommon::vaddress>::const_iterator addr_it = _destinations.begin(); addr_it != _destinations.end(); ++addr_it)
227 sock.
sendto(data.c_str(), data.length(), 0, addr);
234 }
catch (
const std::bad_cast&) {
254 if (_interfaces.find(dialup.
iface) != _interfaces.end())
break;
257 _interfaces.insert(dialup.
iface);
278 if (_interfaces.find(dialup.
iface) == _interfaces.end())
break;
281 _interfaces.erase(dialup.
iface);
295 }
catch (std::bad_cast&) {
305 if (_interfaces.find(evt.
getInterface()) == _interfaces.end())
return;
353 std::set<sa_family_t> bound_set;
357 for (std::set<ibrcommon::vaddress>::const_iterator it_addr = _destinations.begin(); it_addr != _destinations.end(); ++it_addr)
362 sa_family_t fam = addr.
family();
364 if (bound_set.find(fam) == bound_set.end()) {
375 _socket.
add(msock, _virtual_mcast_iface);
381 bound_set.insert(fam);
395 for (std::set<ibrcommon::vinterface>::const_iterator it_iface = _interfaces.begin(); it_iface != _interfaces.end(); ++it_iface)
449 _socket.
select(&fds, NULL, NULL, &tv);
452 for (ibrcommon::socketset::const_iterator iter = fds.begin(); iter != fds.end(); ++iter)
460 ssize_t len = sock.
recvfrom(data, 1500, 0, sender);
470 if (beacon.isShort())
482 for (dtn::net::DiscoveryBeacon::service_list::iterator iter = services.begin(); iter != services.end(); ++iter) {
485 if ( (service.
getParameters().find(
"port=") != std::string::npos) &&
486 (service.
getParameters().find(
"ip=") == std::string::npos) ) {
501 if ( tv.tv_sec <= 0 && tv.tv_usec <= 0 )