4d3131c5c01cd226c892ee3313fbf006224c9fcc
[senf.git] / Socket / Protocols / UN / UNAddressing.cc
1 // Copyright (C) 2007 
2 // Fraunhofer Institute for Open Communication Systems (FOKUS) 
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <dw6@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief UNAddressing non-inline non-template implementation */
23
24 #include "UNAddressing.hh"
25 //#include "UNAddressing.ih"
26
27 // Custom includes
28 #include <stdio.h>
29 #include <boost/operators.hpp>
30
31 #define prefix_
32 ///////////////////////////////cc.p////////////////////////////////////////
33
34 prefix_ senf::UNSocketAddress::UNSocketAddress()
35 {}
36
37 prefix_ senf::UNSocketAddress::UNSocketAddress(std::string p)
38 {
39     clear();
40     ::strncpy(addr_.sun_path, p.c_str(), sizeof(addr_.sun_path));
41     addr_.sun_path[sizeof(addr_.sun_path)-1] = 0;
42 }
43
44 prefix_ senf::UNSocketAddress fromString(std::string s) 
45 {
46     return senf::UNSocketAddress::UNSocketAddress(s);
47 }
48
49 prefix_ bool senf::UNSocketAddress::operator==(UNSocketAddress const & other)
50     const
51 {
52     return path() == other.path();
53 }
54
55 prefix_ std::string senf::UNSocketAddress::path()
56         const
57 {
58     return std::string(addr_.sun_path);
59 }
60
61 prefix_ bool senf::UNSocketAddress::boolean_test()
62     const
63 {
64     return addr_.sun_path[0] != 0;
65 }
66
67 prefix_ void senf::UNSocketAddress::clear()
68 {
69     ::memset(&addr_, 0, sizeof(addr_));
70     addr_.sun_family = AF_UNIX;
71 }
72
73 prefix_ sockaddr * senf::UNSocketAddress::sockaddr_p()
74 {
75     return reinterpret_cast <struct sockaddr  *> (&addr_); 
76 }
77
78 prefix_ sockaddr const  * senf::UNSocketAddress::sockaddr_p()
79     const
80 {
81     return reinterpret_cast <struct sockaddr const  *> (&addr_); 
82 }
83
84 prefix_ unsigned senf::UNSocketAddress::sockaddr_len()
85         const
86 {
87     return sizeof(addr_);
88 }
89
90 prefix_ std::ostream & operator<<(std::ostream & os,
91                                   senf::UNSocketAddress::UNSocketAddress const & addr)
92 {
93     os << addr.path();
94     return os;
95 }
96
97 ///////////////////////////////cc.e////////////////////////////////////////
98 #undef prefix_
99 //#include "UNAddressing.mpp"
100
101 \f
102 // Local Variables:
103 // mode: c++
104 // fill-column: 100
105 // comment-column: 40
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"
110 // End: