X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/7619ddb0a299ecde33f5dbaf89bcf6c875507d7f..555b1af398c2b808d93a2e93699bce8dcd2b917a:/package/ead/src/ead-client.c diff --git a/package/ead/src/ead-client.c b/package/ead/src/ead-client.c index 14e04c40b..2592c8f15 100644 --- a/package/ead/src/ead-client.c +++ b/package/ead/src/ead-client.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ static uint16_t nid = 0xffff; struct sockaddr_in local, remote; static int s = 0; static int sockflags; +static struct in_addr serverip = { + .s_addr = 0x01010101 /* dummy */ +}; static unsigned char *skey = NULL; static unsigned char bbuf[MAXPARAMLEN]; @@ -79,6 +83,7 @@ send_packet(int type, bool (*handler)(void), unsigned int max) int res = 0; type = htonl(type); + memcpy(&msg->ip, &serverip.s_addr, sizeof(msg->ip)); set_nonblock(0); sendto(s, msgbuf, sizeof(struct ead_msg) + ntohl(msg->len), 0, (struct sockaddr *) &remote, sizeof(remote)); set_nonblock(1); @@ -293,12 +298,14 @@ send_command(const char *command) static int usage(const char *prog) { - fprintf(stderr, "Usage: %s [:]\n" + fprintf(stderr, "Usage: %s [-s ] [-b ] [:] \n" "\n" - "\n: Node ID (4 digits hex)\n" - "\n: Username to authenticate with\n" + "\t-s : Set the server's source address to \n" + "\t-b : Set the broadcast address to \n" + "\t: Node ID (4 digits hex)\n" + "\t: Username to authenticate with\n" "\n" - "\nPassing no arguments shows a list of active nodes on the network\n" + "\tPassing no arguments shows a list of active nodes on the network\n" "\n", prog); return -1; } @@ -309,6 +316,8 @@ int main(int argc, char **argv) int val = 1; char *st = NULL; const char *command = NULL; + const char *prog = argv[0]; + int ch; msg->magic = htonl(EAD_MAGIC); msg->tid = 0; @@ -324,12 +333,27 @@ int main(int argc, char **argv) local.sin_addr.s_addr = INADDR_ANY; local.sin_port = 0; + while ((ch = getopt(argc, argv, "b:s:h")) != -1) { + switch(ch) { + case 's': + inet_aton(optarg, &serverip); + break; + case 'b': + inet_aton(optarg, &remote.sin_addr); + break; + case 'h': + return usage(prog); + } + } + argv += optind; + argc -= optind; + switch(argc) { - case 4: - command = argv[3]; - /* fall through */ case 3: - username = argv[2]; + command = argv[2]; + /* fall through */ + case 2: + username = argv[1]; st = strchr(username, ':'); if (st) { *st = 0; @@ -340,15 +364,15 @@ int main(int argc, char **argv) memset(st, 0, strlen(st)); } /* fall through */ - case 2: - nid = strtoul(argv[1], &st, 16); + case 1: + nid = strtoul(argv[0], &st, 16); if (st && st[0] != 0) - return usage(argv[0]); + return usage(prog); /* fall through */ - case 1: + case 0: break; default: - return usage(argv[0]); + return usage(prog); } msg->nid = htons(nid);