Enviado em 01/01/2020 - 16:25h
Não consigo entender porque o código está dando falha de segmentação, está igual ao exemplo que peguei. O que causa esses erros ? Segue o código.#include <stdio.h>
#include <pcap.h>
#include <time.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
void print_packet_info(const u_char *packet, struct pcap_pkthdr packet_header);
int main(int argc, char const *argv[])
{
char *device;
char error_buffer[PCAP_ERRBUF_SIZE];
pcap_t *handle;
const u_char *packet;
struct pcap_pkthdr packet_header;
int packet_count_limit = 1;
int timeout_limit = 10000; //tempo em milisegundos
device = pcap_lookupdev(error_buffer);
if (device == NULL)
{
printf("Erro ao encontrar dispositivo: %s\n", error_buffer);
return 1;
}
//abrindo o dispositivo para captura
handle = pcap_open_live(device, BUFSIZ, packet_count_limit, timeout_limit, error_buffer);
//O código captura um pacote. Se não houver tráfico na rede e o tempo for atingido, será retornado NULL
packet = pcap_next(handle, &packet_header);
if (packet == NULL)
{
printf("Nenhum pacote encontrado. \n");
return 2;
}
print_packet_info(packet, packet_header);
return 0;
}
void print_packet_info(const u_char *packet, struct pcap_pkthdr packet_header)
{
printf("Tamanho capturado do pacote: %d\n", packet_header.caplen);
printf("Tamanho total do pacote: %d\n", packet_header.len);
}
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Fez porcaria no teu repositório Git? Aprenda a restaurar uma versão anterior do seu código!
Restaurando Fontes de Download do Hydra no Linux
Atualizando "na marra" o YT-DLP quando começa a dar erro de downloads
Como instalar o WPS com interface e corretor ortográfico em PT-BR no Arch Linux
Bluetooth CSR 4.0 Dongle (Alternativo) (2)
Desbloquear chaveiro padrão (5)
como eu instalo o mali-t60x_r12... (5)