Re: libnet_write

"Mustafa Abu Sedera" <[email protected]> Tue, 08 Jun 2004 15:10:40 +0000
Newsgroups gmane.comp.security.libnet
Message-ID <[email protected]>
Hi,
like I wrote before.....if you don't want do build the eth hdr you can use 
libnet_adv_write_raw().
This is nto an "official" function in libnet. I modified the 
libnet_adv_write_link() so that it injects the packet to the kernel which 
takes care of the eth hdr because i needed it in a program.
You just copy and paste the code at the beginning of your program or in a 
header file then use it like an ordinary libnet function.
I suggested before to add it to the libnet API but didn't get any feedback.
Please try it out as it made my job much easier.
here it is again if you have deleted the previous email:

int
libnet_adv_write_raw(libnet_t *l, u_int8_t *packet, u_int32_t len)
{
    u_int c;

    if (l == NULL)
    {
        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;

        default:
            snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                "%s(): advanced raw mode not enabled\n", __func__);
            return (-1);
    }

    /* 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);
}
To describe the function again....
You pass a pointer "packet" which would point to the ip header of a packet 
with length "len" (total IP packet length without the eth hdr) and it writes 
the packet to libnet handle "l".

Regards,
Mustaffa Abu Sedira


>From: [email protected]
>To: Aaron Turner <[email protected]>
>CC: "Jee J.Z." <[email protected]>, [email protected]
>Subject: Re: libnet_write
>Date: Mon, 7 Jun 2004 10:01:44 +0530
>
>
>
>
>
>Hi,
>
>   What if I do not want to build the ethernet header. I want the packet to
>be a raw packet that is handed to ip after the write call. What about
>libnet_write_raw_ipv4, i tihink that is no longer supported, i use libnet
>1.1.2.1.
>  Mustafa talked about libnet_write_raw_ipv4, but I can't finds that in my
>help either, such a function exists ?
>
>thanks
>Amit
>

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail