Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 642
staigoun Avatar asked Feb 12 '23 07:02

staigoun


2 Answers

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;
like image 193
alk Avatar answered Feb 13 '23 20:02

alk


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.

like image 23
Sourav Ghosh Avatar answered Feb 13 '23 22:02

Sourav Ghosh