I am new to C/C++. I am using the following code to send multiple messages to my server. A CONNECT message, a new line and then a null terminator. But when I send these messages, they are getting converted somewhere. I collected the messages exchanged using Wireshark. Because of the difference in what I am sending and what really got sent to the server, my server doesn’t respond well. Please help. Thank you.
C code (What I am trying to send):
sockfd = socket(AF_INET, SOCK_STREAM, 0);
char peer0_0[] = {0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x0d, 0x0a };
char peer0_1[] = {0x0d, 0x0a }; //NEW LINE
char peer0_2[] = {0x00, 0x0d, 0x0a }; //NULL TERM
n = send(sockfd,peer0_0,strlen(peer0_0),0);
n = send(sockfd,peer0_1,strlen(peer0_1),0);
n = send(sockfd,peer0_2,strlen(peer0_2),0);
What I see in Wireshark (going to the server):
char peer0_0[] = {0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x0d, 0x0a };
char peer0_1[] = {0x0d, 0x0a, 0xc3, 0x5f, 0xff, 0x7f };
You use
strlen, but the arrays are not null terminated. Usesizeof:strlenis no good, as you have null terminator inside the third array (the first byte), sostrlen(peer0_2)= 0.