Ejemplo n.º 1
0
static int
str2node(int fd, const char *nodestr)
{
	struct eui64 eui, tmpeui;
	struct fw_devlstreq *data;
	char *endptr;
	int i, node;

	if (nodestr == '\0')
		return (-1);

	/*
	 * Deal with classic node specifications.
	 */
	node = strtol(nodestr, &endptr, 0);
	if (*endptr == '\0')
		goto gotnode;

	/*
	 * Try to get an eui and match it against available nodes.
	 */
#ifdef __HAIKU__
	if (eui64_aton(nodestr, &eui) != 0)
#else
	if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
#endif
		return (-1);

	data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
	if (data == NULL)
		err(EX_SOFTWARE, "%s: data malloc", __func__);
	get_dev(fd,data);

	for (i = 0; i < data->info_len; i++) {
		fweui2eui64(&data->dev[i].eui, &tmpeui);
		if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) {
			node = data->dev[i].dst;
			free(data);
			goto gotnode;
		}
	}
	if (i >= data->info_len) {
		if (data != NULL)
			free(data);
		return (-1);
	}

gotnode:
	if (node < 0 || node > 63)
		return (-1);
	else
		return (node);
}
Ejemplo n.º 2
0
static void
test_str(const char *str, const struct eui64 *eui)
{
    struct eui64 e;
    char buf[EUI64_SIZ];
    int rc;

    ATF_REQUIRE_MSG(eui64_aton(str, &e) == 0, "eui64_aton failed");
    rc = memcmp(&e, eui, sizeof(e));
    if (rc != 0) {
        eui64_ntoa(&e, buf, sizeof(buf));
        atf_tc_fail(
            "eui64_aton(\"%s\", ..) failed; memcmp returned %d. "
            "String obtained form eui64_ntoa was: `%s`",
            str, rc, buf);
    }
}
Ejemplo n.º 3
0
/*
 * Parse a string of text containing an EUI-64 and hostname
 * and separate it into its component parts.
 */
static int
eui64_line(const char *l, struct eui64 *e, char *hostname, size_t len)
{
	char *line, *linehead, *cur;

	linehead = strdup(l);
	if (linehead == NULL)
		return (-1);
	line = linehead;

	/* Find and parse the EUI64 */
	while ((cur = strsep(&line, " \t\r\n")) != NULL) {
		if (*cur != '\0') {
			if (eui64_aton(cur, e) == 0)
				break;
			else
				goto bad;
		}
	}

	/* Find the hostname */
	while ((cur = strsep(&line, " \t\r\n")) != NULL) {
		if (*cur != '\0') {
			if (strlcpy(hostname, cur, len) <= len)
				break;
			else
				goto bad;
		}
	}

	/* Make sure what remains is either whitespace or a comment */
	while ((cur = strsep(&line, " \t\r\n")) != NULL) {
		if (*cur == '#')
			break;
		if (*cur != '\0')
			goto bad;
	}

	free(linehead);
	return (0);

bad:
	free(linehead);
	return (-1);
}