LLAddressing.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief LLSocketAddress and LLAddressingPolicy inline non-template implementation
16  */
17 
18 // Custom includes
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 prefix_ senf::LLSocketAddress::LLSocketAddress()
26  : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
27 {}
28 
29 prefix_ senf::LLSocketAddress::LLSocketAddress(unsigned prot, std::string const & iface)
30  : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
31 {
32  protocol(prot);
33  interface(iface);
34 }
35 
36 prefix_ senf::LLSocketAddress::LLSocketAddress(std::string const &iface)
37  : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
38 {
39  interface(iface);
40 }
41 
42 prefix_ senf::LLSocketAddress::LLSocketAddress(MACAddress const & addr,
43  std::string const & iface)
44  : BSDSocketAddress (sizeof(sockaddr_ll), AF_PACKET)
45 {
46  address(addr);
47  interface(iface);
48 }
49 
50 prefix_ senf::LLSocketAddress::LLSocketAddress(const LLSocketAddress& other)
51  : BSDSocketAddress (other)
52 {}
53 
54 prefix_ senf::LLSocketAddress& senf::LLSocketAddress::operator=(const LLSocketAddress& other)
55 {
56  BSDSocketAddress::operator=(other);
57  return *this;
58 }
59 
60 prefix_ unsigned senf::LLSocketAddress::protocol()
61  const
62 {
63  return ntohs(addr_.sll_protocol);
64 }
65 
66 prefix_ void senf::LLSocketAddress::protocol(unsigned prot)
67 {
68  addr_.sll_protocol = htons(prot);
69 }
70 
71 prefix_ unsigned senf::LLSocketAddress::arptype()
72  const
73 {
74  return ntohs(addr_.sll_hatype);
75 }
76 
77 prefix_ senf::LLSocketAddress::PktType senf::LLSocketAddress::pkttype()
78  const
79 {
80  return PktType(ntohs(addr_.sll_pkttype));
81 }
82 
83 prefix_ senf::MACAddress senf::LLSocketAddress::address()
84  const
85 {
86  return MACAddress::from_data(&addr_.sll_addr[0]);
87 }
88 
89 prefix_ void senf::LLSocketAddress::address(MACAddress const & addr)
90 {
91  std::copy(addr.begin(), addr.end(), &addr_.sll_addr[0]);
92 }
93 
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #undef prefix_
96 
97 
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40
106 // End: