summaryrefslogtreecommitdiff
path: root/otherlibs/unix/getpeername_unix.c
diff options
context:
space:
mode:
authorSébastien Hinderer <Sebastien.Hinderer@inria.fr>2022-04-06 15:34:05 +0200
committerSébastien Hinderer <Sebastien.Hinderer@inria.fr>2022-04-10 10:03:47 +0200
commit988349da1a92da125d3722e306d02931ac428b2a (patch)
treed781b0769307e0ce8c4f1aeb207bdc85f88d2657 /otherlibs/unix/getpeername_unix.c
parent776f3365991178d66cc86728a59dac5e118b1c95 (diff)
downloadocaml-988349da1a92da125d3722e306d02931ac428b2a.tar.gz
otherlibs: Merge win32unix into unix
Diffstat (limited to 'otherlibs/unix/getpeername_unix.c')
-rw-r--r--otherlibs/unix/getpeername_unix.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/otherlibs/unix/getpeername_unix.c b/otherlibs/unix/getpeername_unix.c
new file mode 100644
index 0000000000..9390b55b6a
--- /dev/null
+++ b/otherlibs/unix/getpeername_unix.c
@@ -0,0 +1,41 @@
+/**************************************************************************/
+/* */
+/* OCaml */
+/* */
+/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 1996 Institut National de Recherche en Informatique et */
+/* en Automatique. */
+/* */
+/* All rights reserved. This file is distributed under the terms of */
+/* the GNU Lesser General Public License version 2.1, with the */
+/* special exception on linking described in the file LICENSE. */
+/* */
+/**************************************************************************/
+
+#include <caml/fail.h>
+#include <caml/mlvalues.h>
+#include "unixsupport.h"
+
+#ifdef HAS_SOCKETS
+
+#include "socketaddr.h"
+
+CAMLprim value unix_getpeername(value sock)
+{
+ int retcode;
+ union sock_addr_union addr;
+ socklen_param_type addr_len;
+
+ addr_len = sizeof(addr);
+ retcode = getpeername(Int_val(sock), &addr.s_gen, &addr_len);
+ if (retcode == -1) uerror("getpeername", Nothing);
+ return alloc_sockaddr(&addr, addr_len, -1);
+}
+
+#else
+
+CAMLprim value unix_getpeername(value sock)
+{ caml_invalid_argument("getpeername not implemented"); }
+
+#endif