[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Workarounds for a couple of pieces of windows strangeness.
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv14491/src/common
Modified Files:
crypto.c util.c util.h
Log Message:
Workarounds for a couple of pieces of windows strangeness.
Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- crypto.c 27 Apr 2004 23:50:35 -0000 1.82
+++ crypto.c 28 Apr 2004 19:35:11 -0000 1.83
@@ -41,6 +41,9 @@
#include "util.h"
#ifdef MS_WINDOWS
+#define WIN32_WINNT 0x400
+#define _WIN32_WINNT 0x400
+#define WIN32_LEAN_AND_MEAN
#include <wincrypt.h>
#endif
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- util.c 25 Apr 2004 23:47:26 -0000 1.89
+++ util.c 28 Apr 2004 19:35:11 -0000 1.90
@@ -39,6 +39,9 @@
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -55,6 +58,18 @@
#include <grp.h>
#endif
+#ifdef HAVE_WINSOCK_H
+#define WIN32_WINNT 0x400
+#define _WIN32_WINNT 0x400
+#define WIN32_LEAN_AND_MEAN
+#endif
+#if _MSC_VER > 1300
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#elif defined(_MSC_VER)
+#include <winsock.h>
+#endif
+
/* used by inet_addr, not defined on solaris anywhere!? */
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long) -1)
@@ -1368,6 +1383,42 @@
#endif
}
+/* Similar behavior to Unix gethostbyname: resolve 'name', and set
+ * *addr to the proper IP address, in network byte order. Returns 0
+ * on success, -1 on failure; 1 on transient failure.
+ *
+ * (This function exists because standard windows gethostbyname
+ * doesn't treat raw IP addresses properly.)
+ */
+/* Perhaps eventually this should be replaced by a tor_getaddrinfo or
+ * something.
+ */
+int tor_lookup_hostname(const char *name, uint32_t *addr)
+{
+ struct in_addr iaddr;
+ struct hostent *ent;
+ tor_assert(addr);
+ if (tor_inet_aton(name, &iaddr)) {
+ /* It's an IP. */
+ memcpy(addr, &iaddr.s_addr, 4);
+ return 0;
+ } else {
+ ent = gethostbyname(name);
+ if (ent) {
+ /* break to remind us if we move away from IPv4 */
+ tor_assert(ent->h_length == 4);
+ memcpy(addr, ent->h_addr, 4);
+ return 0;
+ }
+ memset(addr, 0, 4);
+#ifdef MS_WINDOWS
+ return (WSAGetLastError() == WSATRY_AGAIN) ? 1 : -1;
+#else
+ return (h_errno == TRY_AGAIN) ? 1 : -1;
+#endif
+ }
+}
+
/*
Local Variables:
mode:c
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- util.h 25 Apr 2004 19:37:39 -0000 1.56
+++ util.h 28 Apr 2004 19:35:11 -0000 1.57
@@ -212,6 +212,7 @@
struct in_addr;
int tor_inet_aton(const char *cp, struct in_addr *addr);
+int tor_lookup_hostname(const char *name, uint32_t *addr);
/* For stupid historical reasons, windows sockets have an independent set of
* errnos which they use as the fancy strikes them.