|
INET Framework for OMNeT++/OMNEST
|
This class implements a raw IPv4 socket.
More...
#include <Ipv4Socket.h>
This class implements a raw IPv4 socket.
◆ Ipv4Socket()
| inet::Ipv4Socket::Ipv4Socket |
( |
cGate * |
outputGate = nullptr | ) |
|
20 socketId(getEnvir()->getUniqueNumber()),
◆ ~Ipv4Socket()
| virtual inet::Ipv4Socket::~Ipv4Socket |
( |
| ) |
|
|
inlinevirtual |
◆ belongsToSocket()
| bool inet::Ipv4Socket::belongsToSocket |
( |
cMessage * |
msg | ) |
const |
|
overridevirtual |
Returns true if the message belongs to this socket.
Implements inet::ISocket.
32 auto&
tags = check_and_cast<ITaggedObject *>(msg)->getTags();
Referenced by processMessage().
◆ bind() [1/2]
64 Ipv4SocketBindCommand *command =
new Ipv4SocketBindCommand();
66 command->setLocalAddress(localAddress);
68 request->setControlInfo(command);
Referenced by inet::TunnelApp::initialize().
◆ bind() [2/2]
| virtual void inet::Ipv4Socket::bind |
( |
const Protocol * |
protocol, |
|
|
L3Address |
localAddress |
|
) |
| |
|
inlineoverrideprotectedvirtual |
Binds this socket to the given protocol and local address.
All incoming packets matching the given parameters will be delivered via the callback interface.
Implements inet::INetworkSocket.
Referenced by bind().
◆ close()
| void inet::Ipv4Socket::close |
( |
| ) |
|
|
overridevirtual |
Closes this socket releasing all resources.
Once closed, a closed socket may be bound to another (or the same) protocol, and reused.
Implements inet::INetworkSocket.
99 Ipv4SocketCloseCommand *command =
new Ipv4SocketCloseCommand();
101 request->setControlInfo(command);
Referenced by inet::TunnelApp::handleStopOperation().
◆ connect() [1/2]
| void inet::Ipv4Socket::connect |
( |
Ipv4Address |
remoteAddress | ) |
|
|
virtual |
76 Ipv4SocketConnectCommand *command =
new Ipv4SocketConnectCommand();
77 command->setRemoteAddress(remoteAddress);
79 request->setControlInfo(command);
◆ connect() [2/2]
| virtual void inet::Ipv4Socket::connect |
( |
L3Address |
remoteAddress | ) |
|
|
inlineoverrideprotectedvirtual |
Connects to a remote socket.
The socket will only receive packets from the specified address, and you can use send() as opposed to sendTo() to send packets.
Implements inet::INetworkSocket.
77 {
connect(remoteAddress.toIpv4()); }
Referenced by connect().
◆ destroy()
| void inet::Ipv4Socket::destroy |
( |
| ) |
|
|
overridevirtual |
◆ getNetworkProtocol()
| virtual const Protocol* inet::Ipv4Socket::getNetworkProtocol |
( |
| ) |
const |
|
inlineoverridevirtual |
Returns the associated network protocol used to deliver datagrams by this socket.
Implements inet::INetworkSocket.
◆ getSocketId()
| virtual int inet::Ipv4Socket::getSocketId |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ getUserData()
| void* inet::Ipv4Socket::getUserData |
( |
| ) |
const |
|
inline |
◆ isOpen()
| virtual bool inet::Ipv4Socket::isOpen |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ processMessage()
| void inet::Ipv4Socket::processMessage |
( |
cMessage * |
msg | ) |
|
|
overridevirtual |
Examines the message, takes ownership, and updates socket state.
Implements inet::ISocket.
40 switch (msg->getKind()) {
48 check_and_cast<Indication *>(msg);
56 throw cRuntimeError(
"Ipv4Socket: invalid msg kind %d, one of the IPv4_I_xxx constants expected", msg->getKind());
◆ send()
| void inet::Ipv4Socket::send |
( |
Packet * |
packet | ) |
|
|
overridevirtual |
◆ sendTo() [1/2]
91 auto addressReq = packet->addTagIfAbsent<L3AddressReq>();
92 addressReq->setDestAddress(destAddress);
◆ sendTo() [2/2]
| virtual void inet::Ipv4Socket::sendTo |
( |
Packet * |
packet, |
|
|
L3Address |
remoteAddress |
|
) |
| |
|
inlineoverrideprotectedvirtual |
Sends a packet to the given remote address using the associated network protocol.
Implements inet::INetworkSocket.
78 {
sendTo(packet, destAddress.toIpv4()); }
Referenced by sendTo().
◆ sendToOutput()
| void inet::Ipv4Socket::sendToOutput |
( |
cMessage * |
message | ) |
|
|
protected |
117 throw cRuntimeError(
"Ipv4Socket: setOutputGate() must be invoked before the socket can be used");
118 auto&
tags = check_and_cast<ITaggedObject *>(message)->getTags();
120 tags.addTagIfAbsent<SocketReq>()->setSocketId(
socketId);
Referenced by bind(), close(), connect(), destroy(), and send().
◆ setCallback()
Sets a callback object, to be used with processMessage().
This callback object may be your simple module itself (if it multiply inherits from ICallback too, that is you declared it as
class MyAppModule : public cSimpleModule, public ICallback
and redefined the necessary virtual functions; or you may use dedicated class (and objects) for this purpose.
Sockets don't delete the callback object in the destructor or on any other occasion.
Implements inet::INetworkSocket.
Referenced by inet::TunnelApp::initialize().
◆ setOutputGate()
| void inet::Ipv4Socket::setOutputGate |
( |
cGate * |
outputGate | ) |
|
|
inline |
Sets the gate on which to send raw packets.
Must be invoked before socket can be used. Example: socket.setOutputGate(gate("ipOut"));
Referenced by inet::TunnelApp::initialize().
◆ setUserData()
| void inet::Ipv4Socket::setUserData |
( |
void * |
userData | ) |
|
|
inline |
◆ bound
| bool inet::Ipv4Socket::bound = false |
|
protected |
◆ callback
◆ isOpen_
| bool inet::Ipv4Socket::isOpen_ = false |
|
protected |
◆ outputGate
| cGate* inet::Ipv4Socket::outputGate = nullptr |
|
protected |
◆ socketId
| int inet::Ipv4Socket::socketId = -1 |
|
protected |
◆ userData
| void* inet::Ipv4Socket::userData = nullptr |
|
protected |
The documentation for this class was generated from the following files:
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
virtual int getSocketId() const override
Returns the socket Id which is unique within the network node.
Definition: Ipv4Socket.h:61
static const Protocol ipv4
Definition: Protocol.h:93
bool bound
Definition: Ipv4Socket.h:37
virtual void socketClosed(INetworkSocket *socket)=0
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
@ IPv4_C_BIND
Definition: Ipv4SocketCommand_m.h:64
virtual void socketDataArrived(INetworkSocket *socket, Packet *packet)=0
@ IPv4_C_DESTROY
Definition: Ipv4SocketCommand_m.h:67
virtual void sendTo(Packet *packet, Ipv4Address destAddress)
Definition: Ipv4Socket.cc:89
virtual void send(Packet *packet) override
Definition: Ipv4Socket.cc:84
void sendToOutput(cMessage *message)
Definition: Ipv4Socket.cc:114
INetworkSocket::ICallback * callback
Definition: Ipv4Socket.h:40
@ IPv4_C_CLOSE
Definition: Ipv4SocketCommand_m.h:66
@ IPv4_I_SOCKET_CLOSED
Definition: Ipv4SocketCommand_m.h:85
void * userData
Definition: Ipv4Socket.h:41
virtual bool belongsToSocket(cMessage *msg) const override
Returns true if the message belongs to this socket.
Definition: Ipv4Socket.cc:30
@ IPv4_I_DATA
Definition: Ipv4SocketCommand_m.h:84
virtual void connect(Ipv4Address remoteAddress)
Definition: Ipv4Socket.cc:74
int socketId
Definition: Ipv4Socket.h:39
* tags
Definition: IUdp-gates.txt:3
virtual void bind(const Protocol *protocol, Ipv4Address localAddress)
Definition: Ipv4Socket.cc:61
bool isOpen_
Definition: Ipv4Socket.h:38
@ IPv4_C_CONNECT
Definition: Ipv4SocketCommand_m.h:65
cGate * outputGate
Definition: Ipv4Socket.h:42