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"
28 .AddAttribute (
"Protocol",
"Protocol number to match.",
31 MakeUintegerChecker<uint16_t> ())
32 .AddAttribute (
"IcmpFilter",
33 "Any icmp header whose type field matches a bit in this filter is dropped. Type must be less than 32.",
36 MakeUintegerChecker<uint32_t> ())
45 .AddAttribute (
"IpHeaderInclude",
46 "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
49 MakeBooleanChecker ())
141 ipv4->DeleteRawSocket (
this);
190 return SendTo (p, flags, to);
210 if (ipv4->GetRoutingProtocol ())
229 int32_t index = ipv4->GetInterfaceForAddress (src);
231 oif = ipv4->GetNetDevice (index);
232 NS_LOG_LOGIC (
"Set index " << oif <<
"from source " << src);
236 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
246 ipv4->SendWithHeader (p, header, route);
265 for (std::list<Data>::const_iterator i =
m_recv.begin (); i !=
m_recv.end (); ++i)
267 rx += (i->packet)->GetSize ();
276 return RecvFrom (maxSize, flags, tmp);
294 if (!(flags & MSG_PEEK))
323 if (boundNetDevice != incomingInterface->
GetDevice())
347 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)
Ptr< Packet > packet
Packet data.
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.
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)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetSize(void) const
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
NS_LOG_COMPONENT_DEFINE("Ipv4RawSocketImpl")
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
SocketErrno
Enumeration of the possible errors returned by a socket.
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)
Access to the Ipv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
static InetSocketAddress ConvertFrom(const Address &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.
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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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)
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
SocketType
Enumeration of the possible socket types.
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.