Renamed namespaces satcom::lib and satcom::pkf to senf
[senf.git] / Socket / INetAddressing.cci
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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.
12 //
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.
17 //
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.
22
23 // Definition of inline non-template functions
24
25 // Custom includes
26 #include <arpa/inet.h>
27
28 #define prefix_ inline
29 ///////////////////////////////cci.p///////////////////////////////////////
30
31 prefix_ senf::INet4Address::INet4Address()
32 {
33     clear();
34 }
35
36 prefix_ senf::INet4Address::INet4Address(char const * address)
37 {
38     assignString(address);
39 }
40
41 prefix_ senf::INet4Address::INet4Address(std::string address)
42 {
43     assignString(address);
44 }
45
46 prefix_ bool senf::INet4Address::operator==(INet4Address const & other)
47     const
48 {
49     return addr_.sin_port == other.addr_.sin_port && 
50         addr_.sin_addr.s_addr == other.addr_.sin_addr.s_addr;
51 }
52
53 prefix_ std::string senf::INet4Address::host()
54     const
55 {
56     // FIXME: thread safety?
57     return std::string(::inet_ntoa(addr_.sin_addr));
58 }
59
60 prefix_ unsigned senf::INet4Address::port()
61     const
62 {
63     return ntohs(addr_.sin_port);
64 }
65
66 prefix_ struct sockaddr * senf::INet4Address::sockaddr_p()
67 {
68     return reinterpret_cast<struct sockaddr *>(&addr_);
69 }
70
71 prefix_ struct sockaddr const * senf::INet4Address::sockaddr_p()
72     const
73 {
74     return reinterpret_cast<struct sockaddr const *>(&addr_);
75 }
76
77 prefix_ unsigned senf::INet4Address::sockaddr_len()
78     const
79 {
80     return sizeof(addr_);
81 }
82
83 prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const & addr)
84 {
85     os << addr.str();
86     return os;
87 }
88
89 ///////////////////////////////cci.e///////////////////////////////////////
90 #undef prefix_
91
92 \f
93 // Local Variables:
94 // mode: c++
95 // c-file-style: "senf"
96 // End: