PDA

Ver la versión completa : #include <netinet/udp.h> Donde estas ¿?



chewarrior
16-04-2011, 00:20
printf(" %i :%g",iphead->saddr,udphead->sport);
printf("%i %g\n", iphead->daddr,udphead->dport);







/root/C/sniffer.c:50: error: 'struct udphdr' has no member named 'sport'
/root/C/sniffer.c:51: error: 'struct udphdr' has no member named 'dport'



Segun el copilador la estructura no contiene nada, vamos que me los esta tocando pero bien, a ver si me podeis echar una manita :(.


A las librerias:

#include <linux/if_ether.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <netinet/ip.h>
#include <netinet/udp.h>

Goatse
16-04-2011, 00:28
struct udphdr {
__be16 source;
__be16 dest;
__be16 len;
__sum16 check;
};

chewarrior
16-04-2011, 18:46
#include <netinet/in.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>

#define MAX 4025




main(){


int pid;

pid=fork();

if(pid==0){

char buffer[MAX];
int sock;
int bytes_read;

sock = socket(PF_INET,SOCK_RAW,IPPROTO_UDP);

struct iphdr *iph;
struct udphdr *udph;


iph = (struct iphdr *)buffer;

do{

bytes_read=recv(sock,buffer,MAX, 0);


if(iph->protocol==IPPROTO_UDP){

udph=(struct udphdr*)(buffer+sizeof(struct iphdr));

printf("Origen UDP %s :%d\n",inet_ntoa(iph->saddr),ntohs(udph->source));
printf("Destino UDP %s :%d\n", inet_ntoa(iph->daddr),ntohs(udph->dest));

udph==NULL;

iph==NULL;

buffer==NULL;
}

}
while (bytes_read >0);

}
else
{


//fcntl(sock,F_SETFL,O_NONBLOCK);
//memset( &address, 0, sizeof( address ) );
//address.sa_family = AF_INET;
//strncpy( address.sa_data, "wlan0", sizeof(address.sa_data) );
char buffer2[MAX];
int sock2;
int bytes_read2;

sock2 = socket(PF_INET,SOCK_RAW,IPPROTO_TCP);

struct iphdr *iph2;
struct tcphdr *tcph;

iph2 = (struct iphdr *)buffer2;


do{

bytes_read2=recv(sock2,buffer2,MAX,0);

if(iph2->protocol==IPPROTO_TCP){

tcph=(struct tcphdr*)(buffer2+sizeof(struct iphdr));

printf("Origen TCP %s :%d\n",inet_ntoa(iph2->saddr), ntohs(tcph->source));
printf("Numero de secuencia: %d ACK: %i\n ",ntohs(tcph->seq),ntohs(tcph->ack_seq));
printf("Destino TCP %s :%d\n", inet_ntoa(iph2->daddr), ntohs(tcph->dest));

tcph==NULL;

iph2==NULL;

buffer2==NULL;




}
}
while (bytes_read2> 0);

}

}


Ok gracias, parace que al referencia que yo tenia no era la correcta xd.

Goatse
16-04-2011, 18:53
La próxima vez que te pase algo así no haces nada mejor que comprobar el .h para quitarte de dudas ;)

chewarrior
16-04-2011, 19:03
La próxima vez que te pase algo así no haces nada mejor que comprobar el .h para quitarte de dudas


ok ok ok,es que muchas veces me ciego xd.