Commit e9213b16 authored by Leigh Stoller's avatar Leigh Stoller

Add -z (zero) option to the client, passed into the imageunzip

library.
Add -b option to explicitly turn on broadcast mode (client and
server), and fiddle with options and network init slightly so that
I can do simple unicast experiments between two nodes.
parent b274bdf1
......@@ -37,7 +37,8 @@ static void PlayFrisbee(void);
static void GotBlock(Packet_t *p);
static void RequestChunk(int timedout);
static int ImageUnzip(int chunk);
extern int ImageUnzipInit(char *filename, int slice, int debug);
extern int ImageUnzipInit(char *filename, int slice, int debug, int zero);
extern int ImageUnzipQuit();
/*
* The chunker data structure. For each chunk in progress, we maintain this
......@@ -88,6 +89,8 @@ char *usagestr =
" -m mcastaddr Specify a multicast address in dotted notation.\n"
" -i mcastif Specify a multicast interface in dotted notation.\n"
" -s slice Output to DOS slice (DOS numbering 1-4)\n"
" -z Zero fill the output device\n"
" -b Use broadcast instead of multicast\n"
" NOTE: Must specify a raw disk device for output filename.\n"
"\n";
......@@ -101,15 +104,19 @@ usage()
int
main(int argc, char **argv)
{
int ch, slice = 0;
int ch, slice = 0, zero = 0;
char *filename;
while ((ch = getopt(argc, argv, "dhp:m:s:i:t")) != -1)
while ((ch = getopt(argc, argv, "dhp:m:s:i:tbz")) != -1)
switch(ch) {
case 'd':
debug++;
break;
case 'b':
broadcast++;
break;
case 'p':
portnum = atoi(optarg);
break;
......@@ -130,6 +137,10 @@ main(int argc, char **argv)
tracing++;
break;
case 'z':
zero++;
break;
case 'h':
case '?':
default:
......@@ -146,7 +157,7 @@ main(int argc, char **argv)
usage();
ClientLogInit();
ImageUnzipInit(filename, slice, debug);
ImageUnzipInit(filename, slice, debug, zero);
ClientNetInit();
if (tracing) {
......@@ -155,6 +166,7 @@ main(int argc, char **argv)
}
PlayFrisbee();
ImageUnzipQuit();
if (tracing) {
TraceStop();
......
......@@ -128,6 +128,7 @@ int fsleep(unsigned int usecs);
*/
extern int debug;
extern int portnum;
extern int broadcast;
extern struct in_addr mcastaddr;
extern struct in_addr mcastif;
extern char *filename;
......@@ -29,6 +29,7 @@
static int sock;
struct in_addr myipaddr;
int broadcast = 0;
static void
CommonInit(void)
......@@ -99,16 +100,25 @@ CommonInit(void)
pfatal("setsockopt(IPPROTO_IP, IP_MULTICAST_IF)");
}
}
else {
else if (broadcast) {
/*
* Otherwise, we use a broadcast addr.
*/
i = 1;
log("Setting broadcast mode\n");
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
&i, sizeof(i)) < 0)
pfatal("setsockopt(SOL_SOCKET, SO_BROADCAST)");
}
else if (mcastif.s_addr) {
/*
* Overload this. In unicast mode, use this as our
* outgoing interface. Useful when multihomed.
*/
myipaddr.s_addr = mcastif.s_addr;
}
/*
* We use a socket level timeout instead of polling for data.
......@@ -125,13 +135,15 @@ CommonInit(void)
* This is going to be used to return replies to the sender,
* where appropriate.
*/
if (gethostname(buf, sizeof(buf)) < 0)
pfatal("gethostname failed");
if (!myipaddr.s_addr) {
if (gethostname(buf, sizeof(buf)) < 0)
pfatal("gethostname failed");
if ((he = gethostbyname(buf)) == 0)
fatal("gethostbyname: %s", hstrerror(h_errno));
if ((he = gethostbyname(buf)) == 0)
fatal("gethostbyname: %s", hstrerror(h_errno));
memcpy((char *)&myipaddr, he->h_addr, sizeof(myipaddr));
memcpy((char *)&myipaddr, he->h_addr, sizeof(myipaddr));
}
}
int
......
......@@ -276,8 +276,11 @@ ServerRecvThread(void *arg)
DOSTAT(requests++);
ClientRequest(p);
break;
case PKTSUBTYPE_BLOCK:
break;
default:
fatal("ServerRecvThread: Bad packet type!");
fatal("ServerRecvThread: Bad packet type: %d/%d!",
p->hdr.type, p->hdr.subtype);
break;
}
}
......@@ -392,9 +395,10 @@ PlayFrisbee(void)
char *usagestr =
"usage: frisbeed [-d] <-p #> <-m mcastaddr> <filename>\n"
" -d Turn on debugging. Multiple -d options increase output.\n"
" -p portnum Specify a port number to listen on.\n"
" -m mcastaddr Specify a multicast address in dotted notation.\n"
" -i mcastif Specify a multicast interface in dotted notation.\n"
" -p portnum Specify a port number to listen on.\n"
" -m mcastaddr Specify a multicast address in dotted notation.\n"
" -i mcastif Specify a multicast interface in dotted notation.\n"
" -b Use broadcast instead of multicast\n"
"\n";
void
......@@ -411,8 +415,12 @@ main(int argc, char **argv)
pthread_t child_pid;
off_t fsize;
while ((ch = getopt(argc, argv, "dhp:m:i:t")) != -1)
while ((ch = getopt(argc, argv, "dhp:m:i:tb")) != -1)
switch(ch) {
case 'b':
broadcast++;
break;
case 'd':
debug++;
break;
......
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