48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
#pragma once
|
|
|
|
#include "netinet/in.h"
|
|
#include <help.h>
|
|
#include <opt_parse.h>
|
|
|
|
#include <bits/types/struct_timeval.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
|
|
extern char *exec_name;
|
|
extern int tx_count;
|
|
extern int rx_count;
|
|
extern char *address;
|
|
extern double *times;
|
|
|
|
typedef struct {
|
|
bool verbose;
|
|
uint32_t count;
|
|
uint16_t size;
|
|
uint16_t timeout;
|
|
uint16_t linger;
|
|
uint16_t interval;
|
|
} options_t;
|
|
|
|
// TODO: implement the verbose mode !!!
|
|
#define DEFAULT_VERBOSE false
|
|
|
|
#define DEFAULT_SIZE 64
|
|
#define DEFAULT_INTERVAL 1
|
|
#define DEFAULT_TIMEOUT -1
|
|
#define DEFAULT_COUNT -1
|
|
#define DEFAULT_LINGER 10
|
|
|
|
int send_ping(int socket, struct sockaddr_in *dest, args_t *args);
|
|
int init_socket(args_t *args);
|
|
void init_packet(char *buf, int seq, uint32_t size);
|
|
int send_icmp(int socket, char *buf, struct sockaddr_in *addr, uint32_t size);
|
|
int receive_icmp(int socket, char *buf, uint32_t size,
|
|
struct sockaddr_in *addr);
|
|
void process_icmp(char *buf, int bytes, struct sockaddr_in *addr, int seq,
|
|
struct timeval *tv_start, struct timeval *tv_end);
|
|
|
|
// Internal
|
|
unsigned short get_checksum(unsigned short *addr, int count);
|