summaryrefslogtreecommitdiff
path: root/libping.h
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2016-07-06 19:16:33 +0100
committerFreeArtMan <dos21h@gmail.com>2016-07-06 19:16:33 +0100
commitfbdcb64a4b25f24244afc0d7967e93bb40678365 (patch)
tree89be49c72c5502e7faabe3a0a1f90ea343735410 /libping.h
downloadlibping-master.tar.gz
libping-master.zip
libping initial commitHEADmaster
Diffstat (limited to 'libping.h')
-rw-r--r--libping.h76
1 files changed, 76 insertions, 0 deletions
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 <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <linux/if_packet.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+
+#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);