Console: Implement short-option and non-option parsing
[senf.git] / 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_ void senf::LLSocketAddress::clear()
35 {
36     ::memset(&addr_,0,sizeof(addr_));
37     addr_.sll_family = AF_PACKET;
38 }
39
40 prefix_ void senf::LLSocketAddress::address(MACAddress const & addr)
41 {
42     std::copy(addr.begin(), addr.end(),&addr_.sll_addr[0]);
43 }
44
45 prefix_ senf::LLSocketAddress::LLSocketAddress()
46 {
47     clear();
48 }
49
50 prefix_ void senf::LLSocketAddress::protocol(unsigned prot)
51 {
52     addr_.sll_protocol = htons(prot);
53 }
54
55 prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned prot, std::string const & iface)
56 {
57     clear();
58     protocol(prot);
59     interface(iface);
60 }
61
62 prefix_ senf::LLSocketAddress::LLSocketAddress(std::string const &iface)
63 {
64     clear();
65     interface(iface);
66 }
67
68 prefix_ senf::LLSocketAddress::LLSocketAddress(MACAddress const & addr,
69                                                std::string const & iface)
70 {
71     clear();
72     address(addr);
73     interface(iface);
74 }
75
76 prefix_ unsigned senf::LLSocketAddress::protocol()
77     const
78 {
79     return ntohs(addr_.sll_protocol);
80 }
81
82 prefix_ unsigned senf::LLSocketAddress::arptype()
83     const
84 {
85     return ntohs(addr_.sll_hatype);
86 }
87
88 prefix_ senf::LLSocketAddress::PktType senf::LLSocketAddress::pkttype()
89     const
90 {
91     return PktType(ntohs(addr_.sll_pkttype));
92 }
93
94 prefix_ senf::MACAddress senf::LLSocketAddress::address()
95     const
96 {
97     return MACAddress::from_data(&addr_.sll_addr[0]);
98 }
99
100 prefix_ struct sockaddr * senf::LLSocketAddress::sockaddr_p()
101 {
102     return reinterpret_cast<struct sockaddr *>(&addr_);
103 }
104
105 prefix_ struct sockaddr const * senf::LLSocketAddress::sockaddr_p()
106     const
107 {
108     return reinterpret_cast<struct sockaddr const *>(&addr_);
109 }
110
111 prefix_ unsigned senf::LLSocketAddress::sockaddr_len()
112     const
113 {
114     return sizeof(addr_);
115 }
116
117 prefix_ std::ostream & senf::operator<<(std::ostream & os, LLSocketAddress const & llAddr)
118 {
119     // TODO: expose more bytes from sockaddr_ll addr_
120     os << "[some LLSocketAddress]";
121     return os;
122 }
123
124 ///////////////////////////////cci.e///////////////////////////////////////
125 #undef prefix_
126
127 \f
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"
135 // comment-column: 40
136 // End: