Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Send a packet

Shulou Source: shulou.com Published: 2022-06-01 06:28:32 09月17日 Update

# include "stdafx.h"

# include

# include

# include

Void main (int argc, char * * argv)

{

Pcap_t * fp

Char errbuf[PCAP _ ERRBUF_SIZE]

U_char packet [100]

Int i

Pcap_if_t * alldevs

Pcap_if_t * d

Int inum

Int jung0

/ * get the list of devices * /

If (pcap_findalldevs_ex (PCAP_SRC_IF_STRING, NULL, & alldevs, errbuf) =-1)

{

Fprintf (stderr, "Error in pcap_findalldevs:% s\ n", errbuf)

Exit (1)

}

/ * print list * /

For (dudes alldevs; d; dudes-> next)

{

Printf ("d. S", + + j, d-> name)

If (d-> description)

Printf ("(% s)\ n", d-> description)

Else

Printf ("(No description available)\ n")

}

If (jacks 0)

{

Printf ("\ nNo interfaces found! Make sure WinPcap is installed.\ n")

Return

}

Printf ("Enter the interface number (1M% d):", j)

Scanf ("d", & inum)

If (inum

< 1 || inum >

j)

{

Printf ("\ nInterface number out of range.\ n")

/ * release device list * /

Pcap_freealldevs (alldevs)

Return

}

/ * Jump to selected device * /

For (d=alldevs, juni0; j

< inum-1 ;d=d->

Next, jacks +)

/ * Open the output device * /

If ((fp= pcap_open (d-> name, / / device name)

100, / / part to be captured (only the first 100 bytes are captured)

PCAP_OPENFLAG_PROMISCUOUS, / / hybrid mode

1000, / / read timeout

NULL, / / remote machine verification

Errbuf / / error buffering

)) = = NULL)

{

Fprintf (stderr, "\ nUnable to open the adapter.% s is not supported by WinPcap\ n", argv [1])

Return

}

Pcap_freealldevs (alldevs)

/ * suppose that on Ethernet, the destination address of MAC is set to 1: 1 * /

Packet [0] = 255

Packet [1] = 255

Packet [2] = 255

Packet [3] = 255

Packet [4] = 255

Packet [5] = 255

/ * set the MAC source address to 2 * /

Packet [6] = 10

Packet [7] = 10

Packet [8] = 10

Packet [9] = 10

Packet [10] = 10

Packet [11] = 10

Packet [12] = 96

Packet [13] = 00

/ * fill in the rest * /

For (iTunes 14)

Tags: Device address data content byte time machine mode purpose part error jackers Ethernet hybrid buffer output authentication Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info OPPO Reno NVidia Xiaomi