summaryrefslogtreecommitdiff
path: root/ucspi-tcp-0.88/socket_remote6.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-31 22:34:58 -0700
committerJohn Denker <jsd@av8n.com>2012-07-31 22:36:28 -0700
commitef6722750b4518fcb29bf983755b5f02451ef224 (patch)
tree966e94ffd01cd8abb59e16a6992e142db345aa9f /ucspi-tcp-0.88/socket_remote6.c
parentb95f5ec1d83519c603f6e2145865c14932c4a813 (diff)
a bunch of files added by the ipv6 patch
Diffstat (limited to 'ucspi-tcp-0.88/socket_remote6.c')
-rw-r--r--ucspi-tcp-0.88/socket_remote6.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/ucspi-tcp-0.88/socket_remote6.c b/ucspi-tcp-0.88/socket_remote6.c
new file mode 100644
index 0000000..e60a539
--- /dev/null
+++ b/ucspi-tcp-0.88/socket_remote6.c
@@ -0,0 +1,39 @@
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include "byte.h"
+#include "socket.h"
+#include "ip6.h"
+#include "haveip6.h"
+#include "error.h"
+
+int socket_remote6(int s,char ip[16],uint16 *port,uint32 *scope_id)
+{
+#ifdef LIBC_HAS_IP6
+ struct sockaddr_in6 sa;
+#else
+ struct sockaddr_in sa;
+#endif
+ unsigned int dummy = sizeof sa;
+
+ if (getpeername(s,(struct sockaddr *) &sa,&dummy) == -1) return -1;
+#ifdef LIBC_HAS_IP6
+ if (sa.sin6_family==AF_INET) {
+ struct sockaddr_in *sa4=(struct sockaddr_in*)&sa;
+ byte_copy(ip,12,V4mappedprefix);
+ byte_copy(ip+12,4,(char *) &sa4->sin_addr);
+ uint16_unpack_big((char *) &sa4->sin_port,port);
+ return 0;
+ }
+ byte_copy(ip,16,(char *) &sa.sin6_addr);
+ uint16_unpack_big((char *) &sa.sin6_port,port);
+ if (scope_id) *scope_id=sa.sin6_scope_id;
+#else
+ byte_copy(ip,12,V4mappedprefix);
+ byte_copy(ip+12,4,(char *) &sa.sin_addr);
+ uint16_unpack_big((char *) &sa.sin_port,port);
+ if (scope_id) *scope_id=0;
+#endif
+ return 0;
+}