X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Socket%2FProtocols%2FRaw%2FPacketSocketHandle.cc;h=d0f8e5ae99a41676236228c9923b8ecd1b3beb53;hb=1ad3873b372da6187b1fbc645bf276287d2efb54;hp=7250c8c46249213460a1df739d8df281da57d37c;hpb=6bb3fa3caaa41dab4d5b451ca27e70f9e55e49d6;p=senf.git diff --git a/Socket/Protocols/Raw/PacketSocketHandle.cc b/Socket/Protocols/Raw/PacketSocketHandle.cc index 7250c8c..d0f8e5a 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.cc +++ b/Socket/Protocols/Raw/PacketSocketHandle.cc @@ -25,7 +25,7 @@ */ #include "PacketSocketHandle.hh" -#include "PacketSocketHandle.ih" +//#include "PacketSocketHandle.ih" // Custom includes #include @@ -50,8 +50,8 @@ prefix_ void senf::PacketProtocol::init_client(SocketType type, int protocol) protocol = ETH_P_ALL; int sock = ::socket(PF_PACKET, socktype, htons(protocol)); if (sock < 0) - throw SystemException(errno); - body().fd(sock); + throwErrno(); + fd(sock); } prefix_ std::auto_ptr senf::PacketProtocol::clone() @@ -63,11 +63,11 @@ prefix_ std::auto_ptr senf::PacketProtocol::clone() prefix_ unsigned senf::PacketProtocol::available() const { - if (! body().readable()) + if (! fh().readable()) return 0; - ssize_t l = ::recv(body().fd(),0,0,MSG_PEEK | MSG_TRUNC); + ssize_t l = ::recv(fd(),0,0,MSG_PEEK | MSG_TRUNC); if (l < 0) - throw SystemException(errno); + throwErrno(); return l; } @@ -77,20 +77,37 @@ prefix_ bool senf::PacketProtocol::eof() return false; } -prefix_ void senf::PacketProtocol::do_mc_i(std::string interface, - detail::LLAddressCopier const & copier, bool add) +namespace { + + void do_mc(int fd, std::string const & interface, senf::MACAddress address, bool add) + { + struct packet_mreq mreq; + mreq.mr_ifindex = ::if_nametoindex(interface.c_str()); + if (mreq.mr_ifindex == 0) + senf::throwErrno(EINVAL); + mreq.mr_type = PACKET_MR_MULTICAST; + mreq.mr_alen = 6; + std::copy(address.begin(), address.end(), &mreq.mr_address[0]); + if (::setsockopt(fd, SOL_PACKET, + add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP, + &mreq, sizeof(mreq)) < 0) + senf::throwErrno(); + } + +} + +prefix_ void senf::PacketProtocol::mcAdd(std::string const & interface, + MACAddress const & address) + const +{ + do_mc(fd(),interface,address,true); +} + +prefix_ void senf::PacketProtocol::mcDrop(std::string const & interface, + MACAddress const & address) const { - struct packet_mreq mreq; - mreq.mr_ifindex = ::if_nametoindex(interface.c_str()); - if (mreq.mr_ifindex == 0) - throw SystemException(EINVAL); - mreq.mr_type = PACKET_MR_MULTICAST; - mreq.mr_alen = copier(&mreq.mr_address[0]); - if (::setsockopt(body().fd(),SOL_PACKET, - add ? PACKET_ADD_MEMBERSHIP : PACKET_DROP_MEMBERSHIP, - &mreq, sizeof(mreq)) < 0) - throw SystemException(errno); + do_mc(fd(),interface,address,false); } ///////////////////////////////cc.e////////////////////////////////////////