From owner-freebsd-net@FreeBSD.ORG Tue Sep 16 11:23:11 2008 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 18C5B106567C for ; Tue, 16 Sep 2008 11:23:11 +0000 (UTC) (envelope-from nacho319@gmail.com) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.242]) by mx1.freebsd.org (Postfix) with ESMTP id CAB7A8FC1A for ; Tue, 16 Sep 2008 11:23:10 +0000 (UTC) (envelope-from nacho319@gmail.com) Received: by an-out-0708.google.com with SMTP id b33so257851ana.13 for ; Tue, 16 Sep 2008 04:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type; bh=Pb9DDvAZnxQmZlJypZdKcQmgfXDfsWjtYtCmgUSE0yo=; b=FRH1qn0RvOOOTplIn8MeGZwHyXEVfjcYIpttKLBJISiOdLHQjbCneMrjXRNXN897eN IaC2f3HPr0wq4JtMV4dPhj7O2vyZcETOYqR5W95rP8REaC+mC+YIoOBdBNJYjZrUtkzK 6MxhQaTfO12lHIH41o65jfxz+lcNvCfwiuuoI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=xmw0lOipCgCLzBY+Ol55KJeo25RhicZxFZLQMoOtQU39EGzTrS1qyBpV807N7HTV34 iyHeGMj+wuw8R4GPCmV2fbJz+RWx78FNkWo6kvCYoUFk8A1Q/JEZYH6WS/7EU/y3+RfY trkOUFaNMYjEgqMPgEr+QPxgQRd/ijiamilcQ= Received: by 10.100.108.20 with SMTP id g20mr1254115anc.105.1221562874830; Tue, 16 Sep 2008 04:01:14 -0700 (PDT) Received: by 10.100.95.14 with HTTP; Tue, 16 Sep 2008 04:01:14 -0700 (PDT) Message-ID: <900019150809160401v316682fdt4cf8a95bfcb48dc2@mail.gmail.com> Date: Tue, 16 Sep 2008 07:01:14 -0400 From: "Chris Inacio" To: freebsd-net@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: help with code to determine external IP address on FreeBSD gateway machine X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Sep 2008 11:23:11 -0000 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