Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Help Pls....

short int wavein[644];

wavein[0]=sizeof(wavein);
wavein[1]=0;

here i am sending wavein data through socket....I am monitoring using wire shark it is going as 84 02 00 00. here i need to sent as 02 84 00 00 . can any one pls tell me how to do shift operation to send data like this format 02 84 (hexa value of 644 is 0284)..here i need to change LSB to MSB and MSB to LSB .....Pls reply...Thanks for ur valuable comment
Posted

htons() is your friend. And portable. It converts from the byte order of the host to a a network formatted short.

There's an htonl if you ever need to do the same thing with 32 bit data.
 
Share this answer
 
Comments
Member 9102753 14-Jun-12 8:12am    
Thanks alot my dear friend it works...........
When transmitting data over a network, you should use host-to-net functions to make sure you always send it in a systematic way. Look here htons()[^] and here ntohs()[^] to get it back again.
 
Share this answer
 
Comments
Aescleal 13-Jun-12 14:01pm    
Ninjad by a minute :-)
Niklas L 13-Jun-12 14:04pm    
Ah, beaten. I send a five in your general direction.
Member 9102753 14-Jun-12 8:12am    
Thanks alot my dear friend it works...........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900