summaryrefslogtreecommitdiff
path: root/nacl/curvecp/socket_recv.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
commite2967396ac73cb7410787886cdaf072a184ffc49 (patch)
tree527a74d25a4a0705fc641994fd35bfab22662034 /nacl/curvecp/socket_recv.c
parent8928c817df345f29aa0b194743595aa11bd6a8ba (diff)
Added NaCl crypto library.
Diffstat (limited to 'nacl/curvecp/socket_recv.c')
-rw-r--r--nacl/curvecp/socket_recv.c23
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
8long 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}