defs.h

来自「unix下模仿ping功能」· C头文件 代码 · 共 56 行

H
56
字号
#include <stdio.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <signal.h>
#include <sys/time.h>
#include<pthread.h>
//#include<semaphore.h>

extern int errno;

#define MAXWAIT         10       /* max time to wait for response, sec. */
#define MAXPACKET       4096     /* max packet size */
#define MAXHOSTNAMELEN_1  64       /* max length of hostname */
#define SIZE_ICMP_HDR   8        /* 8-byte ICMP header */
#define SIZE_TIME_DATA  8        /* timeval struct (ICMP “data”) */ 
#define DEF_DATALEN     56       /* length of data */

int  packsize;                   /* size of ICMP packet to send */
int  datalen;                    /* size of data after the ICMP header, may be 0 */
int  verbose;                    /* 罗嗦的 */
u_char  sendpack[MAXPACKET];     /* packet we send */
u_char  recvpack[MAXPACKET];     /* received packet */
struct sockaddr_in  dest;        /* who to ping */
int    sockfd;                   /* socket descriptor */
char   *hostname;
int    npackets;        /* max # of packets to send; 0 if no limit */
int    ident;           /* process ID, to identify ICMP packets */
int    ntransmitted;    /* sequence # for outbound packets */
int    nreceived;       /* # of packets we got back */
int    timing;          /* true if time-stamp in each packet */
int    tmin;            /* min round-trip time */
int    tmax;            /* max of round-trip time */
long   tsum;            /* sum of all round-trip times, for average */
int    xiTimeOut;

void sig_alarm();
void send_ping();
void recv_ping();
void pr_pack(char *buf, int cc, struct sockaddr_in *from);
void tvsub(register struct timeval *out, register struct timeval *in);
void sig_finish();
void exit_ping();
u_short in_cksum(register u_short *ptr, register int nbytes);




⌨️ 快捷键说明

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