Milan Shah
Milan Shah

Reputation: 111

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?

Upvotes: 2

Views: 1455

Answers (2)

user6898715
user6898715

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

Kami Kaze
Kami Kaze

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

Related Questions