Sending the Packet

Once we have assembled our protocol blocks, in order from highest-level protocol to lowest-level protocol, we can write this packet to the network. We do this using libnet_write( ), as shown in Example 11-5.

Example 11-5. Writing the packet

/* write the packet */
if ((libnet_write (l)) == -1)
  {
    fprintf (stderr, "Unable to send packet: %s\n", libnet_geterror (l));
    exit (1);
  }

The libnet_write( ) function causes libnet to assemble the packet from the protocol blocks. Then this is sent on the network, either to the IP address supplied for an injection at the LIBNET_RAW level, or to the network hardware address if the injection is at the LIBNET_LINK layer.

Get Network Security Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.