📄 ping.h
字号:
#include <sys/socket.h>#include <netdb.h>#include <signal.h>#include <unistd.h>#include <netinet/udp.h>#include <netinet/in_systm.h>#include <netinet/ip.h>#include <netinet/ip_icmp.h>#include <arpa/inet.h>#include <stdlib.h>#include <string.h>#include <sys/time.h>#include <errno.h>#include <sys/param.h>#include <stdio.h>#ifndef __Ping_H#define __Ping_Hclass Ping{ private: char recvbuf[1500]; char sendbuf[1500]; int dataLength; char *host; // int counter; int sockfd; pid_t pid; struct sockaddr_in destSockaddr; struct sockaddr_in fromSockaddr; //------------------------------------------------------------------- struct in_addr echo_ip; char *echolp; //-------------------------------------------------- int seconds; struct timeval selectTimeout; struct timeval timeout; struct timeval requestTime; double rtt; public:/* const static int REPLY_WAITING=0; const static int REPLY_OK=1; const static int REPLY_ERROR=-1; const static int REPLY_TIMEOUT=-2;*/ static const int REPLY_WAITING=0; static const int REPLY_OK=1; static const int REPLY_ERROR=-1; static const int REPLY_TIMEOUT=-2; Ping(); Ping(int dataLength); void setDataLength(int length); int setHost(char* host); void start(char* host); int getReply(); int getReplyTime(); void request(); unsigned short in_cksum(unsigned short *addr,int len); void tv_sub(struct timeval *out,struct timeval *in); int proc(char* ptr,ssize_t len,struct timeval *tvrecv); int waitReady(); void setTimeout(int sec,int usec); char * getIp(); int counter; int counter1; int geticmp_seq(); int tt;};/*struct addrinfo* host_serv(char *host,const char *serv,int family,int socktype){ int n; struct addrinfo hints, *res; bzero(&hints,sizeof(struct addrinfo)); hints.ai_flags=AI_CANONNAME; hints.ai_family=family; hints.ai_socktype=socktype; if ((n=getaddrinfo(host,serv,&hints,&res))!=0) return NULL; return res;}*///Ping* ping;//int scountor=0;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -