LLAddressing.hh
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 
18 #ifndef HH_SENF_Socket_Protocols_Raw_LLAddressing_
19 #define HH_SENF_Socket_Protocols_Raw_LLAddressing_ 1
20 
21 // Custom includes
22 #include <sys/socket.h>
23 #include <linux/if_packet.h>
26 #include "MACAddress.hh"
27 
28 //#include "LLAddressing.mpp"
29 //#include "LLAddressing.ih"
30 //-/////////////////////////////////////////////////////////////////////////////////////////////////
31 
32 namespace senf {
33 
35  //\{
36 
47  : public BSDSocketAddress
48  {
49  public:
50  static short const addressFamily = AF_PACKET;
51 
56  enum PktType { Undefined = 0
57  , Host = PACKET_HOST
58  , Broadcast = PACKET_BROADCAST
59  , Multicast = PACKET_MULTICAST
61  , OtherHost = PACKET_OTHERHOST
62  , Outgoing = PACKET_OUTGOING
63  };
64 
65  //-////////////////////////////////////////////////////////////////////////
67  //\{
68 
69  LLSocketAddress();
70  explicit LLSocketAddress(unsigned proto, std::string const & iface="");
72 
76  explicit LLSocketAddress(std::string const & iface);
78 
84  // This constructor is for sending packets
85  explicit LLSocketAddress(MACAddress const & addr, std::string const & iface="");
87 
95  LLSocketAddress(LLSocketAddress const & other);
97 
98  //\}
99  //-////////////////////////////////////////////////////////////////////////
100 
101  MACAddress address() const;
102  std::string interface() const;
103  unsigned protocol() const;
104 
105  unsigned arptype() const;
106  PktType pkttype() const;
107 
108  // The mutating interface is purposely restricted to allow only
109  // changing those members, which are sensible to be changed.
110 
111  void address(MACAddress const & addr);
112  void interface(std::string const & iface);
113 
115  void protocol(unsigned prot);
116 
119 
120  private:
121  struct ::sockaddr_ll addr_;
122  };
123 
124  //\}
125 
127  //\{
128 
143  : public BSDAddressingPolicy,
144  private BSDAddressingPolicyMixin<LLSocketAddress>
145  {
147 
151  };
152 
153  //\}
154 
158  std::ostream & operator<<(std::ostream & os, LLSocketAddress const & llAddr);
159 }
160 
161 //-/////////////////////////////////////////////////////////////////////////////////////////////////
162 #include "LLAddressing.cci"
163 //#include "LLAddressing.ct"
164 //#include "LLAddressing.cti"
165 //#include "LLAddressing.mpp"
166 #endif
167 
168 
169 // Local Variables:
170 // mode: c++
171 // fill-column: 100
172 // c-file-style: "senf"
173 // indent-tabs-mode: nil
174 // ispell-local-dictionary: "american"
175 // compile-command: "scons -u test"
176 // comment-column: 40
177 // End:
MACAddress public header.
Addressing policy supporting link-local addressing.
Ethernet MAC address.
Definition: MACAddress.hh:72
BSDSocketAddress public header.
std::string interface() const
Return interface name.
Definition: LLAddressing.cc:34
std::ostream & operator<<(std::ostream &os, LLSocketAddress const &llAddr)
Write link layer address.
LLSocketAddress Address
Link local address.
Definition: LLAddressing.hh:46
static short const addressFamily
Definition: LLAddressing.hh:50
socklen_t const * socklen_p() const
MACAddress address() const
Return address.
LLSocketAddress & operator=(LLSocketAddress const &other)
Socket addressing, BSD style.
struct sockaddr const * sockaddr_p() const
PktType
Valid pkttype() values.
Definition: LLAddressing.hh:56
PktType pkttype() const
Return type of packet.
BSDAddressingPolicyMixin public header.
Template for generic AddressingPolicy implementation based on the BSD socket API. ...
unsigned protocol() const
Return address protocol (ethertype)
LLSocketAddress()
Create empty address.
unsigned arptype() const
Return the arptype field (ARP hardware type)