Question

Good evening everyone.

I'm having trouble creating a TFTP client for an assignment in C++ that uses #include

I'm sending the char buffer:

buffer={'0','2','f','i','l','e','n','a','m','e','0','o','c','t','e','t','0'};

Using the code:

sendto(sock,buffer,strlen(buffer), 0, (sockaddr *) &serverAddr, sizeof(sockaddr));

But when I look at this transfer in the WireShark it says "Opcode: Unknown (12338)" when I look at the Opcode portion of the packet. Even though it has selected the opcode from the string

enter image description here

I'm absolutely stuck, any help would be appreciated. I'm pretty sure if I can send and receive a message I can handle the rest pretty easily.

Just throwing down here what I did but the marked answer was basically it Used the BYTE from winsock2 (don't know if I need to but better safe than sorry)

buffer={(BYTE)0,(BYTE)2,'f','i','l','e','n','a','m','e',(BYTE)0,'o','c','t','e','t',(BYTE)0};

and

sendto(sock,buffer,sizeof(buffer), 0, (sockaddr *) &serverAddr, sizeof(sockaddr));

Was it helpful?

Solution

Not strlen(buffer) but sizeof(buffer)...

strlen stops couting characters at the first occurrence of '\0' - so it returns unspecified value for your buffer array since '\0' is not present in your buffer.

If you want to start your buffer with opcode 02 then pass it as integers not their digit representation:

buffer={0,2,'f','i','l','e','n','a','m','e','0','o','c','t','e','t','0'};
//      ^ ^  simple numbers - not characters - not sure about rest of your buffer

OTHER TIPS

12338 in decimal is 0x30, 0x32 in hex, which corresponds to '0' and '2' from your buffer.

Your using ascii chars, but you need to use a decimal/integer, by setting them to (char) 0x00 and (char) 0x02 in your buffer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top