A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-raw-socket-impl.h
Go to the documentation of this file.
1#ifndef IPV4_RAW_SOCKET_IMPL_H
2#define IPV4_RAW_SOCKET_IMPL_H
3
4#include "ipv4-header.h"
5#include "ipv4-interface.h"
6#include "ipv4-route.h"
7
8#include "ns3/socket.h"
9
10#include <list>
11
12namespace ns3
13{
14
15class NetDevice;
16class Node;
17
18/**
19 * \ingroup socket
20 * \ingroup ipv4
21 *
22 * \brief IPv4 raw socket.
23 *
24 * A RAW Socket typically is used to access specific IP layers not usually
25 * available through L4 sockets, e.g., ICMP. The implementer should take
26 * particular care to define the Ipv4RawSocketImpl Attributes, and in
27 * particular the Protocol attribute.
28 */
30{
31 public:
32 /**
33 * \brief Get the type ID of this class.
34 * \return type ID
35 */
36 static TypeId GetTypeId();
37
39
40 /**
41 * \brief Set the node associated with this socket.
42 * \param node node to set
43 */
44 void SetNode(Ptr<Node> node);
45
46 Socket::SocketErrno GetErrno() const override;
47
48 /**
49 * \brief Get socket type (NS3_SOCK_RAW)
50 * \return socket type
51 */
52 Socket::SocketType GetSocketType() const override;
53
54 Ptr<Node> GetNode() const override;
55 int Bind(const Address& address) override;
56 int Bind() override;
57 int Bind6() override;
58 int GetSockName(Address& address) const override;
59 int GetPeerName(Address& address) const override;
60 int Close() override;
61 int ShutdownSend() override;
62 int ShutdownRecv() override;
63 int Connect(const Address& address) override;
64 int Listen() override;
65 uint32_t GetTxAvailable() const override;
66 int Send(Ptr<Packet> p, uint32_t flags) override;
67 int SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddress) override;
68 uint32_t GetRxAvailable() const override;
69 Ptr<Packet> Recv(uint32_t maxSize, uint32_t flags) override;
70 Ptr<Packet> RecvFrom(uint32_t maxSize, uint32_t flags, Address& fromAddress) override;
71
72 /**
73 * \brief Set protocol field.
74 * \param protocol protocol to set
75 */
76 void SetProtocol(uint16_t protocol);
77
78 /**
79 * \brief Forward up to receive method.
80 * \param p packet
81 * \param ipHeader IPv4 header
82 * \param incomingInterface incoming interface
83 * \return true if forwarded, false otherwise
84 */
85 bool ForwardUp(Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4Interface> incomingInterface);
86 bool SetAllowBroadcast(bool allowBroadcast) override;
87 bool GetAllowBroadcast() const override;
88
89 private:
90 void DoDispose() override;
91
92 /**
93 * \struct Data
94 * \brief IPv4 raw data and additional information.
95 */
96 struct Data
97 {
98 Ptr<Packet> packet; /**< Packet data */
99 Ipv4Address fromIp; /**< Source address */
100 uint16_t fromProtocol; /**< Protocol used */
101 };
102
103 mutable Socket::SocketErrno m_err; //!< Last error number.
104 Ptr<Node> m_node; //!< Node
105 Ipv4Address m_src; //!< Source address.
106 Ipv4Address m_dst; //!< Destination address.
107 uint16_t m_protocol; //!< Protocol.
108 std::list<Data> m_recv; //!< Packet waiting to be processed.
109 bool m_shutdownSend; //!< Flag to shutdown send capability.
110 bool m_shutdownRecv; //!< Flag to shutdown receive capability.
111 uint32_t m_icmpFilter; //!< ICMPv4 filter specification
112 bool m_iphdrincl; //!< Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
113};
114
115} // namespace ns3
116
117#endif /* IPV4_RAW_SOCKET_IMPL_H */
a polymophic address class
Definition: address.h:101
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Packet header for IPv4.
Definition: ipv4-header.h:34
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
Socket::SocketType GetSocketType() const override
Get socket type (NS3_SOCK_RAW)
int GetPeerName(Address &address) const override
Get the peer address of a connected socket.
Ipv4Address m_src
Source address.
std::list< Data > m_recv
Packet waiting to be processed.
int Bind() override
Allocate a local IPv4 endpoint for this socket.
int Send(Ptr< Packet > p, uint32_t flags) override
Send data (or dummy data) to the remote host.
Ipv4Address m_dst
Destination address.
void DoDispose() override
Destructor implementation.
int Close() override
Close a socket.
int Listen() override
Listen for incoming connections.
bool GetAllowBroadcast() const override
Query whether broadcast datagram transmissions are allowed.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
Socket::SocketErrno m_err
Last error number.
void SetProtocol(uint16_t protocol)
Set protocol field.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
uint16_t m_protocol
Protocol.
Socket::SocketErrno GetErrno() const override
Get last error number.
int Connect(const Address &address) override
Initiate a connection to a remote host.
int Bind6() override
Allocate a local IPv6 endpoint for this socket.
bool SetAllowBroadcast(bool allowBroadcast) override
Configure whether broadcast datagram transmissions are allowed.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
uint32_t m_icmpFilter
ICMPv4 filter specification.
bool m_shutdownRecv
Flag to shutdown receive capability.
static TypeId GetTypeId()
Get the type ID of this class.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
bool m_shutdownSend
Flag to shutdown send capability.
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
int GetSockName(Address &address) const override
Get socket address.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A low-level Socket API based loosely on the BSD Socket API.
Definition: socket.h:68
Ptr< Packet > Recv()
Read a single packet from the socket.
Definition: socket.cc:174
SocketType
Enumeration of the possible socket types.
Definition: socket.h:107
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IPv4 raw data and additional information.
Ipv4Address fromIp
Source address.
uint16_t fromProtocol
Protocol used.
Ptr< Packet > packet
Packet data.