Author:
9CBS VC / MFC Network Programming PiggyXP ^ _ ^
table of Contents:
One. Basic knowledge about ARP protocol
3. Fill of the ARP package
two. Programming implementation of sending packets
Plip the packet
.................................................................... .......
3. The fill of thearp package
1) Request package fill:
For example, our computer MAC address is AA-AA-AA-AA-AA-AA, IP is 192.168.0.1
We want to query 192.168.0.99 MAC address, what should I do?
First fill the DLC header, learn from the previous learning, we want to know that a computer corresponding to the MAC address is to send broadcasts to the whole network, so the receiver MAC is definitely fffffffffffffff, the sender Mac is of course himself, so our DLC header is filling, as shown in the figure, bold is the value we want to manually entered (of course, the program I compare the program, will automatically fill in some fields according to the ARP package type you choose, you know ^ _ ^).
DLC Header
Field
BYTE
Fill
Receiver Mac
6
ffffffffffffff
Sender Mac
6
Aaaaaaaaaaaaaaaaaa
EtherType
2
0x0806
Figure 3 ARP request package DLC Header content
Next is an ARP frame, the request package is of course 1, the sender's Mac and IP will of course fill in our own, then pay attention to, the receiver IP here is fill in the IP address we have to query, that is, 192.168 .0.99, and the receiver Mac fills in any value, it does not work, so, as shown in the figure,
ARP FRAME
Field
BYTE
Fill
Hardware type
2
1
Upper layer protocol type
2
0800
MAC address length
1
6
IP address length
1
4
Operate code
2
1
Sender Mac
6
Aaaaaaaaaaaaaaaaaa
Sender IP
4
192.168.0.1
Receiver Mac
6
Arbitrary value xxxxxxxxxxx
Receiver IP
4
192.168.0.99
Data input
18
0
Figure 4 Content of ARP frame in ARP request package
If we construct a such a package, if there is 192.168.0.99 and is active, we will immediately receive a 192.168.0.0.0.0.0.99 a response package, we can check our ARP cache list, isn't it A strip similar to this
Type:
192.168.0.99 BB-BB-BB-BB-BB-BB
Is it very magical?
Let's take another configuration of the ARP response package.
2) Responding to the packing of the package
With the detailed explanation of the previous, you will definitely say that the fill method of the bag is coming, so I will not say it, and the column is fine.
For example, send an ARP response package 192.168.0.99 (Mac to BB-BB-BB-BB-BB), telling it that our MAC address is AA-AA-AA-AA-AA-AA, which is like this to fill Various fields
DLC Header
Field
BYTE
Fill
Receiver Mac
6
Bbbbbbbbbbbbb
Sender Mac
6
Aaaaaaaaaaaaaaaaaa
EtherType
2
0x0806
Figure 5 ARP response package DLC Header content
ARP FRAME
Field
BYTE
Fill
Hardware type
2
1
Upper layer protocol type
2
0800
MAC address length
1
6
IP address length
1
4
Operate code
2
2
Sender Mac
6
Aaaaaaaaaaaaaaaaaa
Sender IP
4
192.168.0.1
Receiver Mac
6
Bbbbbbbbbbbbb
Receiver IP
4
192.168.0.99
Data input
18
0
Figure 6 Content of ARP frame in ARP response package
This will have more address mappings about our 192.168.0.1 in the ARP cache of 192.168.0.99.
Ok, finally arrived, it's time to implement it, ^ _ ^
two. Programming implementation of sending ARP packets
Plip the packet
The above top of the table about the ARP package, corresponding to the structure in the program, corresponding to the above table, then we need three structures below
// DLC Header
Typedef struct tagdlcheader
{
UNSIGNED Char Desmac [6]; / * Destination HW Addrress * /
Unsigned char srcmac [6]; / * Source HW Addresss * /
Unsigned short ethertype; / * Ethernet type * /
} DLCHEADER, * PDLCHEADER;
// ARP FRAME
Typedef struct tagarpframe
{
UNSIGNED Short HW_TYPE; / * HARDWARE Address * /
Unsigned short prot_type; / * protocol address * /
Unsigned char HW_ADDR_LEN; / * Length of Hardware Address * /
Unsigned char prot_addr_len; / * Length of protocol address * /
Unsigned short opcode; / * arp / rarp * /
Unsigned char send_hw_addr [6]; / * sender hardware address * /
Unsigned long send_prot_addr; / * sender protocol address * /
Unsigned char targ_hw_addr [6]; / * Target Hardware Address * /
Unsigned long targ_prot_addr; / * target protocol address * /
UNSIGNED Char Padding [18];
Arpframe, * ParpFrame
// arp packet = DLC Header ARP FRAME
Typedef struct tagarppacket
{
DlcHeader DlcHeader;
Arpframe arpframe;
Arppacket, * Parppacket;
These structures must be read, it is the top seat in the program.
.................
============================================================================================================================================================================================================= ================ Not so fast, the article does not know to be dismantled ..-_- b
Please look forward to following:)
----- Finished AT 2004-05-29 19:41
------ Made in dLUT | DIP