Commit 2b1bb6ed authored by Leigh B. Stoller's avatar Leigh B. Stoller

Did this a while back. Add UDP mode to tmcc, using Mike's udp testmode

stuff. Use -p option to use UDP instead of TCP connection.
parent e2ab35f8
...@@ -12,7 +12,7 @@ all: tmcd tmcc tmcd.restart findif ...@@ -12,7 +12,7 @@ all: tmcd tmcc tmcd.restart findif
include $(TESTBED_SRCDIR)/GNUmakerules include $(TESTBED_SRCDIR)/GNUmakerules
CFLAGS += -O -g -DTBDBNAME='"$(TBDBNAME)"' -I/usr/local/include CFLAGS += -O -g -DUDP -DTBDBNAME='"$(TBDBNAME)"' -I/usr/local/include
tmcd: tmcd.o tmcd: tmcd.o
$(CC) $(CFLAGS) -o tmcd tmcd.o \ $(CC) $(CFLAGS) -o tmcd tmcd.o \
......
...@@ -44,23 +44,23 @@ main(int argc, char **argv) ...@@ -44,23 +44,23 @@ 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 = "";
#ifdef UDPTEST #ifdef UDP
int useudp = 0; int useudp = 0;
void doudp(int argc, char **argv); void doudp(int argc, char **argv);
if (argc > 1 && strcmp(argv[1], "-u") == 0) {
useudp = 1;
argc--, argv++;
}
#endif #endif
portnum = TBSERVER_PORT; portnum = TBSERVER_PORT;
while ((ch = getopt(argc, argv, "p:")) != -1) while ((ch = getopt(argc, argv, "p:u")) != -1)
switch(ch) { switch(ch) {
case 'p': case 'p':
portnum = atoi(optarg); portnum = atoi(optarg);
break; break;
#ifdef UDP
case 'u':
useudp = 1;
break;
#endif
default: default:
usage(); usage();
} }
...@@ -71,6 +71,16 @@ main(int argc, char **argv) ...@@ -71,6 +71,16 @@ main(int argc, char **argv)
} }
argv += optind; argv += optind;
#ifdef UDP
if (useudp) {
doudp(argc, argv);
/*
* Never returns.
*/
abort();
}
#endif
#ifdef LBS #ifdef LBS
inet_aton(MASTERNODE, &serverip); inet_aton(MASTERNODE, &serverip);
#else #else
...@@ -83,10 +93,6 @@ main(int argc, char **argv) ...@@ -83,10 +93,6 @@ main(int argc, char **argv)
} }
#endif #endif
#ifdef UDPTEST
if (useudp)
doudp(argc, argv);
#endif
while (1) { while (1) {
/* Create socket from which to read. */ /* Create socket from which to read. */
sock = socket(AF_INET, SOCK_STREAM, 0); sock = socket(AF_INET, SOCK_STREAM, 0);
...@@ -134,7 +140,10 @@ main(int argc, char **argv) ...@@ -134,7 +140,10 @@ main(int argc, char **argv)
} }
#endif #endif
#endif #endif
/* Since we've gone through a getopt() pass, argv[0] is now the first argument */ /*
* Since we've gone through a getopt() pass, argv[0] is now the
* first argument
*/
switch(argc) { switch(argc) {
case 1: case 1:
n = snprintf(buf, sizeof(buf) - 1, "%s", argv[0]); n = snprintf(buf, sizeof(buf) - 1, "%s", argv[0]);
...@@ -199,7 +208,7 @@ sigcatcher(int foo) ...@@ -199,7 +208,7 @@ sigcatcher(int foo)
{ {
} }
#ifdef UDPTEST #ifdef UDP
/* /*
* Not very robust, send a single request, read a single reply. * Not very robust, send a single request, read a single reply.
*/ */
...@@ -212,11 +221,6 @@ doudp(int argc, char **argv) ...@@ -212,11 +221,6 @@ doudp(int argc, char **argv)
struct in_addr serverip; struct in_addr serverip;
char buf[MYBUFSIZE], *bp, *response = ""; char buf[MYBUFSIZE], *bp, *response = "";
if (argc < 2 || argc > 3) {
fprintf(stderr, "usage: %s <command>\n", argv[0]);
exit(1);
}
#ifdef LBS #ifdef LBS
inet_aton(MASTERNODE, &serverip); inet_aton(MASTERNODE, &serverip);
#else #else
...@@ -241,10 +245,26 @@ doudp(int argc, char **argv) ...@@ -241,10 +245,26 @@ doudp(int argc, char **argv)
name.sin_addr = serverip; name.sin_addr = serverip;
name.sin_port = htons(TBSERVER_PORT); name.sin_port = htons(TBSERVER_PORT);
if (argc == 2) /*
n = snprintf(buf, sizeof(buf) - 1, "%s", argv[1]); * Since we've gone through a getopt() pass, argv[0] is now the
else * first argument
n = snprintf(buf, sizeof(buf) - 1, "%s %s", argv[1], argv[2]); */
switch(argc) {
case 1:
n = snprintf(buf, sizeof(buf) - 1, "%s", argv[0]);
break;
case 2:
n = snprintf(buf, sizeof(buf) - 1, "%s %s", argv[0], argv[1]);
break;
case 3:
n = snprintf(buf, sizeof(buf) - 1, "%s %s %s",
argv[0], argv[1], argv[2]);
break;
default:
fprintf(stderr, "Too many command arguments!\n");
exit(1);
}
if (n >= sizeof(buf)) { if (n >= sizeof(buf)) {
fprintf(stderr, "Command too large!\n"); fprintf(stderr, "Command too large!\n");
exit(1); exit(1);
......
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