![]() * Send down the packet */ if ( pcap_sendpacket(fp, packet, 100 /* size */) != 0)įprintf(stderr, "\nError sending the packet: \n", pcap_geterr(fp)) * Fill the rest of the packet */ for(i=12 i<100 i ) * Supposing to be on ethernet, set mac destination to 1:1:1:1:1:1 */ %s is not supported by WinPcap\n", argv) ![]() NULL, // authentication on the remote machineįprintf(stderr, "\nUnable to open the adapter. * Open the output device */ if ( (fp= pcap_open(argv, // name of the deviceġ00, // portion of the packet to capture (only the first 100 bytes) PCAP_OPENFLAG_PROMISCUOUS, // promiscuous mode * Check the validity of the command line */ if (argc != 2) #include #include #include void main( int argc, char **argv) This means that the application has to create the correct protocol headers in order to send something meaningful. Notice that the buffer is sent to the net as is, without any manipulation. pcap_sendpacket() takes as arguments a buffer containing the data to send, the length of the buffer and the adapter that will send it. After opening an adapter, pcap_sendpacket() is called to send a hand-crafted packet. The simplest way to send a packet is shown in the following code snippet. ![]() Sending a single packet with pcap_sendpacket() Note that the original libpcap library at the moment doesn't provide any way to send packets, therefore all the functions shown here are WinPcap extensions and will not work under Unix. Among them, the user can find a complete set of functions to send packets. Although the name WinPcap indicates clearly that the purpose of the library is packet capture, other useful features for raw networking are provided. ![]()
0 Comments
Leave a Reply. |