GNUPG-1-9-BRANCH gnupg/jnlib (ChangeLog w32-afunix.c w32-afunix.h)

cvs user twoaday cvs at cvs.gnupg.org
Tue Nov 30 10:41:18 CET 2004


    Date: Tuesday, November 30, 2004 @ 10:48:37
  Author: twoaday
    Path: /cvs/gnupg/gnupg/jnlib
     Tag: GNUPG-1-9-BRANCH

   Added: w32-afunix.c w32-afunix.h
Modified: ChangeLog

2004-11-30  Timo Schulz  <ts at g10code.com>
                                                                                
    * w32-afunix.c: New. AF_UNIX emulation for W32.
    * w32-afunix.h: Likewise.


--------------+
 ChangeLog    |    5 ++
 w32-afunix.c |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 w32-afunix.h |   47 +++++++++++++++++++++++
 3 files changed, 167 insertions(+)


Index: gnupg/jnlib/ChangeLog
diff -u gnupg/jnlib/ChangeLog:1.3.2.17 gnupg/jnlib/ChangeLog:1.3.2.18
--- gnupg/jnlib/ChangeLog:1.3.2.17	Tue Nov 23 18:09:51 2004
+++ gnupg/jnlib/ChangeLog	Tue Nov 30 10:48:37 2004
@@ -1,3 +1,8 @@
+2004-11-30  Timo Schulz  <ts at g10code.com>
+
+	* w32-afunix.c: New. AF_UNIX emulation for W32.
+	* w32-afunix.h: Likewise.
+	
 2004-11-22  Werner Koch  <wk at g10code.com>
 
 	* logging.c (log_test_fd): Add test on LOGSTREAM.  Reported by
Index: gnupg/jnlib/w32-afunix.c
diff -u /dev/null gnupg/jnlib/w32-afunix.c:1.1.2.1
--- /dev/null	Tue Nov 30 10:48:37 2004
+++ gnupg/jnlib/w32-afunix.c	Tue Nov 30 10:48:37 2004
@@ -0,0 +1,115 @@
+/* w32-afunix.c
+ * Copyright (C) 2004 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#ifdef _WIN32
+#include <stdio.h>
+#include <windows.h>
+#include <io.h>
+
+#include "w32-afunix.h"
+
+int
+_w32_close (int fd)
+{
+  int rc = closesocket (fd);
+  if (rc && WSAGetLastError () == WSAENOTSOCK)
+      rc = close (fd);
+  return rc;
+}
+
+
+int
+_w32_sock_new (int domain, int type, int proto)
+{
+  if (domain == AF_UNIX || domain == AF_LOCAL)
+    domain = AF_INET;
+  return socket (domain, type, proto);
+}
+
+
+int
+_w32_sock_connect (int sockfd, struct sockaddr * addr, int addrlen)
+{
+  struct sockaddr_in myaddr;
+  struct sockaddr_un * unaddr;
+  FILE * fp;
+  int port = 0;
+  
+  unaddr = (struct sockaddr_un *)addr;
+  fp = fopen (unaddr->sun_path, "rb");
+  if (!fp)
+      return -1;
+  fscanf (fp, "%d", &port);
+  fclose (fp);
+  /* XXX: set errno in this case */
+  if (port < 0 || port > 65535)
+      return -1;
+  
+  myaddr.sin_family = AF_INET;
+  myaddr.sin_port = port; 
+  myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+  /* we need this later. */
+  unaddr->sun_family = myaddr.sin_family;
+  unaddr->sun_port = myaddr.sin_port;
+  unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
+  
+  return connect (sockfd, (struct sockaddr *)&myaddr, sizeof myaddr);
+}
+
+
+int
+_w32_sock_bind (int sockfd, struct sockaddr * addr, int addrlen)
+{
+  if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX)
+    {
+      struct sockaddr_in myaddr;
+      struct sockaddr_un * unaddr;
+      FILE * fp;
+      int len = sizeof myaddr;
+      int rc;
+
+      myaddr.sin_port = 0;
+      myaddr.sin_family = AF_INET;
+      myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
+
+      rc = bind (sockfd, (struct sockaddr *)&myaddr, len);
+      if (rc)
+        return rc;
+      rc = getsockname (sockfd, (struct sockaddr *)&myaddr, &len);
+      if (rc)
+        return rc;
+      unaddr = (struct sockaddr_un *)addr;
+      fp = fopen (unaddr->sun_path, "wb");
+      if (!fp)
+        return -1;
+      fprintf (fp, "%d", myaddr.sin_port);
+      fclose (fp);
+
+      /* we need this later. */
+      unaddr->sun_family = myaddr.sin_family;
+      unaddr->sun_port = myaddr.sin_port;
+      unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
+      
+      return 0;
+    }
+  return bind (sockfd, addr, addrlen);
+}
+
+#endif /*_WIN32*/
Index: gnupg/jnlib/w32-afunix.h
diff -u /dev/null gnupg/jnlib/w32-afunix.h:1.1.2.1
--- /dev/null	Tue Nov 30 10:48:37 2004
+++ gnupg/jnlib/w32-afunix.h	Tue Nov 30 10:48:37 2004
@@ -0,0 +1,47 @@
+/* w32-afunix.h
+ *	Copyright (C) 2004 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 
+ */
+#ifdef _WIN32
+#ifndef W32AFUNIX_DEFS_H
+#define W32AFUNIX_DEFS_H
+
+#include <sys/types.h>
+#include <windows.h>
+#include <unistd.h>
+
+#define DIRSEP_C '\\'
+
+#define AF_LOCAL AF_UNIX
+/* We need to prefix the structure with a sockaddr_in header so we can
+   use it later for sendto and recvfrom. */
+struct sockaddr_un
+{
+  short          sun_family;
+  unsigned short sun_port;
+  struct         in_addr sun_addr;
+  char           sun_path[108-2-4]; /* Path name.  */
+};
+
+int _w32_close (int fd);
+int _w32_sock_new (int domain, int type, int proto);
+int _w32_sock_bind (int sockfd, struct sockaddr *addr, int addrlen);
+int _w32_sock_connect (int sockfd, struct sockaddr *addr, int addrlen);
+
+#endif /*W32AFUNIX_DEFS_H*/
+#endif /*_WIN32*/




More information about the Gnupg-commits mailing list