code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
| #ifndef _PROTOCOL_H #define _PROTOCOL_H
#pragma once #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <netinet/ether.h> #include <net/if.h> #include <arpa/inet.h>
#include "pcap.h"
#define ETHERTYPE_IP 0x0800 #define ETHERTYPE_ARP 0x0806
struct nic_info { uint8_t my_mac[6]; struct in_addr addr; struct in_addr broadaddr; struct in_addr maskaddr; int ifindex; }; #ifndef __linux__ #pragma pack(push,1) #endif struct etherhdr { uint8_t ether_dhost[6]; uint8_t ether_shost[6]; uint16_t ether_type; } #ifndef __linux__ ; #pragma pack(pop) #else __attribute__((__packed__)); #endif
#ifndef __linux__ #pragma pack(push ,1) #endif struct arphdr { uint16_t ar_hrd; uint16_t ar_pro; uint8_t ar_hln; uint8_t ar_pln; uint16_t ar_op; uint8_t ar_sha[6]; uint32_t ar_sip; uint8_t ar_tha[6]; uint32_t ar_tip; } #ifndef __linux__ ; #pragma pack(pop) #else __attribute__((__packed__)); #endif
#ifndef __linux__ #pragma pack(push, 1); #endif struct iphdr { uint8_t ip_hl:4; uint8_t ip_v:4; uint8_t ip_tos; uint16_t ip_len; uint16_t ip_id; uint16_t ip_off; #define IP_RF 0x8000 #define IP_DF 0x4000 #define IP_MF 0x2000 #define IP_OFFMASK 0x1fff uint8_t ip_ttl; uint8_t ip_p; uint16_t ip_sum; struct in_addr ip_src, ip_dst; } #ifndef __linux ; #pragma pack(pop) #else __attribute__((__packed__)); #endif
#ifndef __linux__ #pragma pack(push, 1); #endif struct tcphdr { uint16_t th_sport; uint16_t th_dport; uint32_t th_seq; uint32_t th_ack; uint8_t th_x2:4; uint8_t th_off:4; uint8_t th_flags; #define TH_FIN 0x01 #define TH_SYN 0x02 #define TH_RST 0x04 #define TH_PUSH 0x08 #define TH_ACK 0x10 #define TH_URG 0x20 uint16_t th_win; uint16_t th_sum; uint16_t th_urp;
} #ifndef __linux ; #pragma pack(pop) #else __attribute__((__packed__)); #endif
#ifndef __linux__ #pragma pack(push, 1); #endif struct pseudohdr { struct in_addr ip_src, ip_dst; uint8_t reserved; uint8_t protocol_type; uint16_t tcp_total_length; } #ifndef __linux ; #pragma pack(pop) #else __attribute__((__packed__)); #endif
#ifndef __linux__ #pragma pack(push, 1); #endif struct icmphdr { uint8_t icmp_type; uint8_t icmp_code; uint16_t icmp_cksum; uint16_t icmp_id; uint16_t icmp_seq; } #ifndef __linux ; #pragma pack(pop) #else __attribute__((__packed__)); #endif
int get_info(struct nic_info *nic_info, char *if_name); int get_interface_devices(char *arg);
#endif
|
Author:
Slay
Permalink:
http://sean-baek.github.io/2022/08/21/2022-08-21-protocol-header/
License:
Copyright (c) 2021 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY?