Milan Shah Milan Shah - 1 month ago 15
C Question

Compiler warns about argument 6 in call to sendto

socklen_t clilen; // declaration

n = sendto(sockfd1, buffer, sizeof(buffer), 0, (struct sockaddr *)&cli_addr, &clilen);
if(n < 0)
{
printf("\nERROR writing to socket\n");
exit(0);
}


While compiling my code, it is giving me a warning like.....

warning: passing argument 6 of ‘sendto’ makes integer from pointer without a cast [enabled by default]
n = sendto(sockfd1, buffer, sizeof(buffer), 0, (struct sockaddr *)&cli_addr, &clilen);


What to do?

Answer

Just try

n = sendto(sockfd1, buffer, sizeof(buffer), 0, (struct sockaddr *)&cli_addr, clilen);

I think the last argument type is socklen_t and it's not a pointer, so you don't need to pass the the address of the variable; just pass the variable itself it will work and will not give any warning like you are getting now.