Reputation: 111
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?
Upvotes: 2
Views: 1455
Reputation:
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.
Upvotes: 4
Reputation: 2080
The prototype is
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,const struct sockaddr *dest_addr, socklen_t addrlen);
So the last argument is not a pointer but an integer of type socklen_t
So just pass a (socklen_t) sizeof (struct sockaddr)
and you should be fine. It says its the 6th parameter but you are working on the 5th.
Upvotes: 1