INET Framework for OMNeT++/OMNEST
inet::UDPSocket Class Reference

UDPSocket is a convenience class, to make it easier to send and receive UDP packets from your application models. More...

#include <UDPSocket.h>

Classes

struct  SendOptions
 

Public Member Functions

 UDPSocket ()
 Constructor. More...
 
 ~UDPSocket ()
 Destructor. More...
 
int getSocketId () const
 Returns the internal socket Id. More...
 
Opening and closing connections, sending data
void setOutputGate (cGate *toUdp)
 Sets the gate on which to send to UDP. More...
 
void bind (int localPort)
 Bind the socket to a local port number. More...
 
void bind (L3Address localAddr, int localPort)
 Bind the socket to a local port number and IP address (useful with multi-homing or multicast addresses). More...
 
void connect (L3Address remoteAddr, int remotePort)
 Connects to a remote UDP socket. More...
 
void setTimeToLive (int ttl)
 Set the TTL (IPv6: Hop Limit) field on sent packets. More...
 
void setTypeOfService (unsigned char tos)
 Sets the IPv4 Type of Service / IPv6 Traffic Class fields of packets sent from the UDP socket. More...
 
void setBroadcast (bool broadcast)
 Set the Broadcast option on the UDP socket. More...
 
void setMulticastLoop (bool value)
 The boolean value specifies whether sent multicast packets should be looped back to the local sockets (like the Unix IP_MULTICAST_LOOP socket option). More...
 
void setMulticastOutputInterface (int interfaceId)
 Set the output interface for sending multicast packets (like the Unix IP_MULTICAST_IF socket option). More...
 
void setReuseAddress (bool value)
 Set the ReuseAddress option on the UDP socket. More...
 
void joinMulticastGroup (const L3Address &multicastAddr, int interfaceId=-1)
 Adds the socket to the given multicast group, that is, UDP packets arriving to the given multicast address will be passed up to the socket. More...
 
void joinLocalMulticastGroups (MulticastGroupList mgl)
 Joins the socket to each multicast group that are registered with any of the interfaces. More...
 
void leaveMulticastGroup (const L3Address &multicastAddr)
 Causes the socket to leave the given multicast group, i.e. More...
 
void leaveLocalMulticastGroups (MulticastGroupList mgl)
 Causes the socket to leave each multicast groups that are registered with any of the interfaces. More...
 
void blockMulticastSources (int interfaceId, const L3Address &multicastAddr, const std::vector< L3Address > &sourceList)
 Blocks multicast traffic of the specified group address from specific sources. More...
 
void unblockMulticastSources (int interfaceId, const L3Address &multicastAddr, const std::vector< L3Address > &sourceList)
 Unblocks the multicast traffic of the specified group address from the specified sources. More...
 
void joinMulticastSources (int interfaceId, const L3Address &multicastAddr, const std::vector< L3Address > &sourceList)
 Adds the socket to the given multicast group and source addresses, that is, UDP packets arriving from one of the sources and to the given multicast address will be passed up to the socket. More...
 
void leaveMulticastSources (int interfaceId, const L3Address &multicastAddr, const std::vector< L3Address > &sourceList)
 Causes the socket to leave the given multicast group for the specified sources, i.e. More...
 
void setMulticastSourceFilter (int interfaceId, const L3Address &multicastAddr, UDPSourceFilterMode filterMode, const std::vector< L3Address > &sourceList)
 Sets the source filter for the given multicast group. More...
 
void sendTo (cPacket *msg, L3Address destAddr, int destPort, const SendOptions *options=nullptr)
 Sends a data packet to the given address and port. More...
 
void send (cPacket *msg)
 Sends a data packet to the address and port specified previously in a connect() call. More...
 
void close ()
 Unbinds the socket. More...
 

Static Public Member Functions

static int generateSocketId ()
 Generates a new socket id. More...
 

Protected Member Functions

void sendToUDP (cMessage *msg)
 

Protected Attributes

