Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No matching function for call to recvfrom in iOS

Tags:

xcode

sockets

I have

  #include <sys/socket.h>
   recvfrom(s, dgram, sizeof(dgram), size, (struct sockaddr*)&adr, &x);

I receive no matching function for call to recvfrom in iOS. but Xocde does show the prototype

 recvfrom(int, void*, size_t, int, struct sockaddr *, socklen_t*)

So, Why does Xcode give no matching function error on recvfrom?

like image 715
lilzz Avatar asked Feb 16 '23 04:02

lilzz


2 Answers

It is likely that one of the arguments is of an incorrect type. Try compiling the code through your terminal with gcc for better error messages. For some reason Xcode is really vague about this one.

Make sure that the x in your 6th argument &x is an 'socklen_t *' (aka 'unsigned int *'), not an int. That's what caused me to get this error.

like image 54
user3417450 Avatar answered Feb 23 '23 14:02

user3417450


Use socklen_t for x

socklen_t x = sizeof(servaddr);
uint8_t buffer[1024];

long nBytes = 
     recvfrom(socket, buffer, 1024, 0, (struct sockaddr *) &servaddr, &x)
like image 28
Mike Zriel Avatar answered Feb 23 '23 12:02

Mike Zriel