1
+
2
+ #define SIZE_OF_MAC 6
3
+ #define SIZE_OF_IP 4
4
+ #define ETHERNET_TYPE_ARP 0x0608
5
+ #define ETHERNET_TYPE_IP4 0x0008
6
+
7
+ struct EthernetHeader {
8
+ unsigned char to [SIZE_OF_MAC ];
9
+ unsigned char from [SIZE_OF_MAC ];
10
+ unsigned short type ;
11
+ } __attribute__ ((packed ));
12
+
13
+ struct ARPHeader {
14
+ struct EthernetHeader ethernetheader ;
15
+ unsigned short hardware_type ;
16
+ unsigned short protocol_type ;
17
+ unsigned char hardware_address_length ;
18
+ unsigned char protocol_address_length ;
19
+ unsigned short operation ;
20
+
21
+ unsigned char source_mac [SIZE_OF_MAC ];
22
+ unsigned char source_ip [SIZE_OF_IP ];
23
+
24
+ unsigned char dest_mac [SIZE_OF_MAC ];
25
+ unsigned char dest_ip [SIZE_OF_IP ];
26
+ } __attribute__ ((packed ));
27
+
28
+ struct IPv4Header {
29
+ struct EthernetHeader ethernetheader ;
30
+ unsigned char internet_header_length :4 ;
31
+ unsigned char version :4 ;
32
+ unsigned char type_of_service ;
33
+ unsigned short total_length ;
34
+ unsigned short id ;
35
+ unsigned short flags :3 ;
36
+ unsigned short fragment_offset :13 ;
37
+ unsigned char time_to_live ;
38
+ unsigned char protocol ;
39
+ unsigned short checksum ;
40
+ unsigned long source_addr ;
41
+ unsigned long dest_addr ;
42
+ } __attribute__ ((packed ));
43
+
44
+ struct UDPHeader {
45
+ struct IPv4Header ipv4header ;
46
+ unsigned short source_port ;
47
+ unsigned short destination_port ;
48
+ unsigned short length ;
49
+ unsigned short checksum ;
50
+ } __attribute__ ((packed ));
51
+
52
+ struct DHCPDISCOVERHeader {
53
+ struct UDPHeader udpheader ;
54
+ unsigned char op ;
55
+ unsigned char htype ;
56
+ unsigned char hlen ;
57
+ unsigned char hops ;
58
+ unsigned long xid ;
59
+ unsigned short timing ;
60
+ unsigned short flags ;
61
+ unsigned long address_of_machine ;
62
+ unsigned long dhcp_offered_machine ;
63
+ unsigned long ip_addr_of_dhcp_server ;
64
+ unsigned long ip_addr_of_relay ;
65
+ unsigned char client_mac_addr [16 ];
66
+ unsigned char sname [64 ];
67
+ unsigned char file [128 ];
68
+ unsigned long magic_cookie ;
69
+ unsigned char options [76 ];
70
+ } __attribute__ ((packed ));
71
+
72
+ struct DHCPREQUESTHeader {
73
+ struct UDPHeader udpheader ;
74
+ unsigned char op ;
75
+ unsigned char htype ;
76
+ unsigned char hlen ;
77
+ unsigned char hops ;
78
+ unsigned long xid ;
79
+ unsigned short timing ;
80
+ unsigned short flags ;
81
+ unsigned long address_of_machine ;
82
+ unsigned long dhcp_offered_machine ;
83
+ unsigned long ip_addr_of_dhcp_server ;
84
+ unsigned long ip_addr_of_relay ;
85
+ unsigned char client_mac_addr [16 ];
86
+ unsigned char sname [64 ];
87
+ unsigned char file [128 ];
88
+ unsigned long magic_cookie ;
89
+ unsigned char options [25 ];
90
+ } __attribute__ ((packed ));
91
+
92
+ struct DNSREQUESTHeader {
93
+ struct UDPHeader udpheader ;
94
+ unsigned short transaction_id ;
95
+ unsigned short flags ;
96
+ unsigned short question_count ;
97
+ unsigned short answer_rr ;
98
+ unsigned short authority_rr ;
99
+ unsigned short aditional_rr ;
100
+ } __attribute__ ((packed ));
101
+
102
+
103
+ void * getnetworkpackage ();
104
+ void sendnetworkpackage (int type ,int size ,unsigned char * to ,int where ,int port );
105
+ char initialisenetworkpackage (int type ,int is_ip ,unsigned char * to , int function , int port );
0 commit comments