X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/85f89d5d09dac0d926aaead2615b154ff4beb65a..db3cdd74484e5994efb077f4283bff6713c0f468:/package/ead/src/ead-client.c diff --git a/package/ead/src/ead-client.c b/package/ead/src/ead-client.c index 111dc8ac6..74b0b4361 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 @@ -143,7 +144,10 @@ static bool handle_pong(void) { struct ead_msg_pong *pong = EAD_DATA(msg, pong); - int len = msg->len - sizeof(struct ead_msg_pong); + int len = ntohl(msg->len) - sizeof(struct ead_msg_pong); + + if (len <= 0) + return false; pong->name[len] = 0; auth_type = ntohs(pong->auth_type); @@ -290,12 +294,13 @@ send_command(const char *command) static int usage(const char *prog) { - fprintf(stderr, "Usage: %s [:]\n" + fprintf(stderr, "Usage: %s [-b ] [:] \n" "\n" - "\n: Node ID (4 digits hex)\n" - "\n: Username to authenticate with\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; } @@ -306,6 +311,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; @@ -321,12 +328,22 @@ int main(int argc, char **argv) local.sin_addr.s_addr = INADDR_ANY; local.sin_port = 0; + while ((ch = getopt(argc, argv, "b:")) != -1) { + switch(ch) { + case 'b': + inet_aton(optarg, &remote.sin_addr); + break; + } + } + 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; @@ -337,15 +354,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);