libtins  4.0
loopback.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef TINS_LOOPBACK_H
31 #define TINS_LOOPBACK_H
32 
33 #include <tins/pdu.h>
34 #include <tins/macros.h>
35 
36 namespace Tins {
37 
41 class TINS_API Loopback : public PDU {
42 public:
46  static const PDU::PDUType pdu_flag = PDU::LOOPBACK;
47 
53  Loopback();
54 
68  Loopback(const uint8_t* buffer, uint32_t total_sz);
69 
74  uint32_t family() const {
75  return family_;
76  }
77 
82  void family(uint32_t family_id);
83 
87  uint32_t header_size() const;
88 
93  PDUType pdu_type() const {
94  return pdu_flag;
95  }
96 
104  bool matches_response(const uint8_t* ptr, uint32_t total_sz) const;
105 
109  Loopback* clone() const {
110  return new Loopback(*this);
111  }
112  // Null/Loopback can only be sent in* BSD
113  #ifdef BSD
114 
117  void send(PacketSender& sender, const NetworkInterface& iface);
118  #endif // BSD
119 private:
120  void write_serialization(uint8_t* buffer, uint32_t total_sz);
121 
122  uint32_t family_;
123 };
124 
125 } // Tins
126 
127 #endif // TINS_LOOPBACK_H
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
Sends packets through a network interface.
Definition: packet_sender.h:116
uint32_t family() const
Getter for the family identifier.
Definition: loopback.h:74
Represents a Loopback PDU.
Definition: loopback.h:41
The Tins namespace.
Definition: address_range.h:38
Abstraction of a network interface.
Definition: network_interface.h:47
PDUType pdu_type() const
Getter for the PDU&#39;s type.
Definition: loopback.h:93
Loopback * clone() const
Definition: loopback.h:109
Base class for protocol data units.
Definition: pdu.h:107