jackpal / gateway

A golang library for discovering the address of a LAN gateway.
BSD 3-Clause "New" or "Revised" License
226 stars 69 forks source link

Discover default gateway on linux using /proc/net/route #20

Closed ndeloof closed 4 years ago

ndeloof commented 4 years ago

Linux implementation relies on a set if netutils commands expecting at least one of them to be available. Proposed solution is to use the standard procfs /proc/net/route which exposes this information is a portable way.

alejandrodnm commented 4 years ago

Hi, I'm looking into how to determined which one's the default gateway from /proc/net/route, I stumbled upon this PR, does this mean that the first entry in the file is the default gateway? Sorry for the noise :)

alejandrodnm commented 4 years ago

Shouldn't you search for the entry with Destination = 0? That would give you the default and then parse the gateway from that entry.

jackpal commented 4 years ago

I don't know, I don't know enough about Linux networking. I would certainly consider a pull request.