#include <ICMP.h>
List of all members.
Detailed Description
Member Function Documentation
void ICMP::errorOut |
( |
ICMPMessage * |
icmpmsg | ) |
[protected, virtual] |
void ICMP::handleMessage |
( |
cMessage * |
msg | ) |
[protected, virtual] |
{
cGate *arrivalGate = msg->getArrivalGate();
if (!strcmp(arrivalGate->getName(), "localIn"))
{
processICMPMessage(check_and_cast<ICMPMessage *>(msg));
return;
}
if (!strcmp(arrivalGate->getName(), "pingIn"))
{
sendEchoRequest(PK(msg));
return;
}
}
void ICMP::processEchoReply |
( |
ICMPMessage * |
reply | ) |
[protected, virtual] |
Referenced by processICMPMessage().
{
IPControlInfo *ctrl = check_and_cast<IPControlInfo*>(reply->removeControlInfo());
cPacket *payload = reply->decapsulate();
payload->setControlInfo(ctrl);
delete reply;
send(payload, "pingOut");
}
void ICMP::processEchoRequest |
( |
ICMPMessage * |
request | ) |
[protected, virtual] |
Referenced by processICMPMessage().
{
ICMPMessage *reply = request;
reply->setName((std::string(request->getName())+"-reply").c_str());
reply->setType(ICMP_ECHO_REPLY);
IPControlInfo *ctrl = check_and_cast<IPControlInfo *>(reply->getControlInfo());
IPAddress src = ctrl->getSrcAddr();
IPAddress dest = ctrl->getDestAddr();
ctrl->setSrcAddr(dest);
ctrl->setDestAddr(src);
sendToIP(reply);
}
void ICMP::processICMPMessage |
( |
ICMPMessage * |
icmpmsg | ) |
[protected, virtual] |
void ICMP::sendEchoRequest |
( |
cPacket * |
msg | ) |
[protected, virtual] |
Referenced by handleMessage().
{
IPControlInfo *ctrl = check_and_cast<IPControlInfo*>(msg->removeControlInfo());
ctrl->setProtocol(IP_PROT_ICMP);
ICMPMessage *request = new ICMPMessage(msg->getName());
request->setType(ICMP_ECHO_REQUEST);
request->encapsulate(msg);
request->setControlInfo(ctrl);
sendToIP(request);
}
void ICMP::sendErrorMessage |
( |
cPacket * |
transportPacket, |
|
|
IPControlInfo * |
ctrl, |
|
|
ICMPType |
type, |
|
|
ICMPCode |
code |
|
) |
| [virtual] |
This method can be called from other modules to send an ICMP error packet in response to a received bogus packet from the transport layer (like UDP). The ICMP error packet needs to include (part of) the original IP datagram, so this function will wrap back the transport packet into the IP datagram based on its IPControlInfo.
{
Enter_Method("sendErrorMessage(transportPacket, ctrl, type=%d, code=%d)", type, code);
IPDatagram *datagram = ctrl->removeOrigDatagram();
take(transportPacket);
take(datagram);
datagram->encapsulate(transportPacket);
sendErrorMessage(datagram, type, code);
}
void ICMP::sendErrorMessage |
( |
IPDatagram * |
datagram, |
|
|
ICMPType |
type, |
|
|
ICMPCode |
code |
|
) |
| [virtual] |
This method can be called from other modules to send an ICMP error packet in response to a received bogus packet.
Referenced by IP::fragmentAndSend(), IP::handlePacketFromNetwork(), IPFragBuf::purgeStaleFragments(), IP::routePacket(), IP::sendDatagramToOutput(), and sendErrorMessage().
{
Enter_Method("sendErrorMessage(datagram, type=%d, code=%d)", type, code);
take(origDatagram);
if (origDatagram->getDestAddress().isMulticast())
{
EV << "won't send ICMP error messages for multicast message " << origDatagram << endl;
delete origDatagram;
return;
}
if (origDatagram->getTransportProtocol() == IP_PROT_ICMP)
{
ICMPMessage *recICMPMsg = check_and_cast<ICMPMessage *>(origDatagram->getEncapsulatedPacket());
if (recICMPMsg->getType()<128)
{
EV << "ICMP error received -- do not reply to it" << endl;
delete origDatagram;
return;
}
}
char msgname[32];
static long ctr;
sprintf(msgname, "ICMP-error-#%ld-type%d-code%d", ++ctr, type, code);
EV << "sending ICMP error " << msgname << endl;
ICMPMessage *errorMessage = new ICMPMessage(msgname);
errorMessage->setType(type);
errorMessage->setCode(code);
errorMessage->encapsulate(origDatagram);
int dataLength = origDatagram->getByteLength() - origDatagram->getHeaderLength();
int truncatedDataLength = dataLength <= 8 ? dataLength : 8;
errorMessage->setByteLength(8 + origDatagram->getHeaderLength() + truncatedDataLength);
if (origDatagram->getSrcAddress().isUnspecified())
{
IPControlInfo *controlInfo = new IPControlInfo();
controlInfo->setSrcAddr(IPAddress::LOOPBACK_ADDRESS);
controlInfo->setProtocol(IP_PROT_ICMP);
errorMessage->setControlInfo(controlInfo);
processICMPMessage(errorMessage);
}
else
{
sendToIP(errorMessage, origDatagram->getSrcAddress());
}
}
void ICMP::sendToIP |
( |
ICMPMessage * |
msg, |
|
|
const IPAddress & |
dest |
|
) |
| [protected, virtual] |
void ICMP::sendToIP |
( |
ICMPMessage * |
msg | ) |
[protected, virtual] |
{
send(msg, "sendOut");
}
Member Data Documentation
The documentation for this class was generated from the following files: