2 * Copyright (C) 2004 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 /* Please note that this is a stripped down and modified version of
23 the orginal Assuan code from libassuan. */
27 #ifdef HAVE_W32_SYSTEM
31 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include "assuan-defs.h"
37 _assuan_close (int fd
)
39 #ifndef HAVE_W32_SYSTEM
42 int rc
= closesocket (fd
);
43 if (rc
&& WSAGetLastError () == WSAENOTSOCK
)
51 _assuan_sock_new (int domain
, int type
, int proto
)
53 #ifndef HAVE_W32_SYSTEM
54 return socket (domain
, type
, proto
);
56 if (domain
== AF_UNIX
|| domain
== AF_LOCAL
)
58 return socket (domain
, type
, proto
);
64 _assuan_sock_connect (int sockfd
, struct sockaddr
* addr
, int addrlen
)
66 #ifndef HAVE_W32_SYSTEM
67 return connect (sockfd
, addr
, addrlen
);
69 struct sockaddr_in myaddr
;
70 struct sockaddr_un
* unaddr
;
74 unaddr
= (struct sockaddr_un
*)addr
;
75 fp
= fopen (unaddr
->sun_path
, "rb");
78 fscanf (fp
, "%d", &port
);
80 /* XXX: set errno in this case */
81 if (port
< 0 || port
> 65535)
84 myaddr
.sin_family
= AF_INET
;
85 myaddr
.sin_port
= port
;
86 myaddr
.sin_addr
.s_addr
= htonl (INADDR_LOOPBACK
);
88 /* we need this later. */
89 unaddr
->sun_family
= myaddr
.sin_family
;
90 unaddr
->sun_port
= myaddr
.sin_port
;
91 unaddr
->sun_addr
.s_addr
= myaddr
.sin_addr
.s_addr
;
93 return connect (sockfd
, (struct sockaddr
*)&myaddr
, sizeof myaddr
);