help with code to determine external IP address on FreeBSD gateway machine

Chris Inacio nacho319 at gmail.com
Tue Sep 16 11:23:11 UTC 2008


Hello,
I'm writing a tiny bit of code to do NAT-PMP and I need code that can
determine what the external facing IP address is on a machine with
presumably multiple interfaces.  I think I have a method in mind which would
involve getting the default route, and then figuring out which interface is
reachable by that default route.  There are always all the other methods of
going out to a web site which will reflect my IP address back to me on a web
site - and while reliable, that seems sort of hackish.

So the thing is, I'm not super familiar with the necessary ioctl calls, or
routing socket calls, or...?  Can somebody save me a ton of time and just
point me in the right direction as to how to get this done?  I was looking
through the code of src/net/route.c, but decided a lot of context was needed
to understand what I was reading.

Any help would be very much appreciated.


Thanks,
Chris


More information about the freebsd-net mailing list