I am using ssize_t send(int sockfd, const void *buf, size_t len, int flags); from socket.h file. I have some doubts about it.
Doubt 1:If suppose the string I am passing to send is of length 10 and the length i specified in the third parameter is 15. Then what will send only send 10 chars or it will send 15 chars (which it gets by reading unallocated memory for last 5 chars).
What will happen in the reverse case means if length of second parameter is more than third parameter.
Doubt 2:I am assuming the length of second parameter is equal to third parameter. Now if the second parameter is say – "abc\0def\0qw". Its length is 11. Will send send the whole string or \0 have any of its effect. I think it will send the whole string. How really send works.
If someone know any good source about send, recv which discuss these function in depth pls share.
The
sendfunction knows nothing about “strings”. If you give it a pointer, and tell it to send the next 15 bytes after that pointer, then that is EXACTLY what it will try to do. (You may well encounter a Seg-Fault or similar if you give it an inappropriatelenvalue).There is no justification for believing that it would stop just because it finds a byte with value
0x00. After all, many network protocols are FILLED with0x00all over the place. You can’t havesendstopping every time it happens to find that value.