9a98b10b0c39c4a474f6449448b3a64b26f7b7c7
[senf.git] / Socket / Protocols / UN / UNAddressing.cc
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <david.wagner@fokus.fraunhofer.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 prefix_ senf::UNSocketAddress::UNSocketAddress(std::string p)
34 {
35         sockAddr.sun_family = AF_UNIX;
36         strcpy(sockAddr.sun_path, p.c_str());
37 }
38
39 prefix_ senf::UNSocketAddress fromString(std::string s) {
40     return senf::UNSocketAddress::UNSocketAddress(s);
41 }
42
43
44 prefix_ std::string senf::UNSocketAddress::path()
45         const
46 {
47     return std::string(sockAddr.sun_path);
48 }
49
50 prefix_ sockaddr_un senf::UNSocketAddress::sockaddr()
51 {
52     struct sockaddr_un out; 
53     out.sun_family = sockAddr.sun_family;
54     strncpy(out.sun_path, sockAddr.sun_path, sizeof( out.sun_path));
55     return out; 
56 }
57
58 prefix_ sockaddr * senf::UNSocketAddress::sockaddr_p()
59 {
60     return reinterpret_cast <struct sockaddr  *> (&sockAddr); 
61 }
62
63
64 prefix_ sockaddr const  * senf::UNSocketAddress::sockaddr_p()
65     const
66 {
67     return reinterpret_cast <struct sockaddr const  *> (&sockAddr); 
68 }
69
70 prefix_ unsigned senf::UNSocketAddress::sockaddr_len()
71         const
72 {
73     return sizeof(sockAddr);
74 }
75
76 prefix_ std::ostream & operator<<(std::ostream & os, senf::UNSocketAddress::UNSocketAddress const & addr){
77     os << addr.path();
78     return os;
79 }
80
81
82 ///////////////////////////////cc.e////////////////////////////////////////
83 #undef prefix_
84 //#include "UNAddressing.mpp"
85
86 \f
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // comment-column: 40
91 // c-file-style: "senf"
92 // indent-tabs-mode: nil
93 // ispell-local-dictionary: "american"
94 // compile-command: "scons -u test"
95 // End: