Martin Ambuhl
4/18/2011 7:51:00 AM
On 4/18/2011 3:12 AM, Martin Ambuhl wrote:
> On 4/18/2011 2:58 AM, Ajit Teli wrote:
>> I am writting a c program to send tcp packet (packet is a string) over
>> socket.
> > Please tell me how to form a string which contains NUL char.
>
> Your TCP documentation may tell you that a packet is a string, but it is
> not, at least not a string as defined in C. It is a series of values,
> probably storable in chars, which is not the same thing.
>
> A string in C is terminated by a char with the value 0, and ASCII NUL is
> such a value. Now you might store the values in an array of char. Every
> string is an array of char, but not every array of char is a string.
> Remember that a string is terminated by a 0-valued char. If your array
> has none, then it is not a string. If it has such a char embedded in
> data, then the initial string ends there.
>
> To send a sequence of values stored in a char array, the simplest way is
> to simply send each of the values until you reach the end of the array.
>
I should add:
If you are doing TCP/IP programming, you should have a library of
functions which handles packets. Perhaps those are in your sockets
library if not in a separate TCP/IP library. You should have routines
to which you pass the address of the packet and perhaps its length as
well, and that routine should handle all the necessary work for you.