Libnet
Message too long Apr 16 2005 06:10AM
Karen Pease (meme daughtersoftiresias org) (1 replies)
This should be a relatively simple problem, but it is beyond me. I'm trying
to write 1243 bytes to the wire (which should fit in an ethernet frame), but
am getting "Message too long".

This function (below) is getting called, and it is printing:

1243
ERROR (libnet_context.cxx,249,0x8104fa0): Write error: libnet_write_link():
only -1 bytes written (Message too long)

Here is the function:

// Send a Base packet

bool LibnetContext::send(BasePacket& base_packet)
{
libnet_ptag_t ip_tag = LIBNET_PTAG_INITIALIZER,
ethernet_tag = LIBNET_PTAG_INITIALIZER,
udp_tag = LIBNET_PTAG_INITIALIZER;

const string contents=base_packet.serialize_contents();
const int length=contents.length();

cout << (LIBNET_IPV4_H + LIBNET_UDP_H + length) << endl;

//Build the udp header
udp_tag = libnet_build_udp(
base_packet.src_port.value(),
base_packet.dest_port.value(),
LIBNET_UDP_H,
0,
(u_int8_t*)contents.data(), //payload
length, //payload size
l, //libnet handle
udp_tag); //libnet id
if (udp_tag == -1)
{
ERROR << "Can't build UDP header: " << libnet_geterror(l) << "\n";
return false;
}

//Build the ipv4 header
ip_tag = libnet_build_ipv4(
LIBNET_IPV4_H + LIBNET_UDP_H + length, //length
0, //TOS
0, //IP ID
0, //IP Frag
64, //TTL
IPPROTO_UDP, //Protocol
0, //checksum
base_packet.src_ip.get_inaddr(), //source IP
base_packet.dest_ip.get_inaddr(), //destination IP
NULL, //payload
0, //payload size
l, //libnet handle
ip_tag); //libnet id
if (ip_tag == -1)
{
ERROR << "Can't build IP header: " << libnet_geterror(l) << "\n";
return false;
}

//Build the ethernet header

ethernet_tag = libnet_build_ethernet(
base_packet.dest_mac.get_array(),
base_packet.src_mac.get_array(),
ETHERTYPE_IP,
NULL,
0,
l,
ethernet_tag);

if (ethernet_tag == -1)
{
ERROR << "Can't build ethernet header: " << libnet_geterror(l) <<
"\n";
return false;
}

const int c = libnet_write(l);
if (c==-1)
{
ERROR << "Write error: " << libnet_geterror(l) << "\n";
return false;
}

return true;
}

ERROR is a macro that prints the header on the error message; line 249 is the
line that says "Write error...".

For anyone who can offer any help, I'd be greatly appreciative. :)

- Karen

[ reply ]
How can I add ieee 802.11b support to libnet? Apr 20 2005 07:13PM
Liang Yang (liang_yang hotmail com) (1 replies)
Re: How can I add ieee 802.11b support to libnet? Apr 21 2005 05:51AM
Frédéric Raynal (frederic raynal security-labs org)


 

Privacy Statement
Copyright 2010, SecurityFocus