Commit c4901d0f authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[1957] Added new open socket methods.

parent 6f914bb2
......@@ -23,6 +23,7 @@
#include <dhcp/dhcp6.h>
#include <dhcp/iface_mgr.h>
#include <exceptions/exceptions.h>
#include <asiolink/io_error.h>
#include <util/io/pktinfo_utilities.h>
using namespace std;
......@@ -393,6 +394,78 @@ int IfaceMgr::openSocket(const std::string& ifname, const IOAddress& addr,
}
}
int IfaceMgr::openSocketFromIface(const std::string& ifname, const uint16_t port, const uint8_t family) {
int sock = 0;
for (IfaceCollection::iterator iface=ifaces_.begin();
iface!=ifaces_.end();
++iface) {
if ((iface->getFullName() != ifname) &&
(iface->getName() != ifname)) {
continue;
}
AddressCollection addrs = iface->getAddresses();
for (AddressCollection::iterator addr= addrs.begin();
addr != addrs.end();
++addr) {
// skip IPv4 addresses
if (addr->getFamily() != family) {
continue;
}
sock = openSocket(iface->getName(), *addr, port);
if (sock<0) {
cout << "Failed to open unicast socket." << endl;
}
return (sock);
}
}
return (sock);
}
int IfaceMgr::openSocketFromAddr(const std::string& addr_name, const uint16_t port) {
int sock = 0;
for (IfaceCollection::iterator iface=ifaces_.begin();
iface!=ifaces_.end();
++iface) {
AddressCollection addrs = iface->getAddresses();
for (AddressCollection::iterator addr = addrs.begin();
addr != addrs.end();
++addr) {
try {
IOAddress searched_addr(addr_name);
if (addr->getAddress() != searched_addr.getAddress()) {
continue;
}
} catch (const isc::asiolink::IOError& e) {
cout << "Failed to open socket from address: " << e.what() << endl;
return (sock);
}
sock = openSocket(iface->getName(), *addr, port);
if (sock<0) {
cout << "Failed to open unicast socket." << endl;
}
return (sock);
}
}
return (sock);
}
/*int IfaceMgr::openSocketFromRemoteAddr(const std::string& remote_addr_name,
const uint16_t port,
const uint8_t family) {
return 0;
}*/
int IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, uint16_t port) {
cout << "Creating UDP4 socket on " << iface.getFullName()
......
......@@ -375,6 +375,15 @@ public:
int openSocket(const std::string& ifname,
const isc::asiolink::IOAddress& addr, const uint16_t port);
int openSocketFromIface(const std::string& ifname, const uint16_t port,
const uint8_t family);
int openSocketFromAddr(const std::string& addr_name, const uint16_t port);
int openSocketFromRemoteAddr(const std::string& remote_addr_name,
const uint16_t port,
const uint8_t family);
/// Opens IPv6 sockets on detected interfaces.
///
/// Will throw exception if socket creation fails.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment