memset(mac_, 0, sizeof(mac_));
}
+void
+IfaceMgr::Iface::closeSockets() {
+ for (SocketCollection::iterator sock = sockets_.begin();
+ sock != sockets_.end(); ++sock) {
+ cout << "Closing socket " << sock->sockfd_ << endl;
+ close(sock->sockfd_);
+ }
+ sockets_.clear();
+}
+
std::string
IfaceMgr::Iface::getFullName() const {
ostringstream tmp;
void IfaceMgr::closeSockets() {
for (IfaceCollection::iterator iface = ifaces_.begin();
iface != ifaces_.end(); ++iface) {
-
- for (SocketCollection::iterator sock = iface->sockets_.begin();
- sock != iface->sockets_.end(); ++sock) {
- cout << "Closing socket " << sock->sockfd_ << endl;
- close(sock->sockfd_);
- }
- iface->sockets_.clear();
+ iface->closeSockets();
}
-
}
IfaceMgr::~IfaceMgr() {
struct sockaddr_in6 addr6;
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
- addr6.sin6_port = htons(port);
- if (addr.toText() != "::1")
+ addr6.sin6_port = htons(port); if (addr.toText() != "::1")
addr6.sin6_scope_id = if_nametoindex(iface.getName().c_str());
memcpy(&addr6.sin6_addr,
bool
IfaceMgr::send(const Pkt4Ptr& pkt)
{
-
Iface* iface = getIface(pkt->getIface());
if (!iface) {
isc_throw(BadValue, "Unable to send Pkt4. Invalid interface ("
/// provided set to indicated which sockets have something to read.
for (iface = ifaces_.begin(); iface != ifaces_.end(); ++iface) {
- for (SocketCollection::const_iterator s = iface->sockets_.begin();
- s != iface->sockets_.end(); ++s) {
+ const SocketCollection& socket_collection = iface->getSockets();
+ for (SocketCollection::const_iterator s = socket_collection.begin();
+ s != socket_collection.end(); ++s) {
// Only deal with IPv4 addresses.
if (s->addr_.getFamily() == AF_INET) {
// Let's find out which interface/socket has the data
for (iface = ifaces_.begin(); iface != ifaces_.end(); ++iface) {
- for (SocketCollection::const_iterator s = iface->sockets_.begin();
- s != iface->sockets_.end(); ++s) {
+ const SocketCollection& socket_collection = iface->getSockets();
+ for (SocketCollection::const_iterator s = socket_collection.begin();
+ s != socket_collection.end(); ++s) {
if (FD_ISSET(s->sockfd_, &sockets)) {
candidate = &(*s);
break;
IfaceCollection::const_iterator iface = ifaces_.begin();
const SocketInfo* candidate = 0;
while (iface != ifaces_.end()) {
- for (SocketCollection::const_iterator s = iface->sockets_.begin();
- s != iface->sockets_.end(); ++s) {
+ const SocketCollection& socket_collection = iface->getSockets();
+ for (SocketCollection::const_iterator s = socket_collection.begin();
+ s != socket_collection.end(); ++s) {
if (s->addr_.getFamily() != AF_INET6) {
continue;
}
<< pkt.getIface());
}
+ const SocketCollection& socket_collection = iface->getSockets();
SocketCollection::const_iterator s;
- for (s = iface->sockets_.begin(); s != iface->sockets_.end(); ++s) {
+ for (s = socket_collection.begin(); s != socket_collection.end(); ++s) {
if ((s->family_ == AF_INET6) &&
(!s->addr_.getAddress().to_v6().is_multicast())) {
- return (s->sockfd_);
+ return (s->sockfd_);t
}
/// @todo: Add more checks here later. If remote address is
/// not link-local, we can't use link local bound socket
<< pkt.getIface());
}
+ const SocketCollection& socket_collection = iface->getSockets();
SocketCollection::const_iterator s;
- for (s = iface->sockets_.begin(); s != iface->sockets_.end(); ++s) {
+ for (s = socket_collection.begin(); s != socket_collection.end(); ++s) {
if (s->family_ == AF_INET) {
return (s->sockfd_);
}
/// @param ifindex interface index (unique integer identifier)
Iface(const std::string& name, int ifindex);
+ /// @brief Closes all open sockets on interface
+ void closeSockets();
+
/// @brief Returns full interface name as "ifname/ifindex" string.
///
/// @return string with interface name
/// @return true if there was such socket, false otherwise
bool delSocket(uint16_t sockfd);
+ /// @brief Returns collection of all sockets added to interface.
+ ///
+ /// When new socket is created with @ref IfaceMgr::openSocket
+ /// it is added to sockets collection on particular interface.
+ /// If socket is opened by other means (e.g. function that does
+ /// not use @ref IfaceMgr::openSocket) it will not be available
+ /// in this collection. Note that functions like
+ /// @ref IfaceMgr::openSocketFromIface use
+ /// @ref IfaceMgr::openSocket internally.
+ ///
+ /// @return collection of sockets added to interface
+ const SocketCollection& getSockets() const { return sockets_; }
+
+ protected:
/// socket used to sending data
- /// TODO: this should be protected
SocketCollection sockets_;
- protected:
/// network interface name
std::string name_;