serval-dna/nacl/nacl-20110221/curvecp/socket_recv.c
Daniel O'Connor bf9710fd5a Unpacked nacl-20110221 after processing by nacl-prepare-sources.
This only affects build_android, if nacl-gcc-prep is run then build/`uname -s` will be created.
2012-02-27 12:40:14 +10:30

24 lines
560 B
C

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include "socket.h"
#include "byte.h"
long long socket_recv(int fd,unsigned char *x,long long xlen,unsigned char *ip,unsigned char *port)
{
struct sockaddr_in sa;
socklen_t salen;
int r;
if (xlen < 0) { errno = EPROTO; return -1; }
if (xlen > 1048576) xlen = 1048576;
byte_zero(&sa,sizeof sa);
salen = sizeof sa;
r = recvfrom(fd,x,xlen,0,(struct sockaddr *) &sa,&salen);
byte_copy(ip,4,&sa.sin_addr);
byte_copy(port,2,&sa.sin_port);
return r;
}