Added support for tmcc to compile under Windows with the WIN_SOCK networking API.

parent 58960470
...@@ -34,9 +34,25 @@ int isssl; ...@@ -34,9 +34,25 @@ int isssl;
#define READ tmcd_sslread #define READ tmcd_sslread
#define CLOSE tmcd_sslclose #define CLOSE tmcd_sslclose
#else #else
#ifdef _WIN32
inline int win_send(SOCKET s, const char FAR* buf, int len)
{
return send(s,buf,len,0);
}
inline int win_recv(SOCKET s, char FAR* buf, int len)
{
return recv(s,buf,len,0);
}
#define ACCEPT accept
#define CONNECT connect
#define WRITE win_send
#define READ win_recv
#define CLOSE close
#else
#define ACCEPT accept #define ACCEPT accept
#define CONNECT connect #define CONNECT connect
#define WRITE write #define WRITE write
#define READ read #define READ read
#define CLOSE close #define CLOSE close
#endif #endif /*_WIN32*/
#endif /*WITHSSL*/
...@@ -3,9 +3,22 @@ ...@@ -3,9 +3,22 @@
* Copyright (c) 2000-2003 University of Utah and the Flux Group. * Copyright (c) 2000-2003 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
#ifdef _WIN32
/*Windows version should be linked to: WS2_32*/
/*g++ -Wall -o tmcc tmcc.c -D_WIN32 -lWS2_32*/
#include <winsock2.h>
#include <unistd.h>
#include <getopt.h>
typedef int socklen_t;
#define ECONNREFUSED WSAECONNREFUSED
#endif
#include <sys/types.h> #include <sys/types.h>
#ifndef _WIN32
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#endif
#include <sys/un.h> #include <sys/un.h>
#include <sys/fcntl.h> #include <sys/fcntl.h>
#include <stdio.h> #include <stdio.h>
...@@ -20,18 +33,22 @@ ...@@ -20,18 +33,22 @@
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#ifndef _WIN32
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#endif
#include "decls.h" #include "decls.h"
#include "ssl.h" #include "ssl.h"
#ifndef STANDALONE #ifndef STANDALONE
#include "config.h" #include "config.h"
#endif #endif
#ifndef _WIN32
#undef BOSSNODE #undef BOSSNODE
#ifndef BOSSNODE #ifndef BOSSNODE
#include <resolv.h> #include <resolv.h>
#endif #endif
#endif
#ifndef KEYFILE #ifndef KEYFILE
#define KEYFILE "/etc/emulab.pkey" #define KEYFILE "/etc/emulab.pkey"
...@@ -132,6 +149,9 @@ main(int argc, char **argv) ...@@ -132,6 +149,9 @@ main(int argc, char **argv)
char *keyfile = NULL; char *keyfile = NULL;
char *privkey = NULL; char *privkey = NULL;
char *proxypath= NULL; char *proxypath= NULL;
#ifdef _WIN32
WSADATA wsaData;
#endif
while ((ch = getopt(argc, argv, "v:s:p:un:t:k:x:l:do:")) != -1) while ((ch = getopt(argc, argv, "v:s:p:un:t:k:x:l:do:")) != -1)
switch(ch) { switch(ch) {
...@@ -195,6 +215,14 @@ main(int argc, char **argv) ...@@ -195,6 +215,14 @@ main(int argc, char **argv)
usage(); usage();
} }
#ifdef _WIN32
/*Windows requires us to start up the version of the network API that we want*/
if(WSAStartup( MAKEWORD( 2, 2 ), &wsaData )) {
fprintf(stderr,"WSAStartup failed\n");
exit(1);
}
#endif
if (!bossnode) { if (!bossnode) {
int port = 0; int port = 0;
...@@ -356,6 +384,7 @@ getbossnode(char **bossnode, int *portp) ...@@ -356,6 +384,7 @@ getbossnode(char **bossnode, int *portp)
} }
} }
#ifndef _WIN32
/* /*
* Nameserver goo * Nameserver goo
*/ */
...@@ -365,6 +394,7 @@ getbossnode(char **bossnode, int *portp) ...@@ -365,6 +394,7 @@ getbossnode(char **bossnode, int *portp)
if (he && he->h_name) if (he && he->h_name)
*bossnode = strdup(he->h_name); *bossnode = strdup(he->h_name);
else else
#endif
*bossnode = strdup("UNKNOWN"); *bossnode = strdup("UNKNOWN");
return 0; return 0;
#endif #endif
...@@ -519,8 +549,8 @@ doudp(char *data, int outfd, struct in_addr serverip, int portnum) ...@@ -519,8 +549,8 @@ doudp(char *data, int outfd, struct in_addr serverip, int portnum)
static int static int
dounix(char *data, int outfd, char *unixpath) dounix(char *data, int outfd, char *unixpath)
{ {
#ifdef linux #if defined(linux) || defined(_WIN32)
fprintf(stderr, "unix domain socket mode not supported on linux!\n"); fprintf(stderr, "unix domain socket mode not supported on this platform!\n");
return -1; return -1;
#else #else
int n, sock, cc, length; int n, sock, cc, length;
...@@ -596,8 +626,8 @@ dounix(char *data, int outfd, char *unixpath) ...@@ -596,8 +626,8 @@ dounix(char *data, int outfd, char *unixpath)
static void static void
beproxy(char *localpath, struct in_addr serverip, char *partial) beproxy(char *localpath, struct in_addr serverip, char *partial)
{ {
#ifdef linux #if defined(linux) || defined(_WIN32)
fprintf(stderr, "proxy mode not supported on linux!\n"); fprintf(stderr, "proxy mode not supported on this platform!\n");
exit(-1); exit(-1);
#else #else
int sock, newsock, cc, length; int sock, newsock, cc, length;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment