#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
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];
static struct t_preconf *tcp;
static int auth_type = EAD_AUTH_DEFAULT;
static int timeout = EAD_TIMEOUT;
+static uint16_t sid = 0;
static void
set_nonblock(int enable)
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);
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);
if (nid == 0xffff)
printf("%04x: %s\n", ntohs(msg->nid), pong->name);
+ sid = msg->sid;
return true;
}
static int
usage(const char *prog)
{
- fprintf(stderr, "Usage: %s <node> <username>[:<password>]\n"
+ fprintf(stderr, "Usage: %s [-s <addr>] [-b <addr>] <node> <username>[:<password>] <command>\n"
"\n"
- "\n<node>: Node ID (4 digits hex)\n"
- "\n<username>: Username to authenticate with\n"
+ "\t-s <addr>: Set the server's source address to <addr>\n"
+ "\t-b <addr>: Set the broadcast address to <addr>\n"
+ "\t<node>: Node ID (4 digits hex)\n"
+ "\t<username>: 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;
}
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;
+ msg->sid = 0;
memset(&local, 0, sizeof(local));
memset(&remote, 0, sizeof(remote));
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;
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);
fprintf(stderr, "Device did not accept user name\n");
return 1;
}
+ timeout = EAD_TIMEOUT_LONG;
if (!get_prime()) {
fprintf(stderr, "Failed to get user password info\n");
return 1;
}
-
- timeout = EAD_TIMEOUT_LONG;
if (!send_a()) {
fprintf(stderr, "Failed to send local authentication data\n");
return 1;