📄 h_recvfrom_clt.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"); */ if (close(sd) < 0) { printf("close is NG.\n"); exit(1); } printf("close is OK.\n"); exit(0);}/* * UDP 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-6\n"); errno = 0; /* create an endpoint for UDP communication */ if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("socket is NG.(errno=%d)\n", errno); exit(1); } printf("socket is OK.\n"); sleep(2); 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); for (i=0; i < 10; i++) { len = sendto(sd, buf, sizeof(buf), 0, (struct sockaddr *)&sindst, sizeof(sindst)); if (len < 0) break; printf("sendto is OK.(size=%d)\n", len);#if 0 /* 28.Feb.2006 */ // sleep(1);#endif } if (i != 10) { printf("sendto is NG.(errno=%d)\n", errno); } errno = 0; len = sendto(sd, buf, 0, 0, (struct sockaddr *)&sindst, sizeof(sindst)); if (len < 0) printf("sendto is NG.(errno=%d)\n", errno); else printf("sendto is OK.(size=%d)\n", len); 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 + -