dhcp icon indicating copy to clipboard operation
dhcp copied to clipboard

Can't build/run on macOS due to client.go code

Open begetan opened this issue 6 years ago • 16 comments

go build
# github.com/insomniacslk/dhcp/dhcpv4
../../insomniacslk/dhcp/dhcpv4/client.go:125:25: undefined: unix.AF_PACKET
../../insomniacslk/dhcp/dhcpv4/client.go:125:68: undefined: unix.ETH_P_IP
../../insomniacslk/dhcp/dhcpv4/client.go:133:12: undefined: unix.SockaddrLinklayer

There are no constants in package golang.org/x/sys/unix for darwin_amd64

grep AF_PACKET *
grep: linux: Is a directory
syscall_linux.go:// SockaddrLinklayer implements the Sockaddr interface for AF_PACKET type sockets.
syscall_linux.go:	sa.raw.Family = AF_PACKET
syscall_linux.go:	case AF_PACKET:
zerrors_linux_386.go:	AF_PACKET                            = 0x11
zerrors_linux_amd64.go:	AF_PACKET                            = 0x11
zerrors_linux_arm.go:	AF_PACKET                            = 0x11
zerrors_linux_arm64.go:	AF_PACKET                            = 0x11
zerrors_linux_mips.go:	AF_PACKET                            = 0x11
zerrors_linux_mips64.go:	AF_PACKET                            = 0x11
zerrors_linux_mips64le.go:	AF_PACKET                            = 0x11
zerrors_linux_mipsle.go:	AF_PACKET                            = 0x11
zerrors_linux_ppc64.go:	AF_PACKET                            = 0x11
zerrors_linux_ppc64le.go:	AF_PACKET                            = 0x11
zerrors_linux_riscv64.go:	AF_PACKET                            = 0x11
zerrors_linux_s390x.go:	AF_PACKET                            = 0x11
zerrors_linux_sparc64.go:	AF_PACKET                        = 0x11
zerrors_solaris_amd64.go:	AF_PACKET                     = 0x20

This is a commit probably breaks compilation:
https://github.com/insomniacslk/dhcp/commit/4eedccfd12105dbcde88298e87bbbcf41aa7c1df

In BSD system AF_PACKET should be replaced by AF_LINK

BTW, why not to move client for separate package? I just removed file client.go from repo in order to compile server code.

begetan avatar Jan 17 '19 00:01 begetan

cc @get9

insomniacslk avatar Jan 17 '19 00:01 insomniacslk

BTW, why not to move client for separate package? I just removed file client.go from repo in order to compile server code.

This is actually something I've considered in the past, splitting client and server from protocol parsing. The library structure wold become a bit more fragmented but I can try and see if it doesn't look too bad.

insomniacslk avatar Jan 17 '19 00:01 insomniacslk

I'm fine with that; this package should be reserved for dhcp library code. We can have a separate one for sample clients that's a consumer of this code.

Do we have CI set up for mac builds of this library?

get9 avatar Jan 17 '19 01:01 get9

Compiling for FreeBSD I ran into the same thing.

abh avatar Jan 17 '19 01:01 abh

I'm fine with that; this package should be reserved for dhcp library code. We can have a separate one for sample clients that's a consumer of this code.

I think what @begetan meant was to split out client.go and server.go in a separate package, correct me if I'm wrong. As per the sample client, there is a working (yet not full-featured) dhclient implementation in the examples repo, https://github.com/insomniacslk/exdhcp/blob/master/dhclient/main.go

Do we have CI set up for mac builds of this library?

No, the tests are linux-only. We would just need an os section in .travis.yml, like this, https://github.com/insomniacslk/dublin-traceroute/blob/master/.travis.yml#L20. I will add it today,

insomniacslk avatar Jan 17 '19 09:01 insomniacslk

This is the PR that broke the build, http://github.com/insomniacslk/dhcp/pull/198 (not the commit mentioned above). AF_PACKET was introduced to deal with unconfigured interfaces, which is fundamental for a DHCP client to work, but AF_PACKET is Linux-specific. I'll work on a fix for darwin/freebsd

insomniacslk avatar Jan 17 '19 11:01 insomniacslk

Quick search: https://stackoverflow.com/questions/17169298/af-packet-on-osx

EDIT: this doesn't help as it basically recommends to go back to L3 sockets and wouldn't work on unconfigured interfaces

insomniacslk avatar Jan 17 '19 11:01 insomniacslk

If I'm reading it right, dhclient in FreeBSD uses... BPF, https://github.com/freebsd/freebsd/blob/master/sbin/dhclient/bpf.c#L100 . Basically like running tcpdump

insomniacslk avatar Jan 17 '19 11:01 insomniacslk

I think what @begetan meant was to split out client.go and server.go in a separate package, correct me if I'm wrong.

Exactly! That packages can handle network specific stuff (like this case) so people can manage which component of the library they actually need.

begetan avatar Jan 17 '19 23:01 begetan

Tracked at https://github.com/insomniacslk/dhcp/issues/231

insomniacslk avatar Jan 18 '19 12:01 insomniacslk

Should we close this one after PR #241? cc @begetan

pmazzini avatar Jan 28 '19 20:01 pmazzini

not really - the build still fails on darwin. Just not a hi-pri at the moment

insomniacslk avatar Jan 28 '19 20:01 insomniacslk

Should we close this one after PR #241? cc @begetan

@pmazzini This PR makes library indpendent from client code and usable on Darwin/BSD, but client code not compiled yet. It should be fixed one day.

begetan avatar Jan 29 '19 21:01 begetan

Any update yet on being able to use the client on non-linux (eg darwin) ?

hans-d avatar Sep 10 '20 21:09 hans-d

PRs are welcomed. There is even a patch that needs testing in https://github.com/insomniacslk/dhcp/issues/378#issuecomment-609066057.

pmazzini avatar Sep 12 '20 08:09 pmazzini

Related:

  • https://github.com/insomniacslk/dhcp/issues/378
  • https://github.com/insomniacslk/dhcp/pull/423

The main package should compile now and the nclient code should be usable.

pmazzini avatar Aug 10 '21 07:08 pmazzini

The client code was moved to a separate package since. I am leaving #318 for OSX related support.

pmazzini avatar Aug 16 '23 20:08 pmazzini