68 Enter_Method(
"sendErrorMessage(datagram, type=%d, code=%d)", type, code);
73 IPv4Address origSrcAddr = origDatagram->getSrcAddress();
74 IPv4Address origDestAddr = origDatagram->getDestAddress();
77 if (origDestAddr.isMulticast() || origDestAddr.isLimitedBroadcastAddress() ||
possiblyLocalBroadcast(origDestAddr, inputInterfaceId)) {
78 EV_DETAIL <<
"won't send ICMP error messages for broadcast/multicast message " << origDatagram << endl;
84 if ((inputInterfaceId != -1 && origSrcAddr.isUnspecified())
85 || origSrcAddr.isMulticast()
86 || origSrcAddr.isLimitedBroadcastAddress()
88 EV_DETAIL <<
"won't send ICMP error messages to broadcast/multicast address, message " << origDatagram << endl;
94 if (origDatagram->getTransportProtocol() ==
IP_PROT_ICMP) {
95 ICMPMessage *recICMPMsg = check_and_cast<ICMPMessage *>(origDatagram->getEncapsulatedPacket());
97 EV_DETAIL <<
"ICMP error received -- do not reply to it" << endl;
106 sprintf(msgname,
"ICMP-error-#%ld-type%d-code%d", ++ctr, type, code);
109 EV_DETAIL <<
"sending ICMP error " << msgname << endl;
112 ICMPMessage *errorMessage =
new ICMPMessage(msgname);
113 errorMessage->setType(type);
114 errorMessage->setCode(code);
115 errorMessage->encapsulate(origDatagram);
125 int dataLength = origDatagram->getByteLength() - origDatagram->getHeaderLength();
126 int truncatedDataLength = dataLength <= 8 ? dataLength : 8;
127 errorMessage->setByteLength(8 + origDatagram->getHeaderLength() + truncatedDataLength);
131 if (origSrcAddr.isUnspecified()) {
133 IPv4ControlInfo *controlInfo =
new IPv4ControlInfo();
136 errorMessage->setControlInfo(controlInfo);
142 sendToIP(errorMessage, origDatagram->getSrcAddress());
virtual void sendToIP(ICMPMessage *, const IPv4Address &dest)
Definition: ICMP.cc:286
bool isIcmpInfoType(int type)
Definition: ICMPMessage_m.h:189
Definition: IPProtocolId_m.h:77
static const IPv4Address LOOPBACK_ADDRESS
127.0.0.1
Definition: IPv4Address.h:103
virtual bool possiblyLocalBroadcast(const IPv4Address &addr, int interfaceId)
Definition: ICMP.cc:159
virtual void processICMPMessage(ICMPMessage *)
Definition: ICMP.cc:186