00001 // $Id: INetSocketProtocol.cc 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2006 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #include "INetSocketProtocol.hh" 00027 //#include "INetSocketProtocol.ih" 00028 00029 // Custom includes 00030 #include <sys/socket.h> 00031 #include <netinet/in.h> 00032 #include <net/if.h> 00033 #include <senf/Utils/Exception.hh> 00034 00035 //#include "INetSocketProtocol.mpp" 00036 #define prefix_ 00037 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00038 00039 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00040 // senf::INetSocketProtocol 00041 00042 prefix_ void senf::INetSocketProtocol::bindInterface(std::string const & iface) 00043 const 00044 { 00045 if (::setsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface.c_str(), iface.size()) < 0) 00046 SENF_THROW_SYSTEM_EXCEPTION("::setsockopt(SO_BINDTODEVICE)"); 00047 } 00048 00049 prefix_ std::string senf::INetSocketProtocol::bindInterface() 00050 { 00051 char iface[IFNAMSIZ]; 00052 socklen_t size (sizeof(iface)); 00053 ::memset(iface, 0, sizeof(iface)); 00054 if (::getsockopt(fd(), SOL_SOCKET, SO_BINDTODEVICE, iface, &size) < 0) 00055 SENF_THROW_SYSTEM_EXCEPTION("::getsockopt(SO_BINDTODEVICE)"); 00056 iface[size < IFNAMSIZ ? size : IFNAMSIZ-1] = 0; 00057 return iface; 00058 } 00059 00060 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00061 // senf::IPv4SocketProtocol 00062 00063 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00064 // senf::IPv6SocketProtocol 00065 00066 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00067 #undef prefix_ 00068 //#include "INetSocketProtocol.mpp" 00069 00070 00071 // Local Variables: 00072 // mode: c++ 00073 // fill-column: 100 00074 // c-file-style: "senf" 00075 // indent-tabs-mode: nil 00076 // ispell-local-dictionary: "american" 00077 // compile-command: "scons -u test" 00078 // comment-column: 40 00079 // End: