From fbdcb64a4b25f24244afc0d7967e93bb40678365 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Wed, 6 Jul 2016 19:16:33 +0100 Subject: libping initial commit --- libping.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 libping.h (limited to 'libping.h') diff --git a/libping.h b/libping.h new file mode 100644 index 0000000..071915a --- /dev/null +++ b/libping.h @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define ICMP_TREQUEST 8 +#define ICMP_TECHO 0 + +#define ICMP_DEFAULT_SIZE 0 +//#define ICMP_MAX + +typedef struct icmp_pckt_t +{ + //etherenet header - 14 bytes + uint8_t eth_dest[6]; + uint8_t eth_src[6]; + uint16_t eth_type; + + //IP4 header - 20 bytes + uint8_t head_hlength; //4bits version, 4bit header length + uint8_t tos; + uint16_t ip_length; + + uint16_t ip_ident; + uint16_t flags_fragment_off; + + uint8_t ttl; //time to live + uint8_t protocol; + uint16_t ip_chksum; + + uint32_t source_addr; + uint32_t dest_addr; + + //ICMP header 12 bytes + uint8_t type; + uint8_t code; + uint16_t icmp_check_sum; + uint16_t icmp_ident; + uint16_t seq_num; + uint8_t data[ICMP_MAX_DATA]; +} __attribute__((packed, aligned(1))) icmp_pckt_t; + +int icmp_eth_init( icmp_pckt_t *icmp ); +int icmp_eth_dest( icmp_pckt_t *icmp, uint8_t *mac ); +int icmp_eth_src( icmp_pckt_t *icmp, uint8_t *mac ); +int icmp_eth_len( icmp_pckt_t *icmp ); +int icmp_ip_init( icmp_pckt_t *icmp ); +int icmp_ip_chksum( icmp_pckt_t *icmp ); +int icmp_ip_dest( icmp_pckt_t *icmp, uint32_t dest ); +int icmp_ip_src( icmp_pckt_t *icmp, uint32_t src ); +int icmp_ip_ident( icmp_pckt_t *icmp, uint16_t ident ); +int icmp_ip_ttl( icmp_pckt_t *icmp, uint8_t ttl ); +int icmp_ip_len( icmp_pckt_t *icmp ); +int icmp_icmp_init( icmp_pckt_t *icmp ); +int icmp_icmp_set_chks( icmp_pckt_t *icmp ); +int icmp_icmp_set_code( icmp_pckt_t *icmp, uint8_t code ); +int icmp_icmp_set_type( icmp_pckt_t *icmp, uint8_t type ); +int icmp_icmp_len( icmp_pckt_t *icmp ); +int icmp_icmp_ident( icmp_pckt_t *icmp, uint16_t ident ); +int icmp_icmp_seq( icmp_pckt_t *icmp, uint16_t seq); +int icmp_total_len( icmp_pckt_t *icmp ); +int icmp_icmp_ts( icmp_pckt_t *icmp, uint64_t timestamp ); +int icmp_dump( icmp_pckt_t *icmp ); +int icmp_data( icmp_pckt_t *icmp, uint8_t *data, size_t size ); + +uint16_t +ip_checksum (uint16_t *addr, int len); -- cgit v1.2.3