libnet_adv_write_raw()
"Mustafa Abu Sedera" <[email protected]>
| Newsgroups | gmane.comp.security.libnet |
|---|---|
| Message-ID | <[email protected]> |
Hi Mike! as you have maybe already seen in the mailing list i was asking if it was possible to send a raw ip packet in a similar way like libnet_adv_write_link() by just specifying a pointer to the packet and it's length. i looked at the source code of libnet_write() and used libnet_write_raw_ipv4() directly in my program and it worked,but having the disadvantage of libnet_t* not being updated with new statistics. so made some easy modification to libnet_write() by cutting away the code of libnet_pblock_coalesce() and instead let let the user supply the function with the u_int8_t* packet and u_int32_t len. then doing some checking if libnet_t is opened in advanced mode raw and cut away the code which wouldn't be used anymore (switch cases & default, aligner check, free packet). please take a look at it. if you like the idea and could do it in a better way it could be added to 1.1.2. P.S. please don't make fun of me if it is totally dump ;). i am still kinda noob but this function would be useful for me and i think for others too. regards, Mustaffa Abu Sedira _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail
libnet_adv_write_raw.c
(application/octet-stream, 1.4 KB)
int
libnet_adv_write_raw(libnet_t *l, u_int8_t *packet, u_int32_t len)
{
u_int c;
if (l == NULL)
{
return (-1);
}
if ( (l->injection_type != LIBNET_RAW4_ADV) || (l->injection_type != LIBNET_RAW6_ADV) )
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
"%s(): advanced raw mode not enabled\n", __func__);
return (-1);
}
/* assume error */
c = -1;
switch (l->injection_type)
{
case LIBNET_RAW4_ADV:
if (len > LIBNET_MAX_PACKET)
{
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
"%s(): packet is too large %d\n", __func__, len);
return (c);
}
c = libnet_write_raw_ipv4(l, packet, len);
break;
case LIBNET_RAW6_ADV:
c = libnet_write_raw_ipv6(l, packet, len);
break;
}
/* do statistics */
if (c == len)
{
l->stats.packets_sent++;
l->stats.bytes_written += c;
}
else
{
l->stats.packet_errors++;
/*
* XXX - we probably should have a way to retrieve the number of
* bytes actually written (since we might have written something).
*/
if (c > 0)
{
l->stats.bytes_written += c;
}
}
return (c);
}