82 lines
1.7 KiB
C
82 lines
1.7 KiB
C
#ifndef FT_PING_H
|
|
# define FT_PING_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
#include <unistd.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/socket.h>
|
|
#include <netdb.h>
|
|
#include <byteswap.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#define PACKET_DATA_LENGTH 40
|
|
|
|
#define HELP_MESSAGE " [OPTION...] HOST ...\n\
|
|
Send ICMP ECHO_REQUEST packets to network hosts.\n\
|
|
\n\
|
|
-c, --count=NUMBER stop after sending NUMBER packets\n\
|
|
-n, --numeric do not resolve host addresses\n\
|
|
--ttl=N specify N as time-to-live\n\
|
|
-w, --timeout=N stop after N seconds\n\
|
|
\n\
|
|
-f, --flood flood ping (root only)\n\
|
|
-?, --help give this help list\n"
|
|
|
|
typedef struct s_waitlist
|
|
{
|
|
struct timeval time;
|
|
uint16_t seq;
|
|
struct s_waitlist *next;
|
|
} t_waitlist;
|
|
|
|
typedef struct s_host_list
|
|
{
|
|
char *host;
|
|
struct s_host_list *next;
|
|
} t_host_list;
|
|
|
|
typedef struct s_settings
|
|
{
|
|
t_host_list *hosts;
|
|
int count; // -c (--count)
|
|
int timeout; // -w (--timeout)
|
|
double interval; //-i (--interval)
|
|
int linger; //-W (--linger)
|
|
int ttl; // --ttl
|
|
short setTtl; // is ttl set
|
|
|
|
int socket;
|
|
uint16_t id;
|
|
short stop;
|
|
short err;
|
|
|
|
} t_settings;
|
|
|
|
|
|
typedef struct s_icmp_echo
|
|
{
|
|
uint8_t type;
|
|
uint8_t code;
|
|
uint16_t checksum;
|
|
uint16_t identifier;
|
|
uint16_t sequence;
|
|
struct timeval time;
|
|
uint8_t data[40];
|
|
} t_icmp_echo;
|
|
|
|
t_icmp_echo prepare_icmp_echo(uint16_t sequence, uint16_t identifier);
|
|
int add_host(t_settings *res, char *host);
|
|
void free_hosts(t_host_list *list);
|
|
t_settings parse_args(int argc, char **argv);
|
|
void show_help(t_settings *set, char *name);
|
|
void send_pings(t_settings *set);
|
|
|
|
#endif
|