Skip to main content

This is a new website theme. Help me improve it and give your feedback (opens in a new tab).

Toy Finger Daemon

Published:

Tags:

Openbsd Finger Retro Journal
This blog post is more than two years old. It is preserved here in the hope that it is useful to someone, but please be aware that links may be broken and that opinions expressed here may not reflect my current views. If this is a technical article, it may no longer reflect current best practice.

The finger protocol is defined in RFC742. It’s a pretty simple protocol. I’d like to have a more useful output at some point, perhaps including status updates from Mastodon or APRS, but for now I’ve got the hang of reading the request and sending some output with some simple C program.

It uses inetd just like the Gopher server.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static __dead void
handle_query(char *input, int len)
{
	if (len == 0) {
		printf("Summary:\n\n");
		printf("-USER-\n");
		printf("irl\n");
	} else if (len == 3 && memcmp(input, "irl", 3) == 0) {
		printf("+-----+\n");
		printf("| irl |\n");
		printf("+-----+\n");
		printf("\n");
		printf("  gopher://irl.xyz/1/\n");
		printf("  sip:[email protected]\n");
		printf("  https://iain.learmonth.me/\n");
		printf("  https://hackers.town/@irl/\n");
		printf("  mailto:[email protected]\n");
	} else {
		printf("Unknown input of %d bytes\n", len);
	}
	exit(0);
}

int
main(int argc, char **argv)
{
	char input[256];
	int i, pos = 0;

	while (pos < 256)
	{
		pos += read(0, &input[pos], 256 - pos);
		for (i = 0; i < pos; i++)
		{
			if (input[i] == '\r' || input[i] == '\n')
				handle_query(input, i);
		}
	}

	printf("Invalid\n");
}