summaryrefslogtreecommitdiffstats
path: root/socket_accept.c
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2010-07-09 12:32:17 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2010-07-09 12:32:17 +0200
commit6c027b4de25a529908be895e7ff19236f4002a57 (patch)
treef70d3a400bbb9ba8a83e9d4ffcaa4b6e367fc8bb /socket_accept.c
downloadcrypto-6c027b4de25a529908be895e7ff19236f4002a57.zip
crypto-6c027b4de25a529908be895e7ff19236f4002a57.tar.gz
initial commit, resurrect one of my realy old projects
Diffstat (limited to 'socket_accept.c')
-rw-r--r--socket_accept.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/socket_accept.c b/socket_accept.c
new file mode 100644
index 0000000..61de070
--- /dev/null
+++ b/socket_accept.c
@@ -0,0 +1,22 @@
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include "socket.h"
+#include "uint16.h"
+
+
+int socket_accept4(int s,char ip[4],u16 *port)
+{
+ struct sockaddr_in sa;
+ socklen_t dummy = sizeof sa;
+ int fd;
+
+ fd = accept(s,(struct sockaddr *) &sa,&dummy);
+ if (fd == -1) return -1;
+
+ memcpy(ip,(char *) &sa.sin_addr,4);
+ u16_unpack_big((char *) &sa.sin_port,port);
+
+ return fd;
+}