static void set_pri_req(int fd, u_int32_t pri_req) { struct fw_devlstreq *data; struct fw_devinfo *devinfo; struct eui64 eui; char addr[EUI64_SIZ]; u_int32_t max, reg, old; int i; data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); if (data == NULL) err(EX_SOFTWARE, "%s:data malloc", __func__); get_dev(fd, data); #define BUGET_REG 0xf0000218 for (i = 0; i < data->info_len; i++) { devinfo = &data->dev[i]; if (!devinfo->status) continue; reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0); fweui2eui64(&devinfo->eui, &eui); eui64_ntoa(&eui, addr, sizeof(addr)); printf("%d %s, %08x", devinfo->dst, addr, reg); if (reg > 0) { old = (reg & 0x3f); max = (reg & 0x3f00) >> 8; if (pri_req > max) pri_req = max; printf(" 0x%x -> 0x%x\n", old, pri_req); read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req); } else {
static void list_dev(int fd) { struct fw_devlstreq *data; struct fw_devinfo *devinfo; struct eui64 eui; char addr[EUI64_SIZ], hostname[40]; int i; data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); if (data == NULL) err(EX_SOFTWARE, "%s:data malloc", __func__); get_dev(fd, data); printf("%d devices (info_len=%d)\n", data->n, data->info_len); printf("node EUI64 status hostname\n"); for (i = 0; i < data->info_len; i++) { devinfo = &data->dev[i]; fweui2eui64(&devinfo->eui, &eui); eui64_ntoa(&eui, addr, sizeof(addr)); if (eui64_ntohost(hostname, sizeof(hostname), &eui)) hostname[0] = 0; printf("%4d %s %6d %s\n", (devinfo->status || i == 0) ? devinfo->dst : -1, addr, devinfo->status, hostname ); } free((void *)data); }
/* * Map an EUI-64 to a hostname. Use either /etc/eui64 or NIS/YP. */ int eui64_ntohost(char *hostname, size_t len, const struct eui64 *id) { FILE *fp; char buf[BUFSIZ + 2]; struct eui64 local_eui64; char local_host[MAXHOSTNAMELEN]; #ifdef YP char *result; int resultlen; char eui64_a[24]; char *yp_domain; #endif if ((fp = fopen(_PATH_EUI64, "re")) == NULL) return (1); while (fgets(buf,BUFSIZ,fp)) { if (buf[0] == '#') continue; #ifdef YP if (buf[0] == '+') { if (yp_get_default_domain(&yp_domain)) continue; eui64_ntoa(id, eui64_a, sizeof(eui64_a)); if (yp_match(yp_domain, "eui64.byid", eui64_a, strlen(eui64_a), &result, &resultlen)) { continue; } strncpy(buf, result, resultlen); buf[resultlen] = '\0'; free(result); } #endif if (eui64_line(buf, &local_eui64, local_host, sizeof(local_host)) == 0) { if (bcmp(&local_eui64.octet[0], &id->octet[0], EUI64_LEN) == 0) { /* We have a match */ strcpy(hostname, local_host); fclose(fp); return(0); } } } fclose(fp); return (1); }
int main(int argc, char **argv) { char a[EUI64_SIZ]; printf("1..1\n"); if (eui64_ntoa(&test_eui64_id, a, sizeof(a)) == 0 && strcmp(a, test_eui64_id_ascii) == 0) { printf("ok 1 - eui64_ntoa\n"); return (0); } printf("# a = '%s'\n", a); printf("not ok 1 - eui64_ntoa\n"); return (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); } }
static int test_line(const char *line, const struct eui64 *eui, const char *host) { struct eui64 e; char buf[256]; static int test = 0; test++; if (eui64_line(line, &e, buf, sizeof(buf)) != 0 || memcmp(&e, eui, sizeof(struct eui64)) != 0 || strcmp(buf, host) != 0) { printf("not ok %d - eui64_line(\"%s\")\n", test, line); printf("# host = %s\n", buf); eui64_ntoa(&e, buf, sizeof(buf)); printf("# e = %s\n", buf); return (0); } else { printf("ok %d - eui64_line(\"%s\")\n", test, line); return (1); } }