DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T s

⟦2c0ae8a32⟧ TextFile

    Length: 940 (0x3ac)
    Types: TextFile
    Names: »serv.c«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec8/inet/serv.c« 

TextFile

#include <stdio.h>

#include <sys/types.h>
#include <netinet/in.h>

#include "service.h"

int comm_chan;
char in_buf[BUFSIZ];

main()
{
    if ( (comm_chan = setup_server( SERV_NAME, SERV_PORT )) < 0 ) {
	perror( "setup_server" );
	exit(1);
    }

    for ( ;; ) {
	struct sockaddr_in from;
	int fromlen = sizeof(from);
	int r;

	if ( (r = recvfrom( comm_chan, in_buf, sizeof(in_buf), 0,
			    (struct sockaddr *) &from, &fromlen )) < 0 ) {
	    perror( "receive" );
	    continue;
	}

	/* Data received, display it. */
	printf( "From " );
	print_bytes( (char *) &from, sizeof(from) );
	printf( ": %.*s\n", r, in_buf );
	fflush(stdout);

	/* Reply to the bugger. */
#define MSG "Hello."
	sendto(comm_chan,MSG,sizeof(MSG),0,(struct sockaddr *)&from,fromlen);
    }
}

print_bytes( p, n )
unsigned char *p;
int n;
{
    printf( "[" );
    for ( ; n; --n, ++p ) {
	printf( "%d", *p );
	if ( n != 1 ) printf( "," );
    }
    printf( "]" );
}