🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #8163

programando con libnet

#8163
From: nyenyus
Date: Sun, 22 Dec 2002 15:12
83 lines
4136 bytes
hola,

estoy intentando programar en C una aplicacion para generar paquetes ARP 
bajo linux. Para ello utilizo las libreria libnet.
He seguido y mirado (y re-mirado) el ejemplo que hay en el tar.gz. 
El problema es que cuando ejecuto el programa, en el hub parece que si hay 
actividad (es decir, k envia el paquete) pero en cambio al escuchar con 
tcpdump no me da nada, no lo captura. Mi duda es: el paquete se genera y yo 
no se como funciona el tcpdump (utilizo comando #tcpdump "arp")? esta mal 
escrito el c�digo (abajo lo pego)?

Gracias

En el codigo siguiente se utilizan unos objetos (Cabecera_MAC y 
Cabecera_ARP). Creo que estan bien, pq ya las he utilizado y no han dado 
nunca fallo alguno. No los "pego" aqui por el tama�o, si alguien lo quiere 
k lo pida.
---------------------------------------------------------------
#include "MiGenerador.h"

char errbuf[LIBNET_ERRBUF_SIZE];
libnet_ptag_t t;

Mi_Generador::Mi_Generador(std::string dispositivo)
{
  Mi_Generador::dispositivo = dispositivo;
  if ((l=::libnet_init(LIBNET_LINK_ADV,(char 
*)dispositivo.c_str(),errbuf))==NULL)
      throw Excepciones("Mi_Generador::Mi_Generador ---> Error inicializando 
libnet\n---- " + (string) errbuf + " --\n");
  
}
***
Mi_Generador::~Mi_Generador(void)
{
  libnet_destroy(l);
}
***
void Mi_Generador::Send_ARP (Cabecera_ARP * carp, Cabecera_MAC * cmac)
{
  int c;
  u_char * paquete;
  u_long paquete_s;
    
  if ((t = ::libnet_build_arp(carp->GetHardType_value(),
                              carp->GetProtocol_value(),
                              carp->GetLen_value(HARD_ADDR),
                              carp->GetLen_value(PROT_ADDR),
                              carp->GetOperation_value(),
                              carp->GetAddr_value(SRC_ADDR, HARD_ADDR),
                              carp->GetAddr_value(SRC_ADDR, HARD_ADDR),
                              carp->GetAddr_value(SRC_ADDR, HARD_ADDR),
                              carp->GetAddr_value(SRC_ADDR, HARD_ADDR),
                              NULL,0,l,0))==-1)
      throw Excepciones("Mi_Generador::Send_ARP ---> Error generando paquete 
ARP -- error generando cabecera ARP" + (string) libnet_geterror(l));

  if ((t=::libnet_build_ethernet(cmac->GetAddr_value(DST_ADDR),
                                 cmac->GetAddr_value(SRC_ADDR),
                                 cmac->GetType_value(),
                                 NULL,0,l,0))==-1)
      throw Excepciones("Mi_Generador::Send_ARP ---> Error generando paquete 
ARP -- error generando cabecera ethernet" + (string) libnet_geterror(l));


  if ((c=libnet_adv_cull_packet(l,&paquete,&paquete_s))==-1)            
      throw Excepciones("Mi_Generador::Send_ARP ---> Error enviando paquete 
ARP -- " + (string) libnet_geterror(l));

  if ((c=libnet_write(l))==-1)
      throw Excepciones("Mi_Generador::Send_ARP ---> Error enviando(2) 
paquete ARP -- " + (string) libnet_geterror(l));
}








-- 
nyenyusbaratus_NO_SPAM_@_YA_SABEIS_hotmail.com
Technical Details
Message-ID: <au4kon$4844j$2@ID-165466.news.dfncis.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!162.red-80-36-231.pooles.rima-tde.NET!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,87c83778e303619b,start
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2002-12-22 07:12:25 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!162.red-80-36-231.pooles.rima-tde.NET!not-for-mail
From: nyenyus <nyenyusbaratus_YA_SABEIS_NO_SPAM@hotmail.com>
Newsgroups: es.comp.os.linux.programacion
Subject: programando con libnet
Date: Sun, 22 Dec 2002 16:12:25 +0100
Organization: Casa
Lines: 83
Message-ID: <au4kon$4844j$2@ID-165466.news.dfncis.de>
Reply-To: nyenyusbaratus_QUITAR_XDD_@hotmail.com
NNTP-Posting-Host: 162.red-80-36-231.pooles.rima-tde.net (80.36.231.162)
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 8Bit
X-Trace: fu-berlin.de 1040569944 4460691 80.36.231.162 (16 [165466])
Mail-Copies-To: nyenyusbaratus_NO_SPAM_YA_SABEIS@hotmail.com
User-Agent: KNode/0.7.1