LLAddressing.cc
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 #include "LLAddressing.hh"
19 //#include "LLAddressing.ih"
20 
21 // Custom includes
22 #include <net/if.h>
23 #include <sys/socket.h>
24 
25 #include <boost/algorithm/string/classification.hpp>
26 #include <boost/algorithm/string/finder.hpp>
27 
29 
30 //#include "LLAddressing.mpp"
31 #define prefix_
32 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 
35  const
36 {
37  if (addr_.sll_ifindex == 0)
38  return std::string();
39  char name[IFNAMSIZ];
40  ::bzero(name, IFNAMSIZ);
41  if (! ::if_indextoname(addr_.sll_ifindex, name))
43  return std::string(name);
44 }
45 
46 prefix_ void senf::LLSocketAddress::interface(std::string const & iface)
47 {
48  if (iface.empty())
49  addr_.sll_ifindex = 0;
50  else {
51  addr_.sll_ifindex = if_nametoindex(iface.c_str());
52  if (addr_.sll_ifindex == 0)
53  throw UnknownInterfaceException(iface);
54  }
55 }
56 
57 prefix_ std::ostream & senf::operator<<(std::ostream & os, LLSocketAddress const & llAddr)
58 {
59  os << "[" << llAddr.address()
60  << '%' << llAddr.interface()
61  << ' ' << llAddr.protocol()
62  << ' ' << llAddr.arptype()
63  << ( llAddr.pkttype() == senf::LLSocketAddress::Host ? " Host" :
64  llAddr.pkttype() == senf::LLSocketAddress::Broadcast ? " Broadcast" :
65  llAddr.pkttype() == senf::LLSocketAddress::Multicast ? " Multicast" :
66  llAddr.pkttype() == senf::LLSocketAddress::OtherHost ? " OtherHost" :
67  llAddr.pkttype() == senf::LLSocketAddress::Outgoing ? " Outgoing" :
68  llAddr.pkttype() == senf::LLSocketAddress::Broadcast ? "Broadcast" : "" )
69  << "]";
70  return os;
71 }
72 
73 //-/////////////////////////////////////////////////////////////////////////////////////////////////
74 #undef prefix_
75 //#include "LLAddressing.mpp"
76 
77 
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"
85 // comment-column: 40
86 // End:
std::ostream & operator<<(std::ostream &os, Packet const &packet)
std::string interface() const
Return interface name.
Definition: LLAddressing.cc:34
Link local address.
Definition: LLAddressing.hh:46
LLSocketAddress and LLAddressingPolicy public header.
AddressExceptions public header.
MACAddress address() const
Return address.
PktType pkttype() const
Return type of packet.
unspecified_keyword_type name
#define prefix_
Definition: LLAddressing.cc:31
unsigned protocol() const
Return address protocol (ethertype)
unsigned arptype() const
Return the arptype field (ARP hardware type)