xtreme v.2

Mavroyanopoulos Nikos nmav at hellug.gr
Thu Jun 17 21:30:58 EEST 1999


Mia ligo veltiomeni ekdosi. Auti menei panta anoikti sto 6699 ara arkei
na to trexete mia fora. An den sas endiaferei ti sas stelnei i xtreme
kante uncomment to NO_STDOUT kai NO_STDERR kai trexte to sto background
san "./a.out &". Ante kai oso kratisei:)

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>

#define LISTENQ 1024
#define SA struct sockaddr
#define SERV_PORT 6699
/* #define NO_STDOUT */
/* #define NO_STDERR */

int main()
{

	int listenfd, connfd;
	socklen_t len;
	unsigned char buff;
	struct sockaddr_in cliaddr, servaddr;
	char topbuff[512];

	if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket");
		return -1;
	}
	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(SERV_PORT);

	if (bind(listenfd, (SA *) & servaddr, sizeof(servaddr)) < 0) {
                fprintf(stderr, "Probably a TIME_WAIT state. Retry later.\n");
		perror("bind");
		return -1;
	}
	if (listen(listenfd, LISTENQ) < 0) {
		perror("listen");
		return -1;
	}
	len = sizeof(cliaddr);

	for (;;) {
		if ((connfd = accept(listenfd, (SA *) & cliaddr, &len)) < 0) {
			perror("accept");
			return -1;
		}
#ifndef NO_STDERR
		fprintf(stderr, "connection from %s, port %d\n",
			inet_ntop(AF_INET, &cliaddr.sin_addr, topbuff, sizeof(topbuff)),
			ntohs(cliaddr.sin_port));
#endif			

		for (;;) {
			if (read(connfd, &buff, 1) == 0)
				break;
#ifndef NO_STDOUT
			fwrite(&buff, 1, 1, stdout);
#endif			
		}

		close(connfd);
		fflush(stdout);
#ifndef NO_STDERR
		fprintf(stderr, "connection terminated\n");
		fflush(stderr);
#endif
	}
}

-- 
Nikos Mavroyanopoulos
mailto:nmav at hellug.gr
God heals and the doctor takes the fee.
--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at hellug.gr
Ta archives tis listas einai sto http://lists.hellug.gr/archives
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users at hellug.gr
====================================================================



More information about the Linux-greek-users mailing list