简体   繁体   English

当在wireshark中查看时,来自TFTP客户端的未知操作码

[英]Unkown Opcode from TFTP Client when looked at in wireshark

Good evening everyone. 各位晚上好。

I'm having trouble creating a TFTP client for an assignment in C++ that uses #include 我在使用#include在C ++中为赋值创建TFTP客户端时遇到了问题

I'm sending the char buffer: 我正在发送char缓冲区:

buffer={'0','2','f','i','l','e','n','a','m','e','0','o','c','t','e','t','0'}; 缓冲液= { '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)); 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. 但是当我在WireShark中查看此转移时,当我查看数据包的操作码部分时,它会显示“操作码:未知(12338)”。 Even though it has selected the opcode from the string 即使它已从字符串中选择了操作码

在此输入图像描述

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) 只是在这里扔掉我所做的但是标记的答案基本上是使用来自winsock2的BYTE(不知道我是否需要但是比安全更好)

buffer={(BYTE)0,(BYTE)2,'f','i','l','e','n','a','m','e',(BYTE)0,'o','c','t','e','t',(BYTE)0}; 缓冲液= {(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)); sendto(sock,buffer,sizeof(buffer),0,(sockaddr *)&serverAddr,sizeof(sockaddr));

Not strlen(buffer) but sizeof(buffer) ... 不是strlen(buffer)而是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. strlen在第一次出现'\\0'停止couting字符 - 所以它返回缓冲区数组的未指定值,因为缓冲区中不存在'\\0'

If you want to start your buffer with opcode 02 then pass it as integers not their digit representation: 如果你想用操作码02启动缓冲区,那么将它作为整数传递而不是它们的数字表示:

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

12338 in decimal is 0x30, 0x32 in hex, which corresponds to '0' and '2' from your buffer. 十进制的12338是0x30,十六进制的0x32,它对应于缓冲区中的'0'和'2'。

Your using ascii chars, but you need to use a decimal/integer, by setting them to (char) 0x00 and (char) 0x02 in your buffer. 你使用ascii字符,但你需要使用十进制/整数,通过在缓冲区中将它们设置为(char) 0x00(char) 0x02

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM