All pastes #460025 Raw Edit

Simple UDP-based netbeep

public c v1 · immutable
#460025 ·published 2007-04-26 20:18 UTC
rendered paste body
/* * Ultra-simple UDP-based network beeper * should be started by xinetd like: *	socket_type     = dgram *	type		= UNLISTED *	protocol        = udp *	port		= HERE-SOME-PORT-NUMBER *	wait            = yes *	server		= HERE-GUESS-WHAT *	only_from	= HERE-SOME-IP * * We don't use no auth or args sanitization, assume 'beep' is in /usr/bin. Have fun. * * (C) 2007 Michal Gorny * redistributed under GPL2 terms */#include <stdlib.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/socket.h>#include <sys/ioctl.h>#include <termios.h>#include <fcntl.h>#include <unistd.h>int main(void) {	char buf[64];	int n;	struct sockaddr sa;	ssize_t ss = sizeof(sa);			/* stolen from netkit-tftp		 * ftp://ftp.uk.linux.org/pub/linux/Networking/netkit/		 */	{		int on = 1;				if (ioctl(0, FIONBIO, &on) < 0)			exit(2);	}		n = recvfrom(0, buf, sizeof(buf)-1, 0, &sa, &ss);	if (n < 1)		exit(1);	buf[n] = 0;	execl("/usr/bin/beep", "beep", buf);		return 0;}