47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
#ifndef ICMP_H
|
|
#define ICMP_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <netinet/in.h>
|
|
#include <time.h>
|
|
|
|
/* Opaque handle type */
|
|
typedef struct icmp_handle icmp_handle_t;
|
|
|
|
/* Reply structure passed to callback */
|
|
typedef struct icmp_reply {
|
|
uint8_t type;
|
|
uint8_t code;
|
|
struct in_addr from;
|
|
uint8_t ttl;
|
|
struct timespec timestamp;
|
|
void *payload;
|
|
size_t payload_len;
|
|
void *ip_payload;
|
|
size_t ip_payload_len;
|
|
} icmp_reply_t;
|
|
|
|
/* Callback type for received packets */
|
|
typedef void (*icmp_callback_t)(const icmp_reply_t *reply, void *userdata);
|
|
|
|
/* Handle lifecycle */
|
|
icmp_handle_t *icmp_create(void);
|
|
void icmp_destroy(icmp_handle_t *h);
|
|
int icmp_get_fd(const icmp_handle_t *h);
|
|
|
|
/* Send functions */
|
|
int icmp_send_raw(icmp_handle_t *h, uint8_t type, uint8_t code,
|
|
const void *payload, size_t len, struct in_addr dest,
|
|
uint8_t ttl);
|
|
|
|
int icmp_send_echo(icmp_handle_t *h, struct in_addr dest, uint16_t id,
|
|
uint16_t seq, uint8_t ttl);
|
|
|
|
/* Receive function */
|
|
int icmp_process(icmp_handle_t *h, icmp_callback_t cb, void *userdata);
|
|
|
|
/* Error handling */
|
|
const char *icmp_strerror(const icmp_handle_t *h);
|
|
|
|
#endif /* ICMP_H */
|