Skip to content

pbridge.c Bianucci#387

Open
andrea-bianucci wants to merge 3 commits intolucaderi:masterfrom
andrea-bianucci:master
Open

pbridge.c Bianucci#387
andrea-bianucci wants to merge 3 commits intolucaderi:masterfrom
andrea-bianucci:master

Conversation

@andrea-bianucci
Copy link
Copy Markdown

Buonasera,

Ho trasformato l'originario pcount.c in pbridge.c, implementando una struttura bidirezionale tra due interfacce di rete. Ho introdotto solo i cambiamenti necessari per garantire il funzionamento del bridge, preparando al contempo il terreno per l'integrazione futura dei filtri di pacchetto.

Ho stravolto l'idea iniziale dei thread con poll() e pcap_dispatch(). Per quanto rigurda l'invio dei pacchetti ho deciso di rimanere aderente a packet_send.c visto a lezione, quindi l'uso di pcap_inject.

Resto a completa disposizione per feedback, suggerimenti o eventuali correzioni sull'architettura,
AB

// - packet --> puntatore ai dati del pacchetto da inviare (es: ARP, ICMP, ...)
// - len --> lunghezza del pacchetto in byte
fprintf(stderr, "Failed to send packet: %s\n", pcap_geterr(handle));
exit(1);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gli exit in un programma non sono mai belli: andrebbero gestiti diversamente

Copy link
Copy Markdown
Owner

@lucaderi lucaderi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buon lavoro, ci sono piccoli problemi che puoi risolvere


if(stat(device, &s) == 0) { // stat() verifica se device esiste come file nel filesystem --> 0 == esiste; se non esiste lo trattiamo come nome di interfaccia (es: eth0)
/* Device is a file (probabilmente .pcap) on filesystem */
if((pd1 = pcap_open_offline(device, errbuf)) == NULL) { // non stiamo catturando traffico live --> leggiamo pacchetti gia salvati (file .pcap)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questo lo puoi togliere con il bridge


if(stat(device2, &s) == 0) { // stat() verifica se device esiste come file nel filesystem --> 0 == esiste; se non esiste lo trattiamo come nome di interfaccia (es: eth0)
/* Device is a file (probabilmente .pcap) on filesystem */
if((pd2 = pcap_open_offline(device2, errbuf)) == NULL) { // non stiamo catturando traffico live --> leggiamo pacchetti gia salvati (file .pcap)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem qui

}

if(fds[0].revents & POLLIN) {
pcap_dispatch(pd1, 1, dummyProcessPacket, (u_char*)pd2);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questo va bene ma se vuoi puoi invitare direttamente il pacchetto

- Apportate correzioni evidenziate nella commit precedente
- Rimosse funzionalità non necessarie al semplice bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants