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);
}
Desktop Linux ganha fôlego enquanto distros refinam experiência e segurança
Wayland em alta, IA em debate e novos ventos para distros e devices
Qt 6.10 e Python 3.14 puxam o ritmo do software livre nesta quarta
Atualizações de Apps, Desktop e Kernel agitam o ecossistema Linux nesta terça-feira
Como mudar o nome de dispositivos Bluetooth via linha de comando
Adicionando o repositório backports no Debian 13 Trixie
Não tenho som no meu Kali linux [RESOLVIDO] (3)
Primeiras impressões do Debian 13 (28)
Erro ao enviar notificação por e-mail (1)
Erro ao fazer remaster usando Penguin eggs (2)
Meu Amigo não consegue entrar em meu mundo, via tailscale, hamachi e z... (1)