Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/ndb/glean/iap.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ndb.h>
#include <ip.h>
#include "nbcache.h"

enum {
	Iapttl = 30
};

/*
 * This packet format is Snell and Wilcox Propritory
 * and is a simple service advertising protocol
 */
void
iap(Pkt *p)
{
	Node *n;
	uchar ipaddr[IPv4addrlen];
	char *attr[64], *value[64];
	int i, num, sys, ip, ver, iap;

	if((num = tokenize((char *)p->pos, attr, nelem(attr))) < 1)
		return;

	ip = -1;
	iap = -1;
	sys = -1;
	ver = -1;
	for(i = 0; i < num; i++){
		if((value[i] = strchr(attr[i], '=')) != nil)
			*value[i]++ = 0;

		strlwr(attr[i]);
		if(strcmp(attr[i], "ipaddr") == 0)
			ip = i;
		if(strcmp(attr[i], "iap") == 0)
			iap = i;
		if(strcmp(attr[i], "sys") == 0)
			sys = i;
		if(strcmp(attr[i], "version") == 0)
			ver = i;
	}

	if(iap == -1)
		return;

	if(ver == -1 || strcmp(value[ver], "1.0") != 0){
		print("wrong version\n");
		return;
	}

	if(sys != -1)
		n = getnode(Thost, Iapttl, "%s", value[sys]);
	else
	if(ip != -1)
		n = getnode(Thost, Iapttl, "iap-%s", value[ip]);
	else
		return;

	setval(n, "ip", value[ip]);
	v4parseip(ipaddr, value[ip]);

	if(Debug)
		setval(n, "src", "iap");

	for(i = 1; i < num; i++){
		if(i == ver || i == sys || i == ip)
			continue;
		setval(n, attr[i], "%s", value[i]);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.