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.
23 // Definition of non-inline non-template functions
25 #include "INetAddressing.hh"
26 //#include "INetAddressing.ih"
31 #include <sys/socket.h>
32 #include <boost/lexical_cast.hpp>
34 //#include "INetAddressing.mpp"
36 ///////////////////////////////cc.p////////////////////////////////////////
38 prefix_ satcom::lib::INet4Address::INet4Address(std::string host, unsigned port)
41 // TODO: gethostbyname einbauen
42 if (::inet_aton(host.c_str(), &addr_.sin_addr) == 0)
43 throw InvalidINetAddressException();
44 addr_.sin_port = htons(port);
47 prefix_ std::string satcom::lib::INet4Address::str()
51 s << host() << ':' << port();
55 prefix_ void satcom::lib::INet4Address::clear()
57 ::memset(&addr_,0,sizeof(addr_));
58 addr_.sin_family = AF_INET;
61 prefix_ void satcom::lib::INet4Address::assignString(std::string address)
64 // TODO: gethostbyname einbauen
65 unsigned i = address.find(':');
66 if (i == std::string::npos)
67 throw InvalidINetAddressException();
68 if (::inet_aton(std::string(address,0,i).c_str(), &addr_.sin_addr) == 0)
69 throw InvalidINetAddressException();
71 // Replace lexical_cast with strtoul ?
72 addr_.sin_port = htons(boost::lexical_cast< ::u_int16_t >(std::string(address,i+1)));
74 catch (boost::bad_lexical_cast const & ex) {
75 throw InvalidINetAddressException();
79 ///////////////////////////////cc.e////////////////////////////////////////
81 //#include "INetAddressing.mpp"
86 // c-file-style: "satcom"