⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpdaytime.c

📁 comer s TCPIP-vol3源代码...当然是经典咯
💻 C
字号:
/* TCPdaytime.c - TCPdaytime, main */#include <unistd.h>#include <stdlib.h>#include <string.h>#include <stdio.h>extern int	errno;int	TCPdaytime(const char *host, const char *service);int	errexit(const char *format, ...);int	connectTCP(const char *host, const char *service);#define	LINELEN		128/*------------------------------------------------------------------------ * main - TCP client for DAYTIME service *------------------------------------------------------------------------ */intmain(int argc, char *argv[]){	char	*host = "localhost";	/* host to use if none supplied	*/	char	*service = "daytime";	/* default service port		*/	switch (argc) {	case 1:		host = "localhost";		break;	case 3:		service = argv[2];		/* FALL THROUGH */	case 2:		host = argv[1];		break;	default:		fprintf(stderr, "usage: TCPdaytime [host [port]]\n");		exit(1);	}	TCPdaytime(host, service);	exit(0);}/*------------------------------------------------------------------------ * TCPdaytime - invoke Daytime on specified host and print results *------------------------------------------------------------------------ */TCPdaytime(const char *host, const char *service){	char	buf[LINELEN+1];		/* buffer for one line of text	*/	int	s, n;			/* socket, read count		*/	s = connectTCP(host, service);	while( (n = read(s, buf, LINELEN)) > 0) {		buf[n] = '\0';		/* ensure null-terminated	*/		(void) fputs( buf, stdout );	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -