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

📄 h_recv_clt.c

📁 T-kernel Tcp/ip Protocol Stack Sample
💻 C
字号:
/* *  Copyright (C) 1999-2006 MITSUBISHI ELECTRIC CORPORATION and *  RENESAS SOLUTIONS CORPORATION and *  RENESAS TECHNOLOGY CORPORATION *  All rights reserved. * *  TCP/IP Test Application program [API]. */#include <stdio.h>#include <signal.h>#include <ctype.h>#include <errno.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <netdb.h>#include "config.h"extern int errno;int sd;void sig_hdr(){	/* printf("received SIGINT.\n"); */	shutdown(sd, SHUT_RDWR);	if (close(sd) < 0) {		printf("close is NG.\n");		exit(1);	}	printf("close is OK.\n");	exit(0);}/* * TCP client program */main(argc, argv)int	argc;char **argv;{	int i, len;	struct sockaddr_in sindst;	int tcpopt;	char buf[2048];	signal(SIGINT, sig_hdr);printf("for TEST-7\n");	errno = 0;	/* create an endpoint for TCP communication */	if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {		printf("socket is NG.(errno=%d)\n", errno);		exit(1);	}	printf("socket is OK.\n");		memset((char *)&sindst, 0, sizeof(struct sockaddr_in));	sindst.sin_family = AF_INET;	sindst.sin_addr.s_addr = inet_addr(TGT_ADDR);	sindst.sin_port = htons(TGT_PORT);	/* initiate a connection on the socket */	if (connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) {		printf("connect is NG.(errno=%d)\n", errno);		close(sd);		exit(1);	}	printf("connect is OK.\n");		sleep(2);	for (i=0; i < 10; i++) {		len = send(sd, buf, sizeof(buf), 0);		if (len < 0)			break;		printf("send is OK.(size=%d)\n", len);	}	if (i != 10) {		printf("send is NG.(errno=%d)\n", errno);	}	errno = 0;	len = send(sd, buf, 0, 0);	if (len < 0)		printf("send is NG.(errno=%d)\n", errno);	else		printf("send is OK.(size=%d)\n", len);	if (shutdown(sd, SHUT_RDWR) < 0) {		printf("shutdown is NG.(errno=%d)\n", errno);	}	printf("shutdown is OK.\n");	if (close(sd) < 0) {		printf("close is NG.(errno=%d)\n", errno);	}	printf("close is OK.\n\n");	sleep(2);	exit(0);}/* EOF */

⌨️ 快捷键说明

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