00ed1a87ea07d99ec3c1cbfffb6433f95c4b6afb
[senf.git] / Socket / LLAddressing.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 /** \file
24     \brief LLSocketAddress and LLAddressingPolicy  inline non-template implementation
25  */
26
27 // Custom includes
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 prefix_ senf::LLSocketAddress::LLSocketAddress()
35 {
36     clear();
37 }
38
39 prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned protocol, std::string interface)
40 {
41     clear();
42     this->protocol(protocol);
43     this->interface(interface);
44 }
45
46 prefix_  senf::LLSocketAddress::LLSocketAddress(std::string interface)
47 {
48     clear();
49     this->interface(interface);
50 }
51
52 prefix_ void senf::LLSocketAddress::clear()
53 {
54     ::memset(&addr_,0,sizeof(addr_));
55     addr_.sll_family = AF_PACKET;
56 }
57
58 prefix_ unsigned senf::LLSocketAddress::protocol()
59     const
60 {
61     return ntohs(addr_.sll_protocol);
62 }
63
64 prefix_ unsigned senf::LLSocketAddress::arptype()
65     const
66 {
67     /** \todo make sure, that the value really is in network byte
68         order */
69     return ntohs(addr_.sll_hatype);
70 }
71
72 prefix_ unsigned senf::LLSocketAddress::pkttype()
73     const
74 {
75     /** \todo make sure, that the value really is in network byte
76         order */
77     return ntohs(addr_.sll_pkttype);
78 }
79
80 prefix_ senf::LLSocketAddress::LLAddress senf::LLSocketAddress::address()
81     const
82 {
83     return LLAddress(&addr_.sll_addr[0], &addr_.sll_addr[addr_.sll_halen]);
84 }
85
86 prefix_ void senf::LLSocketAddress::protocol(unsigned protocol)
87 {
88     addr_.sll_protocol = htons(protocol);
89 }
90
91 prefix_ struct sockaddr * senf::LLSocketAddress::sockaddr_p()
92 {
93     return reinterpret_cast<struct sockaddr *>(&addr_);
94 }
95
96 prefix_ struct sockaddr const * senf::LLSocketAddress::sockaddr_p()
97     const
98 {
99     return reinterpret_cast<struct sockaddr const *>(&addr_);
100 }
101
102 prefix_ unsigned senf::LLSocketAddress::sockaddr_len()
103     const
104 {
105     return sizeof(addr_);
106 }
107
108 ///////////////////////////////cci.e///////////////////////////////////////
109 #undef prefix_
110
111 \f
112 // Local Variables:
113 // mode: c++
114 // c-file-style: "senf"
115 // End: