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