0431630fa4e69b6ab367fe52e3e39d5a8f453c96
[senf.git] / senf / Socket / Protocols / Raw / LLAddressing.cci
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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     : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
36 {}
37
38 prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned prot, std::string const & iface)
39     : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
40 {
41     protocol(prot);
42     interface(iface);
43 }
44
45 prefix_ senf::LLSocketAddress::LLSocketAddress(std::string const &iface)
46     : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
47 {
48     interface(iface);
49 }
50
51 prefix_ senf::LLSocketAddress::LLSocketAddress(MACAddress const & addr,
52                                                std::string const & iface)
53     : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
54 {
55     address(addr);
56     interface(iface);
57 }
58
59 prefix_ senf::LLSocketAddress::LLSocketAddress(const LLSocketAddress& other)
60     : BSDSocketAddress (other)
61 {}
62
63 prefix_ senf::LLSocketAddress& senf::LLSocketAddress::operator=(const LLSocketAddress& other)
64 {
65     BSDSocketAddress::operator=(other);
66     return *this;
67 }
68
69 prefix_ unsigned senf::LLSocketAddress::protocol()
70     const
71 {
72     return ntohs(addr_.sll_protocol);
73 }
74
75 prefix_ void senf::LLSocketAddress::protocol(unsigned prot)
76 {
77     addr_.sll_protocol = htons(prot);
78 }
79
80 prefix_ unsigned senf::LLSocketAddress::arptype()
81     const
82 {
83     return ntohs(addr_.sll_hatype);
84 }
85
86 prefix_ senf::LLSocketAddress::PktType senf::LLSocketAddress::pkttype()
87     const
88 {
89     return PktType(ntohs(addr_.sll_pkttype));
90 }
91
92 prefix_ senf::MACAddress senf::LLSocketAddress::address()
93     const
94 {
95     return MACAddress::from_data(&addr_.sll_addr[0]);
96 }
97
98 prefix_ void senf::LLSocketAddress::address(MACAddress const & addr)
99 {
100     std::copy(addr.begin(), addr.end(), &addr_.sll_addr[0]);
101 }
102
103 ///////////////////////////////cci.e///////////////////////////////////////
104 #undef prefix_
105
106 \f
107 // Local Variables:
108 // mode: c++
109 // fill-column: 100
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"
114 // comment-column: 40
115 // End: