4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief INet[46]Address and INet[46]AddressingPolicy non-inline non-template implementation
27 #include "INetAddressing.hh"
28 //#include "INetAddressing.ih"
33 #include <sys/socket.h>
34 #include <boost/lexical_cast.hpp>
36 //#include "INetAddressing.mpp"
38 ///////////////////////////////cc.p////////////////////////////////////////
40 prefix_ senf::INet4Address::INet4Address(std::string host, unsigned port)
43 /** \todo gethostbyname support */
44 if (::inet_aton(host.c_str(), &addr_.sin_addr) == 0)
45 throw InvalidINetAddressException();
46 addr_.sin_port = htons(port);
49 prefix_ std::string senf::INet4Address::str()
53 s << host() << ':' << port();
57 prefix_ void senf::INet4Address::clear()
59 ::memset(&addr_,0,sizeof(addr_));
60 addr_.sin_family = AF_INET;
63 prefix_ void senf::INet4Address::assignString(std::string address)
66 unsigned i = address.find(':');
67 if (i == std::string::npos)
68 throw InvalidINetAddressException();
69 // The temporary string in the next expr is guaranteed to live
70 // until end-of-statement
71 if (::inet_aton(std::string(address,0,i).c_str(), &addr_.sin_addr) == 0)
72 throw InvalidINetAddressException();
74 // Replace lexical_cast with strtoul ?
75 addr_.sin_port = htons(boost::lexical_cast< ::u_int16_t >(std::string(address,i+1)));
77 catch (boost::bad_lexical_cast const &) {
78 throw InvalidINetAddressException();
82 ///////////////////////////////cc.e////////////////////////////////////////
84 //#include "INetAddressing.mpp"
89 // c-file-style: "senf"