int sockId
 
cGate * gateToUdp
 

Handling of messages arriving from UDP

bool belongsToSocket (cMessage *msg)
 Returns true if the message belongs to this socket instance (message has a UDPControlInfo as getControlInfo(), and the sockId in it matches that of the socket.) More...
 
static bool belongsToAnyUDPSocket (cMessage *msg)
 Returns true if the message belongs to any UDPSocket instance. More...
 
static std::string getReceivedPacketInfo (cPacket *pk)
 Utility function: returns a line of information about a packet received via UDP. More...
 

Detailed Description

UDPSocket is a convenience class, to make it easier to send and receive UDP packets from your application models.

You'd have one (or more) UDPSocket object(s) in your application simple module class, and call its member functions (bind(), connect(), sendTo(), etc.) to create and configure a socket, and to send datagrams.

UDPSocket chooses and remembers the sockId for you, assembles and sends command packets such as UDP_C_BIND to UDP, and can also help you deal with packets and notification messages arriving from UDP.

Here is a code fragment that creates an UDP socket and sends a 1K packet over it (the code can be placed in your handleMessage() or activity()):

  UDPSocket socket;
  socket.setOutputGate(gate("udpOut"));
  socket.connect(Address("10.0.0.2"), 2000);
  cPacket *pk = new cPacket("dgram");
  pk->setByteLength(1024);
  socket.send(pk);
  socket.close();

Processing messages sent up by the UDP module is relatively straightforward. You only need to distinguish between data packets and error notifications, by checking the message kind (should be either UDP_I_DATA or UDP_I_ERROR), and casting the control info to UDPDataIndication or UDPErrorIndication. USPSocket provides some help for this with the belongsToSocket() and belongsToAnyUDPSocket() methods.

Constructor & Destructor Documentation

inet::UDPSocket::UDPSocket ( )

Constructor.

The getSocketId() method returns a valid Id right after constructor call.

27 {
28  // don't allow user-specified sockIds because they may conflict with
29  // automatically assigned ones.
31  gateToUdp = nullptr;
32 }
static int generateSocketId()
Generates a new socket id.
Definition: UDPSocket.cc:34
cGate * gateToUdp
Definition: UDPSocket.h:76
int sockId
Definition: UDPSocket.h:75
inet::UDPSocket::~UDPSocket ( )
inline

Destructor.

91 {}

Member Function Documentation

bool inet::UDPSocket::belongsToAnyUDPSocket ( cMessage *  msg)
static

Returns true if the message belongs to any UDPSocket instance.

(This basically checks if the message has an UDPControlInfo attached to it as getControlInfo().)

320 {
321  return dynamic_cast<UDPControlInfo *>(msg->getControlInfo());
322 }
bool inet::UDPSocket::belongsToSocket ( cMessage *  msg)

Returns true if the message belongs to this socket instance (message has a UDPControlInfo as getControlInfo(), and the sockId in it matches that of the socket.)

314 {
315  return dynamic_cast<UDPControlInfo *>(msg->getControlInfo()) &&
316  ((UDPControlInfo *)(msg->getControlInfo()))->getSockId() == sockId;
317 }
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::bind ( L3Address  localAddr,
int  localPort 
)

Bind the socket to a local port number and IP address (useful with multi-homing or multicast addresses).

Use port=0 for an ephemeral port.

59 {
60  if (localPort < -1 || localPort > 65535) // -1: ephemeral port
61  throw cRuntimeError("UDPSocket::bind(): invalid port number %d", localPort);
62 
63  UDPBindCommand *ctrl = new UDPBindCommand();
64  ctrl->setSockId(sockId);
65  ctrl->setLocalAddr(localAddr);
66  ctrl->setLocalPort(localPort);
67  cMessage *msg = new cMessage("BIND", UDP_C_BIND);
68  msg->setControlInfo(ctrl);
69  sendToUDP(msg);
70 }
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
Definition: UDPControlInfo_m.h:59
void inet::UDPSocket::blockMulticastSources ( int  interfaceId,
const L3Address multicastAddr,
const std::vector< L3Address > &  sourceList 
)

