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);
}
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
O Que Fazer Após Instalar Ubuntu 25.04
O Que Fazer Após Instalar Fedora 42
Debian 12 -- Errata - Correções de segurança
Instalando o Pi-Hole versão v5.18.4 depois do lançamento da versão v6.0
Alguém poderia me ajudar a escolher peças pra montar um desktop? (14)
O FIM da minha distro predileta: ARCOLINUX ...que pena (9)
samba4 gpo instalar impressora via windows (0)