2 #include <netinet/in.h>
3 #include <sys/socket.h>
8 #include "ns3/ipv4-packet-info-tag.h"
9 #include "ns3/inet-socket-address.h"
11 #include "ns3/packet.h"
12 #include "ns3/uinteger.h"
13 #include "ns3/boolean.h"
27 .AddAttribute (
"Protocol",
"Protocol number to match.",
30 MakeUintegerChecker<uint16_t> ())
31 .AddAttribute (
"IcmpFilter",
32 "Any icmp header whose type field matches a bit in this filter is dropped. Type must be less than 32.",
35 MakeUintegerChecker<uint32_t> ())
44 .AddAttribute (
"IpHeaderInclude",
45 "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
140 ipv4->DeleteRawSocket (
this);
189 return SendTo (p, flags, to);
209 if (ipv4->GetRoutingProtocol ())
228 int32_t index = ipv4->GetInterfaceForAddress (src);
230 oif = ipv4->GetNetDevice (index);
231 NS_LOG_LOGIC (
"Set index " << oif <<
"from source " << src);
235 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
245 ipv4->SendWithHeader (p, header, route);
264 for (std::list<Data>::const_iterator i =
m_recv.begin (); i !=
m_recv.end (); ++i)
266 rx += (i->packet)->GetSize ();
275 return RecvFrom (maxSize, flags, tmp);
293 if (!(flags & MSG_PEEK))
322 if (boundNetDevice != incomingInterface->
GetDevice())
346 uint8_t type = icmpHeader.
GetType ();
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Ipv4Address m_src
Source address.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
SocketErrno
Enumeration of the possible errors returned by a socket.
AttributeValue implementation for Boolean.
Ptr< Packet > packet
Packet data.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void AddPacketTag(const Tag &tag) const
Add a packet tag.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
static TypeId GetTypeId(void)
Get the type ID of this class.
Ipv4Address fromIp
Source address.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
SocketType
Enumeration of the possible socket types.
virtual void DoDispose(void)
Destructor implementation.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
a polymophic address class
virtual int Close(void)
Close a socket.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound netdevice, if any.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
A low-level Socket API based loosely on the BSD Socket API.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
bool m_shutdownSend
Flag to shutdown send capability.
Hold an unsigned integer type.
Ipv4Address m_dst
Destination address.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Ipv4Address GetSource(void) const
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Access to the Ipv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
virtual int Bind6()
Allocate a local IPv6 endpoint for this socket.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
virtual int Bind()
Allocate a local IPv4 endpoint for this socket.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
std::list< struct Data > m_recv
Packet waiting to be processed.
virtual int ShutdownRecv(void)
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
virtual enum Socket::SocketType GetSocketType(void) const
Get socket type (NS3_SOCK_RAW)
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
virtual void DoDispose(void)
Destructor implementation.
Ipv4 addresses are stored in host order in this class.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Ptr< NetDevice > GetDevice(void) const
virtual int Listen(void)
Listen for incoming connections.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
uint16_t m_protocol
Protocol.
IPv4 raw data and additional information.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
uint32_t m_icmpFilter
ICMPv4 filter specification.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
bool m_shutdownRecv
Flag to shutdown receive capability.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
uint16_t fromProtocol
Protocol used.
TypeId SetParent(TypeId tid)
void SetProtocol(uint16_t protocol)
Set protocol field.
static bool IsMatchingType(const Address &address)
virtual enum Socket::SocketErrno GetErrno() const
Get last error number.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
void AddHeader(const Header &header)
Add header to this packet.
virtual int ShutdownSend(void)
enum Socket::SocketErrno m_err
Last error number.
virtual int GetSockName(Address &address) const
Get socket address.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.