Plan 9 from Bell Labs’s /usr/web/sources/patch/sorry/no-oudp-etc/udpecho.c.orig

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


#include <u.h>
#include <libc.h>
#include <ip.h>

void
usage(void)
{
	fprint(2, "usage: %s [-x netmtpt]\n", argv0);
	exits("usage");
}

void
main(int argc, char **argv)
{
	int fd, cfd, n;
	char data[128];
	char devdir[40];
	char buf[4096];
	char net[32];
	char *p;

	setnetmtpt(net, sizeof(net), nil);

	ARGBEGIN{
	case 'x':
		p = ARGF();
		if(p == nil)
			usage();
		setnetmtpt(net, sizeof(net), p);
		break;
	}ARGEND;

	sprint(data, "%s/udp!*!echo", net);
	cfd = announce(data, devdir);
	if(cfd < 0)
		sysfatal("can't announce: %r");
	if(fprint(cfd, "headers") < 0)
		sysfatal("can't set header mode: %r");
	fprint(cfd, "oldheaders");

	sprint(data, "%s/data", devdir);

	fd = open(data, ORDWR);
	if(fd < 0)
		sysfatal("open udp data");
	for(;;){
		n = read(fd, buf, sizeof(buf));
		if(n < 0)
			sysfatal("error reading: %r");
		write(fd, buf, n);
	}
}

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.