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.
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;
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 cast
ing. Good practice.
2. check the return value of recvfrom()
[or for that case, any library call] for success.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With