Graphics Programs Reference
In-Depth Information
(eth->ether_type == ETHERTYPE_ARP ? "ARP" : "RARP"),
nemesis_lookup_linktype(l2->linktype));
}
}
}
libnet_destroy_packet(&pkt);
if (l2 != NULL)
libnet_close_link_interface(l2);
return (n);
}
At a high level, this function should be readable to you. Using libnet
functions, it opens a link interface and initializes memory for a packet. Then,
it builds the Ethernet layer using elements from the Ethernet header data
structure and then does the same for the ARP layer. Next, it writes the packet
to the device to inject it, and finally cleans up by destroying the packet and
closing the interface. The documentation for these functions from the libnet
man page is shown below for clarity.
From the libnet Man Page
libnet_open_link_interface() opens a low-level packet interface. This is
required to write link layer frames. Supplied is a u_char pointer to the
interface device name and a u_char pointer to an error buffer. Returned is a
filled in libnet_link_int struct or NULL on error.
libnet_init_packet() initializes a packet for use. If the size parameter is
omitted (or negative) the library will pick a reasonable value for the user
(currently LIBNET_MAX_PACKET). If the memory allocation is successful, the
memory is zeroed and the function returns 1. If there is an error, the
function returns -1. Since this function calls malloc, you certainly should,
at some point, make a corresponding call to destroy_packet().
libnet_build_ethernet() constructs an ethernet packet. Supplied is the
destination address, source address (as arrays of unsigned characterbytes)
and the ethernet frame type, a pointer to an optional data payload, the
payload length, and a pointer to a pre-allocated block of memory for the
packet. The ethernet packet type should be one of the following:
Value Type
ETHERTYPE_PUP PUP protocol
ETHERTYPE_IP IP protocol
ETHERTYPE_ARP ARP protocol
ETHERTYPE_REVARP Reverse ARP protocol
ETHERTYPE_VLAN IEEE VLAN tagging
ETHERTYPE_LOOPBACK Used to test interfaces
libnet_build_arp() constructs an ARP (Address Resolution Protocol) packet.
Supplied are the following: hardware address type, protocol address type, the
hardware address length, the protocol address length, the ARP packet type, the
sender hardware address, the sender protocol address, the target hardware
address, the target protocol address, the packet payload, the payload size,
and finally, a pointer to the packet header memory. Note that this function
Search WWH ::




Custom Search