insomniacslk / dhcp

DHCPv6 and DHCPv4 packet library, client and server written in Go
BSD 3-Clause "New" or "Revised" License
710 stars 169 forks source link

Build-scoping issue in dhcpv4/nclient4/conn_unix.go (also: BSD support for nclient4) #526

Open vista- opened 6 months ago

vista- commented 6 months ago

Hey folks,

I recently ran into an issue trying to build code that imports nclient4 on macOS/BSD-likes:

% GOOS=freebsd go build .
../../go/pkg/mod/github.com/insomniacslk/dhcp@v0.0.0-20240227161007-c728f5dd21c8/dhcpv4/nclient4/conn_unix.go:42:59: undefined: unix.ETH_P_IP

https://github.com/insomniacslk/dhcp/blob/c728f5dd21c872dcb78cba11556619fdd7b6fc20/dhcpv4/nclient4/conn_unix.go#L42

Upon looking this symbol up, I found that it is build-scoped to Linux platforms only: https://cs.opensource.google/go/x/sys/+/master:unix/zerrors_linux.go;drc=5710a32031f3498e357d801987a07d9638c4fa11;l=1091

which kind of conflicts with the build-scoping of the file itself: https://github.com/insomniacslk/dhcp/blob/c728f5dd21c872dcb78cba11556619fdd7b6fc20/dhcpv4/nclient4/conn_unix.go#L7

Would it be possible to move this specific function into a Linux build-scoped file?

To give you some context: I'm working on a multi-platform DHCP "swiss knife", and I added support for BSD-likes in my code using the (now deprecated) github.com/mdlayher/raw module that you migrated off of. I couldn't find anything like it, and it seems like those wanting to use raw BSD network sockets are stuck with it for now.

If you folks happen to be interested in this code even with this caveat, please let me know and I'll work on "upstreaming" BSD support for the DHCPv4 client. :)

hugelgupf commented 6 months ago

I'm for it - both the Linux specific thing and upstreaming