Reputation: 3879
I am creating a UDP socket, and attempting to send to an existing server in the code below:
struct sockaddr_in servAddr;
memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = inet_addr(SERVER IP ADDRESS GOES HERE);
servAddr.sin_port = htons(port);
int testSock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
unsigned char byteData;
int sent;
unsigned int servSize = sizeof(servAddr);
if((sent = sendto(testSock, &byteData, 1, 0, (struct sockaddr *)&servAddr, (socklen_t)&servSize)) < 0){
NSLog(@"Error sending to server: %d %d", errno, sent);
}
Every time "sendto" returns -1, and errno is set to 63. I have never encountered this error before.
I can say with complete confidence that there is nothing wrong with the server, or the IP address or port provided. It has to be client-side.
Upvotes: 0
Views: 1174
Reputation: 310869
63 is 'filename too long'. In this case it is the sockaddr that appears too long to the kernel, and that is because you are passing a pointer as the length, instead of the actual length. The final parameter to sendto() isn't a pointer, it is a value. Remove the '&'.
Upvotes: 4