- prober: send NB or ARP requests to all hosts of the network
- pkt_sniffer: sniff using pcap [ filter: (((arp or rarp) and arp[6:2] & 1 == 0) or ( udp and port 137)) ]
- resolver: perform async reverse DNS resolutions
- notifier: print events to stdout
- if host is !known goto 4
- if host has timedout, delete host and goto 4
- send ARP request; end
- send NB request
- name = ( pkt is NB ? ((NB)pkt).name : NULL )
- mac = pkt.mac
- ip = ( pkt is ARP ? ((ARP)pkt).ip : ((UDP)pkt).ip )
- add new host(mac, ip, name)
- if host.name or host.dns_sent end
- ares_gethostbyaddr(host.ip)
- if host.name end
- host.name = DNS_reply.name
there is many points where we have to check if the current host has been found. this is why i choosen an offset access table rater then an associative one. the offset is the gap between current host IP address and the base IP address. that array will contain only pointers to a struct. a NULL pointer is an unknown host.
we must delay a bit between every round.
a pthread_cond_t
global variable is used to notify that an host has been found.
another pthread_cond_t
global variable is used to notify that an event has been added.