Commit 0da91307 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add [-s server] argument so I can redirect to arbitrary tmcd. Good for

debugging. Make sure it gets passed through to udp case (-u), although
the udp case is going to get killed when we ssl'ize tmcd.
parent dd39d68d
...@@ -23,10 +23,16 @@ ...@@ -23,10 +23,16 @@
void sigcatcher(int foo); void sigcatcher(int foo);
char *getbossnode(void); char *getbossnode(void);
#ifdef UDP
void doudp(int argc, char **argv, struct in_addr, int port);
#endif
char *usagestr = char *usagestr =
"usage: tmcc [-p #] <command>\n" "usage: tmcc [-u] [-p #] [-s server] <command>\n"
" -s server Specify a tmcd server to connect to\n"
" -p portnum Specify a port number to connect to\n" " -p portnum Specify a port number to connect to\n"
" -u Use UDP instead of TCP\n"
"\n"; "\n";
void void
...@@ -48,19 +54,21 @@ main(int argc, char **argv) ...@@ -48,19 +54,21 @@ main(int argc, char **argv)
struct hostent *he; struct hostent *he;
struct in_addr serverip; struct in_addr serverip;
char buf[MYBUFSIZE], *bp, *response = ""; char buf[MYBUFSIZE], *bp, *response = "";
char *bossnode; char *bossnode = NULL;
#ifdef UDP #ifdef UDP
int useudp = 0; int useudp = 0;
void doudp(int argc, char **argv, struct in_addr);
#endif #endif
portnum = TBSERVER_PORT; portnum = TBSERVER_PORT;
while ((ch = getopt(argc, argv, "p:u")) != -1) while ((ch = getopt(argc, argv, "s:p:u")) != -1)
switch(ch) { switch(ch) {
case 'p': case 'p':
portnum = atoi(optarg); portnum = atoi(optarg);
break; break;
case 's':
bossnode = optarg;
break;
#ifdef UDP #ifdef UDP
case 'u': case 'u':
useudp = 1; useudp = 1;
...@@ -76,7 +84,8 @@ main(int argc, char **argv) ...@@ -76,7 +84,8 @@ main(int argc, char **argv)
} }
argv += optind; argv += optind;
bossnode = getbossnode(); if (!bossnode)
bossnode = getbossnode();
he = gethostbyname(bossnode); he = gethostbyname(bossnode);
if (he) if (he)
memcpy((char *)&serverip, he->h_addr, he->h_length); memcpy((char *)&serverip, he->h_addr, he->h_length);
...@@ -95,7 +104,7 @@ main(int argc, char **argv) ...@@ -95,7 +104,7 @@ main(int argc, char **argv)
#ifdef UDP #ifdef UDP
if (useudp) { if (useudp) {
doudp(argc, argv, serverip); doudp(argc, argv, serverip, portnum);
/* /*
* Never returns. * Never returns.
*/ */
...@@ -244,7 +253,7 @@ getbossnode(void) ...@@ -244,7 +253,7 @@ getbossnode(void)
* Not very robust, send a single request, read a single reply. * Not very robust, send a single request, read a single reply.
*/ */
void void
doudp(int argc, char **argv, struct in_addr serverip) doudp(int argc, char **argv, struct in_addr serverip, int portnum)
{ {
int sock, length, n, cc; int sock, length, n, cc;
struct sockaddr_in name, client; struct sockaddr_in name, client;
...@@ -260,7 +269,7 @@ doudp(int argc, char **argv, struct in_addr serverip) ...@@ -260,7 +269,7 @@ doudp(int argc, char **argv, struct in_addr serverip)
/* Create name. */ /* Create name. */
name.sin_family = AF_INET; name.sin_family = AF_INET;
name.sin_addr = serverip; name.sin_addr = serverip;
name.sin_port = htons(TBSERVER_PORT); name.sin_port = htons(portnum);
/* /*
* Since we've gone through a getopt() pass, argv[0] is now the * Since we've gone through a getopt() pass, argv[0] is now the
......
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