Skip to content

Commit

Permalink
The first of many tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
Pix committed Jul 1, 2023
1 parent 4fcf487 commit 534add4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package libpcap_tests

// Will require sudo / root / admin privs in most cases to connect to an interface
import pcap "../"
import "core:fmt"
import "core:strings"
import _t "core:testing"

@(test)
basic_find_devs :: proc(t: ^_t.T) {
errbuf: [pcap.PCAP_ERRBUF_SIZE]byte
interfaces: ^pcap.pcap_if_t

err := pcap.findalldevs(&interfaces, &errbuf[0])
if err == pcap.PCAP_ERROR {
fmt.println(
"Error while finding all devs: ",
strings.string_from_ptr(&errbuf[0], len(errbuf)),
)
panic("findalldevs failed")
}
iface := interfaces
fmt.println("Printing interfaces")
for (iface != nil) {
fmt.printf("Interface: %s ", iface.name)
if iface.flags & pcap.PCAP_IF_UP == pcap.PCAP_IF_UP {
fmt.printf("is UP\n")
} else {
fmt.printf("is DOWN\n")
}
iface = iface.next
}

pcap.freealldevs(interfaces)
}

0 comments on commit 534add4

Please sign in to comment.