diff options
Diffstat (limited to 'nacl/curvecp/socket_recv.c')
-rw-r--r-- | nacl/curvecp/socket_recv.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/nacl/curvecp/socket_recv.c b/nacl/curvecp/socket_recv.c new file mode 100644 index 00000000..8b266ba2 --- /dev/null +++ b/nacl/curvecp/socket_recv.c | |||
@@ -0,0 +1,23 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <sys/socket.h> | ||
3 | #include <netinet/in.h> | ||
4 | #include <errno.h> | ||
5 | #include "socket.h" | ||
6 | #include "byte.h" | ||
7 | |||
8 | long long socket_recv(int fd,unsigned char *x,long long xlen,unsigned char *ip,unsigned char *port) | ||
9 | { | ||
10 | struct sockaddr_in sa; | ||
11 | socklen_t salen; | ||
12 | int r; | ||
13 | |||
14 | if (xlen < 0) { errno = EPROTO; return -1; } | ||
15 | if (xlen > 1048576) xlen = 1048576; | ||
16 | |||
17 | byte_zero(&sa,sizeof sa); | ||
18 | salen = sizeof sa; | ||
19 | r = recvfrom(fd,x,xlen,0,(struct sockaddr *) &sa,&salen); | ||
20 | byte_copy(ip,4,&sa.sin_addr); | ||
21 | byte_copy(port,2,&sa.sin_port); | ||
22 | return r; | ||
23 | } | ||