设为首页 - 加入收藏  
您的当前位置:首页 >域名 >窥探 Socket 监听的秘密 正文

窥探 Socket 监听的秘密

来源:亿华互联编辑:域名时间:2025-11-05 13:03:22
窥探 Socket 监听的秘密
复制[mapan@localhost test]$ ls  client.cpp  makefile  server.cpp  [mapan@localhost test]$   [mapan@localhost test]$ cat server.cpp   #include <unistd.h>  #include <sys/types.h>  #include <sys/socket.h>  #include <netdb.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h>  #include <ctype.h>  #include <errno.h>  #include <malloc.h>  #include <netinet/in.h>  #include <arpa/inet.h>  #include <sys/ioctl.h>  #include <stdarg.h>  #include <fcntl.h>  #include <sys/types.h>  #include <sys/wait.h>  #include <netinet/in.h>  #include <arpa/inet.h>  #include <signal.h>  #define MAXLINE 4096  void main()  {     int listenfd,窥探connfd;     socklen_t  clilen;     struct sockaddr_in cliaddr,servaddr;     listenfd=socket(AF_INET,SOCK_STREAM,0);     bzero(&servaddr,sizeof(servaddr));     servaddr.sin_family=AF_INET;     servaddr.sin_addr.s_addr=INADDR_ANY;     servaddr.sin_port=htons(8888);     bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr));       listen(listenfd,1);     getchar();     connfd=accept(listenfd,(struct sockaddr *)&cliaddr,&clilen);     close(connfd);     close(listenfd); }  [mapan@localhost test]$ cat client.cpp   #include <unistd.h>  #include <sys/types.h>  #include <sys/socket.h>  #include <netdb.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h>  #include <ctype.h>  #include <errno.h>  #include <malloc.h>  #include <netinet/in.h>  #include <arpa/inet.h>  #include <sys/ioctl.h>  #include <stdarg.h>  #include <fcntl.h>  #include <sys/types.h>  #include <sys/wait.h>  #include <netinet/in.h>  #include <arpa/inet.h>  #include <signal.h>  #define MAXLINE 4096  void main()  {     int sockfd;     struct sockaddr_in servaddr;     sockfd=socket(AF_INET,SOCK_STREAM,0);     bzero(&servaddr,sizeof(servaddr));     servaddr.sin_family=AF_INET;     servaddr.sin_port=htons(8888);     servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");     int ret=connect(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));     getchar();     close(sockfd); }  [mapan@localhost test]$ cat makefile   all:server client  server.o:server.cpp    g++ -c server.cpp  client.o:client.cpp    g++ -c client.cpp  server:server.o    g++ -o server server.o  client:client.o    g++ -o client client.o  clean:    rm -f server client *.o  [mapan@localhost test]$  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.
最新文章

2.4872s , 17416.765625 kb

Copyright © 2025 Powered by 窥探 Socket 监听的秘密,亿华互联  滇ICP备2023000592号-16

sitemap

Top