Skip to content

Commit

Permalink
Should now correctly import on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Pix-xiP committed Nov 22, 2023
1 parent 51296f9 commit 15eb257
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ odin-libpcap
**.out
ols.json

tests.bin
4 changes: 2 additions & 2 deletions pcap.odin
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package odin_libpcap

import "core:os"
import _c "core:c"
import "core:c/libc"
import "core:os"

// TODO: Add a when for each system - Linux, Windows etc.
when ODIN_OS == .Windows {
// WinPcap, NPcap are the options here.
foreign import libpcap "system:npcap" // 99% sure this is wrong, but placeholder
}
when ODIN_OS == .Linux {
foreign import libpcap "libpcap" // TODO: Put on a linux VM and check if .a needed
foreign import libpcap "system:pcap"
}
when ODIN_OS == .Darwin {
// HACK: Ran into issues with it finding the dylib, so moved it into the folder..
Expand Down
6 changes: 3 additions & 3 deletions tests/test.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package libpcap_tests

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

Expand All @@ -24,7 +24,7 @@ basic_find_devs :: proc(t: ^_t.T) {
for i := interfaces; i != nil; i = i.next {
fmt.printf("Interface: %s - ", i.name)
for a := i.addresses; a != nil; a = a.next {
if a.addr.family == os.AF_INET {
if cast(int)a.addr.sa_family == os.AF_INET {
sock_in := cast(^os.sockaddr_in)a.addr
ip4 := net.IP4_Address(transmute([4]u8)sock_in.sin_addr.s_addr)
fmt.printf(ntoa(ip4))
Expand Down

0 comments on commit 15eb257

Please sign in to comment.