Cr4sh_Dump
(usa Debian)
Enviado em 02/12/2012 - 08:05h
Bom voce estava certo eu tava declarando errado a include ou seja com <> agora declarei com "" e tentei compilar apenas o main.c mesmo assim volto muitos erros então vou passar a postar os erros novamente e vou postar o conteudo do arquivo common.h e do main.c
Erros apresentados:
root@bt:~/Desktop# gcc -Wall -c main.c
main.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
main.c: In function ‘main’:
main.c:13: error: storage size of ‘saddr’ isn’t known
main.c:14: error: storage size of ‘in’ isn’t known
main.c:15: warning: implicit declaration of function ‘malloc’
main.c:15: warning: incompatible implicit declaration of built-in function ‘malloc’
main.c:17: error: ‘smppslog’ undeclared (first use in this function)
main.c:17: error: (Each undeclared identifier is reported only once
main.c:17: error: for each function it appears in.)
main.c:17: warning: implicit declaration of function ‘fopen’
main.c:18: error: ‘NULL’ undeclared (first use in this function)
main.c:19: warning: implicit declaration of function ‘printf’
main.c:19: warning: incompatible implicit declaration of built-in function ‘printf’
main.c:25: warning: implicit declaration of function ‘socket’
main.c:25: error: ‘AF_INET’ undeclared (first use in this function)
main.c:25: error: ‘SOCK_RAW’ undeclared (first use in this function)
main.c:25: error: ‘IPPROTO_TCP’ undeclared (first use in this function)
main.c:35: warning: implicit declaration of function ‘recvfrom’
main.c:41: warning: implicit declaration of function ‘processPacket’
main.c:44: warning: implicit declaration of function ‘close’
main.c:14: warning: unused variable ‘in’
main.c:13: warning: unused variable ‘saddr’
main.c: At top level:
main.c:51: warning: conflicting types for ‘processPacket’
main.c:41: note: previous implicit declaration of ‘processPacket’ was here
main.c: In function ‘processPacket’:
main.c:57: error: dereferencing pointer to incomplete type
main.c:67: warning: implicit declaration of function ‘print_tcp_packet’
main.c:71: warning: implicit declaration of function ‘print_udp_packet’
main.c:78: warning: incompatible implicit declaration of built-in function ‘printf’
common.h
#ifdef __common_h
#define __common_h
#include<stdio.h> //For all standard things
#include<stdlib.h> //For malloc
#include<string.h> //For memset
#include<sys/socket.h> //For create a Raw Socket
#include<netinet/ip.h> //Declaration for ip header
#include<netinet/tcp.h> //Declaration for tcp header
#include<netinet/udp.h> //Declaration for udp header
#include<netinet/ip_icmp.h>//Declaration for icmp header
#include<arpa/inet.h> //Declaration for arp header
/*function prototipes*/
void print_ip_header(unsigned char*, int);
void print_tcp_packet(unsigned char*, int);
void print_udp_packet(unsigned char*, int);
void print_icmp_packet(unsigned char*, int);
void printDatagram(unsigned char*, int);
void processPacket(unsigned char*, int);
int main();
/*global var declaration*/
extern int sock_raw;
extern int tcp, udp, icmp, igmp, others, total, i, j;
extern FILE *smppslog;
extern struct sockaddr_in source, dest;
#endif /*__common_h*/
main.c
#include "common.h"
/*global var declaration*/
int sock_raw;
int tcp = 0, udp = 0, icmp = 0, igmp = 0, others = 0, total = 0, i, j;
FILE *smppslog;
struct sockaddr_in source, dest;
/*function main*/
int main(){
int saddr_size, data_size;
struct sockaddr saddr;
struct in_addr in;
unsigned char *buffer = (unsigned char *)malloc(65536);//65536 Ports
smppslog=fopen("smpps.txt", "w");
if(smppslog == NULL)
printf("Unable to create the smppslog file, check the permissions.\n");
printf("\n\n\t ##### # # ###### ###### #####\n\t# # ## ## # # # # # #\n\t# # # # # # # # # #\n\t ##### # # # ###### ###### #####\n\t # # # # # #\n\t# # # # # # # #\n\t ##### # # # # #####\n\n");
printf("\t Simple Multi Protocol Packet Sniffer\n\t\t SMPPS v0.9.0 pre-alpha\n\t Development and Programing by\n\t\t Cr4sh_Dump\n\n");
printf("Starting packets capture...\n");
/*create a raw socket that sniffer*/
sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
if(sock_raw < 0){
printf("Socket Error on create\n");
return 1;
}
while(1){
saddr_size = sizeof saddr;
/*Receive a packet*/
data_size = recvfrom(sock_raw, buffer, 65536, 0, &saddr, &saddr_size);
if(data_size < 0){
printf("Recvfrom Error, failed to get packets\n");
return 1;
}
/*Now Process the packet*/
processPacket(buffer, data_size);
}
close(sock_raw);
printf("Process Finished\n");
return 0;
}
/*Process Packet cap function*/
void processPacket(unsigned char* buffer, int size){
/*Get the part IP header of this packet */
struct iphdr *iph = (struct iphdr*)buffer;
++total;
/*Check the protocol and...*/
switch(iph -> protocol){
case 1: //ICMP Protocol
++icmp;
//print_icmp_packet(buffer, size);
break;
case 2: //IGMP Protocol
++igmp;
break;
case 6: //TCP Protocol
++tcp;
print_tcp_packet(buffer, size);
break;
case 17: //UDP Protocol
++udp;
print_udp_packet(buffer, size);
break;
default: //Case other protocol exp: ARP, etc.
++others;
break;
}
printf("TCP : %d UDP : %d ICMP : %d IGMP : %d Others : %d Total : %d\n\n", tcp, udp, icmp, igmp, others, total);
}
Desde já agradeço a ajuda e a paciencia que voces estão me dando Obrigado mesmo.