85 using namespace serializer;
92 if (dynamic_cast<ExtFrame *>(msg) !=
nullptr) {
95 ExtFrame *rawPacket = check_and_cast<ExtFrame *>(msg);
97 packetLength = rawPacket->getDataArraySize();
98 for (
uint32 i = 0; i < packetLength; i++)
99 buffer[i] = rawPacket->getData(i);
101 Buffer
b(const_cast<unsigned char *>(
buffer), packetLength);
103 IPv4Datagram *ipPacket = check_and_cast<IPv4Datagram *>(IPv4Serializer().deserializePacket(
b, c));
104 EV <<
"Delivering an IPv4 packet from " 105 << ipPacket->getSrcAddress()
107 << ipPacket->getDestAddress()
109 << ipPacket->getByteLength()
110 <<
" bytes to IPv4 layer.\n";
111 send(ipPacket,
"upperLayerOut");
116 IPv4Datagram *ipPacket = check_and_cast<IPv4Datagram *>(msg);
119 struct sockaddr_in addr;
120 addr.sin_family = AF_INET;
121 #if !defined(linux) && !defined(__linux) && !defined(_WIN32) 122 addr.sin_len =
sizeof(
struct sockaddr_in);
123 #endif // if !defined(linux) && !defined(__linux) && !defined(_WIN32) 125 addr.sin_addr.s_addr =
htonl(ipPacket->getDestAddress().getInt());
126 Buffer
b(const_cast<unsigned char *>(
buffer),
sizeof(
buffer));
128 c.throwOnSerializerNotFound =
false;
129 IPv4Serializer().serializePacket(ipPacket,
b, c);
130 if (
b.hasError() || c.errorOccured) {
131 EV_ERROR <<
"Cannot serialize and send packet << '" << ipPacket->getName() <<
"' with protocol " << ipPacket->getTransportProtocol() <<
".\n";
136 int32 packetLength =
b.getPos();
137 EV <<
"Delivering an IPv4 packet from " 138 << ipPacket->getSrcAddress()
140 << ipPacket->getDestAddress()
142 << ipPacket->getByteLength()
143 <<
" bytes to link layer.\n";
148 EV <<
"Interface is not connected, dropping packet " << msg << endl;
uint8 buffer[1<< 16]
Definition: ExtInterface.h:52
int numSent
Definition: ExtInterface.h:56
int numRcvd
Definition: ExtInterface.h:57
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
bool isOperational
Definition: MACBase.h:37
virtual void handleMessageWhenDown(cMessage *msg)
Definition: MACBase.cc:108
int32_t int32
Definition: Compat.h:31
uint32_t uint32
Definition: Compat.h:30
int numDropped
Definition: ExtInterface.h:58
bool connected
Definition: ExtInterface.h:51
void sendBytes(unsigned char *buf, size_t numBytes, struct sockaddr *from, socklen_t addrlen)
Send on the currently open connection.
Definition: cSocketRTScheduler.cc:339
value< double, units::m > b
Definition: Units.h:1054
cSocketRTScheduler * rtScheduler
Definition: ExtInterface.h:61