I'm experiencing a strange issue with sockets on OSX Sierra. If there is a null byte anywhere in my data, send() will truncate the data at the null byte and then append "\r\n" to my packet. However, send() still returns the length of the original packet I requested it to send, despite not actually sending that much data.
Here's some code:
int sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
int ret = connect(sock, pAddrInfo->ai_addr, (int)pAddrInfo->ai_addrlen);
if(ret >= 0){
char * packet = (char *)calloc(12,1);
((uint32_t *)packet)[0]= 0xffffffff;
((uint32_t *)packet)[1]= htonl(0x00111111);
((uint32_t *)packet)[2]= htonl(0x11110D0A);
ret = send(sock, (void *)packet, 12, 0);
if(ret < 0)
printf("send failed");
else
printf("sent %d bytes", ret);
}else{
printf("connect failed");
}
After this code I see that send returned 12 bytes were sent, but when capturing the packets with wireshark I see the TCP payload only has length 6 and that the data is FF FF FF FF 0D 0A. I expect to see FF FF FF FF 00 11 11 11 11 11 0D 0A.
This seems to only happen on OSX Sierra. I have tried on a machine running El Capitan and the code works as expected.
I am using xcode 8.0
Thanks.