Socket Receive Question

Login to reply to this topic.
Fri, 2007-07-27 15:31
Joined: 2007-07-25
Forum posts: 2

Hello all,

I am a Symbian C++ newbie so please bare with me. I'm trying to implement a simple traceroute application. I believe I am sending my ICMP echo request properly, but I'm a little bit confused on the response. I am receiving something in my TBuf8 receiveBuffer but I don't know how to manipulate the data. How do i print out the contents of the buffer? How do I read the headers in the response?

Thanks,
-Jay

void Tracer::send_probe(TInetAddr host, TInt ttl) {
        RDebug::Print(_L("Send Probe"));
       
        // build the datagram
        TBuf8<64> data;
        TUint16 seq = 1;
        TUint16 id = 100;

        data.Append(0x08);  // ICMP type (8 - echo request)
        data.Append(0x00);  // ICMP code (0)
        data.Append(0x00);  // checksum first byte
        data.Append(0x00);  // checksum second byte

        data.Append(id>>8); // identifier
        data.Append(id&0x00FF);

        data.Append(seq>>8); // sequence number
        data.Append(seq&0x00FF);

        data.Append(_L("abcdefghijklmnopqrstuvwabcdefghi")); // data
       
        // send the datagram
        TRequestStatus iStatus;
        icmp_socket->SetOpt(KSoIpTTL, KSolInetIp, ttl);
        icmp_socket->SendTo(data, host, 0, iStatus);
        User::WaitForRequest(iStatus);
        RDebug::Print(_L("Send status: %d"), iStatus);
}

void Tracer::get_reply() {
        RDebug::Print(_L("Get probe reply"));
       
        TBuf8<200> recvBuffer;
        TRequestStatus iStatus;

        icmp_socket->Recv(recvBuffer, KIpHeaderIncluded, iStatus);
        User::WaitForRequest(iStatus);
        if(iStatus == KErrNone) {
                RDebug::Print(_L("Data : %s"), recvBuffer);
        } else {
                RDebug::Print(_L("Reply error: %d"), iStatus);       
        }
}


Mon, 2007-07-30 20:37
Joined: 2006-09-18
Forum posts: 68
Re: Socket Receive Question

I haven't used RDebug before but my feeling is that it is expecting a 16bit buffer and you're supplying it with an 8 bit descriptor.

I'm no expert in icmp requests, and replies nut the reply probably isn't human readable, this might mean that a conversion from the 8bit descriptor to a 16 bit descriptor might not go well. I'm not sure about this, so anyone with a lo of descriptor knowledge might point out the truth. To get integers and the like from a descriptor you can get a pointer to the data it contains with TUint8 * bufferPtr = recvBuffer.Ptr(); then use it like you would any pointer.

  • Login to reply to this topic.