Kenneth Lee
Kenneth Lee

Reputation: 36

Unable to cast Omnetpp::cPacket to Inet::Packet

I am trying to send a packet using socket but it's throwing an error.

invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]

My code is as follows:

    cPacket *payload = createPacket();
    //Packet* *payload = createPacket();
    payload->setTimestamp();
    emit(sentPkSignal, payload);
    socket.sendTo(payload, destAddr, destPort);
    numSent++;

I have tried using check and cast. Im new to C++ as well as OMNET++

Upvotes: 0

Views: 463

Answers (1)

Rudi
Rudi

Reputation: 6681

Well, omnetpp::cPacket and inet::Packet is two entirely different thing and you cannot cast or convert one to the other. As you are using INET 4, you MUST create an inet::Packet and pass that to the socket.sendTo() call.

Check the existing application's code to see how to create inet::Packets. i.e. https://github.com/inet-framework/inet/blob/v4.1.2/src/inet/applications/udpapp/UdpBasicApp.cc#L108

Upvotes: 2

Related Questions