Blocks multicast traffic of the specified group address from specific sources.

Use this method only if joinMulticastGroup() was previously called for that group.

242 {
243  cMessage *msg = new cMessage("BlockMulticastSources", UDP_C_SETOPTION);
244  UDPBlockMulticastSourcesCommand *ctrl = new UDPBlockMulticastSourcesCommand();
245  ctrl->setSockId(sockId);
246  ctrl->setInterfaceId(interfaceId);
247  ctrl->setMulticastAddr(multicastAddr);
248  ctrl->setSourceListArraySize(sourceList.size());
249  for (int i = 0; i < (int)sourceList.size(); ++i)
250  ctrl->setSourceList(i, sourceList[i]);
251  msg->setControlInfo(ctrl);
252  sendToUDP(msg);
253 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::close ( )

Unbinds the socket.

Once closed, a closed socket may be bound to another (or the same) port, and reused.

Referenced by inet::UDPSink::processStop(), inet::UDPBasicApp::processStop(), and inet::UDPBasicBurst::processStop().

113 {
114  cMessage *msg = new cMessage("CLOSE", UDP_C_CLOSE);
115  UDPCloseCommand *ctrl = new UDPCloseCommand();
116  ctrl->setSockId(sockId);
117  msg->setControlInfo(ctrl);
118  sendToUDP(msg);
119 }
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
Definition: UDPControlInfo_m.h:62
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::connect ( L3Address  remoteAddr,
int  remotePort 
)

Connects to a remote UDP socket.

This has two effects: (1) this socket will only receive packets from specified address/port, and (2) you can use send() (as opposed to sendTo()) to send packets.

Referenced by inet::NetPerfMeter::establishConnection().

73 {
74  if (addr.isUnspecified())
75  throw cRuntimeError("UDPSocket::connect(): unspecified remote address");
76  if (port <= 0 || port > 65535)
77  throw cRuntimeError("UDPSocket::connect(): invalid remote port number %d", port);
78 
79  UDPConnectCommand *ctrl = new UDPConnectCommand();
80  ctrl->setSockId(sockId);
81  ctrl->setRemoteAddr(addr);
82  ctrl->setRemotePort(port);
83  cMessage *msg = new cMessage("CONNECT", UDP_C_CONNECT);
84  msg->setControlInfo(ctrl);
85  sendToUDP(msg);
86 }
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
Definition: UDPControlInfo_m.h:60
int sockId
Definition: UDPSocket.h:75
int inet::UDPSocket::generateSocketId ( )
static

Generates a new socket id.

Referenced by UDPSocket().

35 {
36  return getEnvir()->getUniqueNumber();
37 }
std::string inet::UDPSocket::getReceivedPacketInfo ( cPacket *  pk)
static

Utility function: returns a line of information about a packet received via UDP.

Referenced by inet::UDPSink::processPacket(), inet::UDPBasicApp::processPacket(), inet::UDPBasicBurst::processPacket(), and inet::UDPVideoStreamCli::receiveStream().

325 {
326  UDPDataIndication *ctrl = check_and_cast<UDPDataIndication *>(pk->getControlInfo());
327 
328  L3Address srcAddr = ctrl->getSrcAddr();
329  L3Address destAddr = ctrl->getDestAddr();
330  int srcPort = ctrl->getSrcPort();
331  int destPort = ctrl->getDestPort();
332  int interfaceID = ctrl->getInterfaceId();
333  int ttl = ctrl->getTtl();
334  int tos = ctrl->getTypeOfService();
335 
336  std::stringstream os;
337  os << pk << " (" << pk->getByteLength() << " bytes) ";
338  os << srcAddr << ":" << srcPort << " --> " << destAddr << ":" << destPort;
339  os << " TTL=" << ttl << " ToS=" << tos << " on ifID=" << interfaceID;
340  return os.str();
341 }
uint8_t tos
Definition: TCP_NSC.cc:83
uint8_t ttl
Definition: TCP_NSC.cc:87
int inet::UDPSocket::getSocketId ( ) const
inline

Returns the internal socket Id.

96 { return sockId; }
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::joinLocalMulticastGroups ( MulticastGroupList  mgl)

Joins the socket to each multicast group that are registered with any of the interfaces.

Referenced by inet::rtp::RTCP::createSocket(), inet::rtp::RTP::createSocket(), inet::UDPEchoApp::handleNodeStart(), inet::UDPSink::setSocketOptions(), and inet::UDPBasicApp::setSocketOptions().

195 {
196  if (mgl.size() > 0) {
197  UDPJoinMulticastGroupsCommand *ctrl = new UDPJoinMulticastGroupsCommand();
198  ctrl->setSockId(sockId);
199  ctrl->setMulticastAddrArraySize(mgl.size());
200  ctrl->setInterfaceIdArraySize(mgl.size());
201 
202  for (unsigned int j = 0; j < mgl.size(); ++j) {
203  ctrl->setMulticastAddr(j, mgl[j].multicastAddr);
204  ctrl->setInterfaceId(j, mgl[j].interfaceId);
205  }
206 
207  cMessage *msg = new cMessage("JoinMulticastGroups", UDP_C_SETOPTION);
208  msg->setControlInfo(ctrl);
209  sendToUDP(msg);
210  }
211 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::joinMulticastGroup ( const L3Address multicastAddr,
int  interfaceId = -1 
)

Adds the socket to the given multicast group, that is, UDP packets arriving to the given multicast address will be passed up to the socket.

One can also optionally specify the output interface for packets sent to that address.

Referenced by inet::UDPSink::setSocketOptions().

182 {
183  cMessage *msg = new cMessage("JoinMulticastGroups", UDP_C_SETOPTION);
184  UDPJoinMulticastGroupsCommand *ctrl = new UDPJoinMulticastGroupsCommand();
185  ctrl->setSockId(sockId);
186  ctrl->setMulticastAddrArraySize(1);
187  ctrl->setMulticastAddr(0, multicastAddr);
188  ctrl->setInterfaceIdArraySize(1);
189  ctrl->setInterfaceId(0, interfaceId);
190  msg->setControlInfo(ctrl);
191  sendToUDP(msg);
192 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::joinMulticastSources ( int  interfaceId,
const L3Address multicastAddr,
const std::vector< L3Address > &  sourceList 
)

Adds the socket to the given multicast group and source addresses, that is, UDP packets arriving from one of the sources and to the given multicast address will be passed up to the socket.

270 {
271  cMessage *msg = new cMessage("JoinMulticastSources", UDP_C_SETOPTION);
272  UDPJoinMulticastSourcesCommand *ctrl = new UDPJoinMulticastSourcesCommand();
273  ctrl->setSockId(sockId);
274  ctrl->setInterfaceId(interfaceId);
275  ctrl->setMulticastAddr(multicastAddr);
276  ctrl->setSourceListArraySize(sourceList.size());
277  for (int i = 0; i < (int)sourceList.size(); ++i)
278  ctrl->setSourceList(i, sourceList[i]);
279  msg->setControlInfo(ctrl);
280  sendToUDP(msg);
281 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::leaveLocalMulticastGroups ( MulticastGroupList  mgl)

Causes the socket to leave each multicast groups that are registered with any of the interfaces.

225 {
226  if (mgl.size() > 0) {
227  UDPLeaveMulticastGroupsCommand *ctrl = new UDPLeaveMulticastGroupsCommand();
228  ctrl->setSockId(sockId);
229  ctrl->setMulticastAddrArraySize(mgl.size());
230 
231  for (unsigned int j = 0; j < mgl.size(); ++j) {
232  ctrl->setMulticastAddr(j, mgl[j].multicastAddr);
233  }
234 
235  cMessage *msg = new cMessage("LeaveMulticastGroups", UDP_C_SETOPTION);
236  msg->setControlInfo(ctrl);
237  sendToUDP(msg);
238  }
239 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::leaveMulticastGroup ( const L3Address multicastAddr)

Causes the socket to leave the given multicast group, i.e.

UDP packets arriving to the given multicast address will no longer passed up to the socket.

Referenced by inet::UDPSink::processStop().

214 {
215  cMessage *msg = new cMessage("LeaveMulticastGroups", UDP_C_SETOPTION);
216  UDPLeaveMulticastGroupsCommand *ctrl = new UDPLeaveMulticastGroupsCommand();
217  ctrl->setSockId(sockId);
218  ctrl->setMulticastAddrArraySize(1);
219  ctrl->setMulticastAddr(0, multicastAddr);
220  msg->setControlInfo(ctrl);
221  sendToUDP(msg);
222 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::leaveMulticastSources ( int  interfaceId,
const L3Address multicastAddr,
const std::vector< L3Address > &  sourceList 
)

Causes the socket to leave the given multicast group for the specified sources, i.e.

UDP packets arriving from those sources to the given multicast address will no longer passed up to the socket.

284 {
285  cMessage *msg = new cMessage("LeaveMulticastSources", UDP_C_SETOPTION);
286  UDPLeaveMulticastSourcesCommand *ctrl = new UDPLeaveMulticastSourcesCommand();
287  ctrl->setSockId(sockId);
288  ctrl->setInterfaceId(interfaceId);
289  ctrl->setMulticastAddr(multicastAddr);
290  ctrl->setSourceListArraySize(sourceList.size());
291  for (int i = 0; i < (int)sourceList.size(); ++i)
292  ctrl->setSourceList(i, sourceList[i]);
293  msg->setControlInfo(ctrl);
294  sendToUDP(msg);
295 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::send ( cPacket *  msg)

Sends a data packet to the address and port specified previously in a connect() call.

Referenced by sendToUDP(), and inet::NetPerfMeter::transmitFrame().

104 {
105  pk->setKind(UDP_C_DATA);
106  UDPSendCommand *ctrl = new UDPSendCommand();
107  ctrl->setSockId(sockId);
108  pk->setControlInfo(ctrl);
109  sendToUDP(pk);
110 }
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
Definition: UDPControlInfo_m.h:58
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::sendTo ( cPacket *  msg,
L3Address  destAddr,
int  destPort,
const SendOptions options = nullptr 
)

Sends a data packet to the given address and port.

Additional options can be passed in a SendOptions struct.

Referenced by inet::rtp::RTCP::createPacket(), inet::rtp::RTP::dataOut(), inet::UDPBasicBurst::generateBurst(), inet::VoIPStreamSender::handleMessage(), inet::UDPEchoApp::handleMessageWhenUp(), inet::UDPVideoStreamCli::requestStream(), inet::sctp::SCTP::sendAbortFromMain(), inet::LDP::sendHelloTo(), inet::UDPBasicApp::sendPacket(), inet::UDPVideoStreamSvr::sendStreamData(), inet::sctp::SCTPAssociation::sendToIP(), inet::DHCPServer::sendToUDP(), inet::DHCPClient::sendToUDP(), and inet::SimpleVoIPSender::sendVoIPPacket().

89 {
90  pk->setKind(UDP_C_DATA);
91  UDPSendCommand *ctrl = new UDPSendCommand();
92  ctrl->setSockId(sockId);
93  ctrl->setDestAddr(destAddr);
94  ctrl->setDestPort(destPort);
95  if (options) {
96  ctrl->setSrcAddr(options->srcAddr);
97  ctrl->setInterfaceId(options->outInterfaceId);
98  }
99  pk->setControlInfo(ctrl);
100  sendToUDP(pk);
101 }
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
Definition: UDPControlInfo_m.h:58
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::sendToUDP ( cMessage *  msg)
protected

Referenced by bind(), blockMulticastSources(), close(), connect(), joinLocalMulticastGroups(), joinMulticastGroup(), joinMulticastSources(), leaveLocalMulticastGroups(), leaveMulticastGroup(), leaveMulticastSources(), send(), sendTo(), setBroadcast(), setMulticastLoop(), setMulticastOutputInterface(), setMulticastSourceFilter(), setReuseAddress(), setTimeToLive(), setTypeOfService(), and unblockMulticastSources().

40 {
41  if (!gateToUdp)
42  throw cRuntimeError("UDPSocket: setOutputGate() must be invoked before socket can be used");
43 
44  cObject *ctrl = msg->getControlInfo();
45  EV_TRACE << "UDPSocket: Send (" << msg->getClassName() << ")" << msg->getFullName();
46  if (ctrl)
47  EV_TRACE << " control info: (" << ctrl->getClassName() << ")" << ctrl->getFullName();
48  EV_TRACE << endl;
49 
50  check_and_cast<cSimpleModule *>(gateToUdp->getOwnerModule())->send(msg, gateToUdp);
51 }
void send(cPacket *msg)
Sends a data packet to the address and port specified previously in a connect() call.
Definition: UDPSocket.cc:103
cGate * gateToUdp
Definition: UDPSocket.h:76
void inet::UDPSocket::setBroadcast ( bool  broadcast)

Set the Broadcast option on the UDP socket.

This will cause the socket to receive broadcast packets as well.

Referenced by inet::DHCPServer::openSocket(), inet::DHCPClient::openSocket(), inet::UDPSink::setSocketOptions(), and inet::UDPBasicApp::setSocketOptions().

122 {
123  cMessage *msg = new cMessage("SetBroadcast", UDP_C_SETOPTION);
124  UDPSetBroadcastCommand *ctrl = new UDPSetBroadcastCommand();
125  ctrl->setSockId(sockId);
126  ctrl->setBroadcast(broadcast);
127  msg->setControlInfo(ctrl);
128  sendToUDP(msg);
129 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::setMulticastLoop ( bool  value)

The boolean value specifies whether sent multicast packets should be looped back to the local sockets (like the Unix IP_MULTICAST_LOOP socket option).

162 {
163  cMessage *msg = new cMessage("SetMulticastLoop", UDP_C_SETOPTION);
164  UDPSetMulticastLoopCommand *ctrl = new UDPSetMulticastLoopCommand();
165  ctrl->setSockId(sockId);
166  ctrl->setLoop(value);
167  msg->setControlInfo(ctrl);
168  sendToUDP(msg);
169 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::setMulticastOutputInterface ( int  interfaceId)

Set the output interface for sending multicast packets (like the Unix IP_MULTICAST_IF socket option).

The argument is the interface's ID in InterfaceTable.

Referenced by inet::UDPBasicApp::setSocketOptions().

152 {
153  cMessage *msg = new cMessage("SetMulticastOutputIf", UDP_C_SETOPTION);
154  UDPSetMulticastInterfaceCommand *ctrl = new UDPSetMulticastInterfaceCommand();
155  ctrl->setSockId(sockId);
156  ctrl->setInterfaceId(interfaceId);
157  msg->setControlInfo(ctrl);
158  sendToUDP(msg);
159 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::setMulticastSourceFilter ( int  interfaceId,
const L3Address multicastAddr,
UDPSourceFilterMode  filterMode,
const std::vector< L3Address > &  sourceList 
)

Sets the source filter for the given multicast group.

If filterMode is INCLUDE, then UDP packets arriving from one of the sources and to to given multicast group will be passed up to the socket. If filterMode is EXCLUDE, then all UDP packets arriving to the given multicast group will be passed up except those that arrive from the specified sources.

299 {
300  cMessage *msg = new cMessage("SetMulticastSourceFilter", UDP_C_SETOPTION);
301  UDPSetMulticastSourceFilterCommand *ctrl = new UDPSetMulticastSourceFilterCommand();
302  ctrl->setSockId(sockId);
303  ctrl->setInterfaceId(interfaceId);
304  ctrl->setMulticastAddr(multicastAddr);
305  ctrl->setFilterMode(filterMode);
306  ctrl->setSourceListArraySize(sourceList.size());
307  for (int i = 0; i < (int)sourceList.size(); ++i)
308  ctrl->setSourceList(i, sourceList[i]);
309  msg->setControlInfo(ctrl);
310  sendToUDP(msg);
311 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::setReuseAddress ( bool  value)

Set the ReuseAddress option on the UDP socket.

It is possible to use an already bound address/port in the bind() command only if both the original and the new socket set the ReuseAddress flag to true. Note that only one socket will receive the packets arrived at that address/port (the last bound one). This option works like REUSE_ADDR socket option in Linux.

172 {
173  cMessage *msg = new cMessage("SetReuseAddress", UDP_C_SETOPTION);
174  UDPSetReuseAddressCommand *ctrl = new UDPSetReuseAddressCommand();
175  ctrl->setSockId(sockId);
176  ctrl->setReuseAddress(value);
177  msg->setControlInfo(ctrl);
178  sendToUDP(msg);
179 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::setTimeToLive ( int  ttl)

Set the TTL (IPv6: Hop Limit) field on sent packets.

Referenced by inet::UDPBasicApp::setSocketOptions().

132 {
133  cMessage *msg = new cMessage("SetTTL", UDP_C_SETOPTION);
134  UDPSetTimeToLiveCommand *ctrl = new UDPSetTimeToLiveCommand();
135  ctrl->setSockId(sockId);
136  ctrl->setTtl(ttl);
137  msg->setControlInfo(ctrl);
138  sendToUDP(msg);
139 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75
uint8_t ttl
Definition: TCP_NSC.cc:87
void inet::UDPSocket::setTypeOfService ( unsigned char  tos)

Sets the IPv4 Type of Service / IPv6 Traffic Class fields of packets sent from the UDP socket.

Referenced by inet::UDPBasicApp::setSocketOptions().

142 {
143  cMessage *msg = new cMessage("SetTOS", UDP_C_SETOPTION);
144  UDPSetTypeOfServiceCommand *ctrl = new UDPSetTypeOfServiceCommand();
145  ctrl->setSockId(sockId);
146  ctrl->setTos(tos);
147  msg->setControlInfo(ctrl);
148  sendToUDP(msg);
149 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
uint8_t tos
Definition: TCP_NSC.cc:83
int sockId
Definition: UDPSocket.h:75
void inet::UDPSocket::unblockMulticastSources ( int  interfaceId,
const L3Address multicastAddr,
const std::vector< L3Address > &  sourceList 
)

Unblocks the multicast traffic of the specified group address from the specified sources.

Use this method only if the traffic was previously blocked by calling blockMulticastSources().

256 {
257  cMessage *msg = new cMessage("UnblockMulticastSources", UDP_C_SETOPTION);
258  UDPUnblockMulticastSourcesCommand *ctrl = new UDPUnblockMulticastSourcesCommand();
259  ctrl->setSockId(sockId);
260  ctrl->setInterfaceId(interfaceId);
261  ctrl->setMulticastAddr(multicastAddr);
262  ctrl->setSourceListArraySize(sourceList.size());
263  for (int i = 0; i < (int)sourceList.size(); ++i)
264  ctrl->setSourceList(i, sourceList[i]);
265  msg->setControlInfo(ctrl);
266  sendToUDP(msg);
267 }
Definition: UDPControlInfo_m.h:61
void sendToUDP(cMessage *msg)
Definition: UDPSocket.cc:39
int sockId
Definition: UDPSocket.h:75

Member Data Documentation

cGate* inet::UDPSocket::gateToUdp
protected

Referenced by sendToUDP(), and UDPSocket().


The documentation for this class was generated from the following files: