staigoun
staigoun

Reputation: 75

Differ in signedness - warning

I don't understand my warning in gcc compiler. Warning is: warning: pointer targets in passing argument 6 of ‘recvfrom’ differ in signedness I don't know, where is a problem, I am not using signed and unsigned value.

Problem is on line:

recvfrom(server_socket, inputbuffer, maxLenght, 0, (struct sockaddr*) remote_addr, &server_addr_len);

I tried this:

recvfrom(server_socket, inputbuffer, maxLenght, 0, (unsigned int) remote_addr, &server_addr_len);

But it didn't help me. Thank you for your advice and explanation.

Upvotes: 5

Views: 4984

Answers (3)

Sourav Ghosh
Sourav Ghosh

Reputation: 134356

See the man page of recvfrom().

It says, the function prototype is

 ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
             struct sockaddr *src_addr, socklen_t *addrlen);

The 6th argument is socklen_t *addrlen. So, while calling recvfrom() from your application, you have to use it like

socklen_t server_addr_len = 0;
struct sockaddr * remote_addr = NULL;
ssize_t retval = 0;
.
. 
retval = recvfrom(server_socket, inputbuffer, maxLenght, 0, remote_addr, &server_addr_len);

SideNotes:

1. Define the variables in a way so that they do not need casting. Good practice.

2. check the return value of recvfrom() [or for that case, any library call] for success.

Upvotes: 2

Iharob Al Asimi
Iharob Al Asimi

Reputation: 53016

Just declare server_addr_len as socklen_t

socklen_t server_addr_len;

since the recvfrom function signature is

ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
         struct sockaddr *src_addr, socklen_t *addrlen);

Upvotes: 1

alk
alk

Reputation: 70971

From man recvfrom():

ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
                    struct sockaddr *src_addr, socklen_t *addrlen);

recvfrom() expects a socklen_t as 6th parameter. You probably pass an int.

So define server_addr_len like so:

socklen_t server_addr_len;

Upvotes: 6

Related Questions