udp測試程式 + makefile
udp測試程式 + makefile
[@more@]C語言:
01 /*
02 ** talker.c -- a datagram "client" demo
03 */
04
05 #include
06 #include
07 #include
08 #include
09 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15
16 #define SERVERPORT "4950" // the port users will be connecting to
17
18 int main(int argc, char *argv[])
19 {
20 int sockfd;
21 struct addrinfo hints, *servinfo, *p;
22 int rv;
23 int numbytes;
24
25 if (argc != 3) {
26 fprintf(stderr,"usage: talker hostname messagen");
27 exit(1);
28 }
29
30 memset(&hints, 0, sizeof hints);
31 hints.ai_family = AF_UNSPEC;
32 hints.ai_socktype = SOCK_DGRAM;
33
34 if ((rv = getaddrinfo(argv[1], SERVERPORT, &hints, &servinfo)) != 0) {
35 fprintf(stderr, "getaddrinfo: %sn", gai_strerror(rv));
36 return 1;
37 }
38
39 // loop through all the results and make a socket
40 for(p = servinfo; p != NULL; p = p->ai_next) {
41 if ((sockfd = socket(p->ai_family, p->ai_socktype,
42 p->ai_protocol)) == -1) {
43 perror("talker: socket");
44 continue;
45 }
46
47 break;
48 }
49
50 if (p == NULL) {
51 fprintf(stderr, "talker: failed to bind socketn");
52 return 2;
53 }
54
55 if ((numbytes = sendto(sockfd, argv[2], strlen(argv[2]), 0,
56 p->ai_addr, p->ai_addrlen)) == -1) {
57 perror("talker: sendto");
58 exit(1);
59 }
60
61 freeaddrinfo(servinfo);
62
63 printf("talker: sent %d bytes to %sn", numbytes, argv[1]);
64 close(sockfd);
65
66 return 0;
67 }
02 ** talker.c -- a datagram "client" demo
03 */
04
05 #include
06 #include
07 #include
08 #include
09 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15
16 #define SERVERPORT "4950" // the port users will be connecting to
17
18 int main(int argc, char *argv[])
19 {
20 int sockfd;
21 struct addrinfo hints, *servinfo, *p;
22 int rv;
23 int numbytes;
24
25 if (argc != 3) {
26 fprintf(stderr,"usage: talker hostname messagen");
27 exit(1);
28 }
29
30 memset(&hints, 0, sizeof hints);
31 hints.ai_family = AF_UNSPEC;
32 hints.ai_socktype = SOCK_DGRAM;
33
34 if ((rv = getaddrinfo(argv[1], SERVERPORT, &hints, &servinfo)) != 0) {
35 fprintf(stderr, "getaddrinfo: %sn", gai_strerror(rv));
36 return 1;
37 }
38
39 // loop through all the results and make a socket
40 for(p = servinfo; p != NULL; p = p->ai_next) {
41 if ((sockfd = socket(p->ai_family, p->ai_socktype,
42 p->ai_protocol)) == -1) {
43 perror("talker: socket");
44 continue;
45 }
46
47 break;
48 }
49
50 if (p == NULL) {
51 fprintf(stderr, "talker: failed to bind socketn");
52 return 2;
53 }
54
55 if ((numbytes = sendto(sockfd, argv[2], strlen(argv[2]), 0,
56 p->ai_addr, p->ai_addrlen)) == -1) {
57 perror("talker: sendto");
58 exit(1);
59 }
60
61 freeaddrinfo(servinfo);
62
63 printf("talker: sent %d bytes to %sn", numbytes, argv[1]);
64 close(sockfd);
65
66 return 0;
67 }
Makefile語言:
# $Id: Makefile,v 1.5 2005/09/20 10:56:17 beah Exp $
#CROSS = ppc_440ep-
#CROSS = arm-soft_uclibc-linux-gnu-
CROSS = arm-hismall-linux-
#CROSS =
CC = $(CROSS)gcc
STRIP = $(CROSS)strip
BINDIR = /usr/local/sbin
MANDIR = /usr/local/man
CFLAGS+= -g -Wall
# CFLAGS+= -DHAS_FGETLN -DHAS_STRLCPY
# CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
# CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
LDFLAGS+= -lpthread
all: talker
$(STRIP) talker
cp talker /tftpboot/
cp talker /target/
talker: talker.o
$(CC) $(LDFLAGS) talker.o $(LDLIBS) -o talker
talker.o: talker.c
$(CC) $(CFLAGS) -c talker.c
install: all
install -o root -g bin -m 0555 talker $(BINDIR)
# install -o root -g wheel -m 0755 -d $(MANDIR)/man8
# install -o root -g bin -m 0444 talker.8 $(MANDIR)/man8
clean:
rm -f talker *.o
#CROSS = ppc_440ep-
#CROSS = arm-soft_uclibc-linux-gnu-
CROSS = arm-hismall-linux-
#CROSS =
CC = $(CROSS)gcc
STRIP = $(CROSS)strip
BINDIR = /usr/local/sbin
MANDIR = /usr/local/man
CFLAGS+= -g -Wall
# CFLAGS+= -DHAS_FGETLN -DHAS_STRLCPY
# CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
# CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare
LDFLAGS+= -lpthread
all: talker
$(STRIP) talker
cp talker /tftpboot/
cp talker /target/
talker: talker.o
$(CC) $(LDFLAGS) talker.o $(LDLIBS) -o talker
talker.o: talker.c
$(CC) $(CFLAGS) -c talker.c
install: all
install -o root -g bin -m 0555 talker $(BINDIR)
# install -o root -g wheel -m 0755 -d $(MANDIR)/man8
# install -o root -g bin -m 0444 talker.8 $(MANDIR)/man8
clean:
rm -f talker *.o
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23168012/viewspace-1048951/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- UDP網路測試UDP
- http tcp udp json 接收測試HTTPTCPUDPJSON
- 如何在 Eolink Apikit 中發起 TCP/UDP 文件測試APITCPUDP
- cmake Makefile面試問題面試
- 【測試】echo傳送和接收TCP/UDP資料包|shell 傳送TCP/UDP資料包TCPUDP
- 測試程式
- 16.Linuxshell程式設計(Makefile)Linux程式設計
- MYSQL程式碼顯示測試測試MySql
- UDP報文觀測作業UDP
- 測試程式碼
- linux下使用makefile方式程式設計主程式Linux程式設計
- 基於UDP程式設計UDP程式設計
- 網路程式設計-UDP程式設計UDP
- 小程式自動化測試--測試3
- Makefile
- falseShare的測試程式False
- 測試程式碼高亮
- 【網路程式設計】Tcp/Udp程式設計TCPUDP
- UDP介紹及UDP傳送端和接收端廣播程式碼UDP
- 白盒測試程式碼應該怎麼測試
- Android應用程式測試-Alltesting|澤眾雲測試Android
- 測試測試測試測試測試測試
- 程式碼寫作測試
- Python網路程式設計——IP、UDPPython程式設計UDP
- Java網路程式設計之UDPJava程式設計UDP
- 【Makefile】5-Makefile變數的基礎變數
- 在ubuntu系統下用Makefile方式程式設計主程式Ubuntu程式設計
- 程式碼重構與單元測試——測試專案(二)
- 如何編寫優秀的測試程式碼|單元測試
- 如何測試微信小程式微信小程式
- 程式碼測試用例指南
- 程式測試第一法則?
- 網路程式設計中TCP與UDP程式設計TCPUDP
- 網路程式設計UDP協議方式程式設計UDP協議
- 【網路程式設計】TCPIP-5-UDP程式設計TCPUDP
- python UDP程式設計是什麼意思?PythonUDP程式設計
- UdpUDP
- makefile之overrideIDE
- makefile規則