コード例 #1
0
ファイル: eui64.c プロジェクト: hmatyschok/MeshBSD
/*
 * 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);
}
コード例 #2
0
ファイル: eui64.c プロジェクト: hmatyschok/MeshBSD
/*
 * Map a hostname to an EUI-64 using /etc/eui64 or NIS/YP.
 */
int
eui64_hostton(const char *hostname, struct eui64 *id)
{
	FILE *fp;
	char buf[BUFSIZ + 2];
	struct eui64 local_eui64;
	char local_host[MAXHOSTNAMELEN];
#ifdef YP
	char *result;
	int resultlen;
	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;
			if (yp_match(yp_domain, "eui64.byname", hostname,
				strlen(hostname), &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 (strcmp(hostname, local_host) == 0) {
				/* We have a match */
				bcopy(&local_eui64, id, sizeof(struct eui64));
				fclose(fp);
				return(0);
			}
		}
	}
	fclose(fp);
	return (1);
}
コード例 #3
0
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);
	}
}