From owner-freebsd-questions Wed Jan 5 5:52:19 2000 Delivered-To: freebsd-questions@freebsd.org Received: from relay.ucb.crimea.ua (UCB-Async4-CRISCO.CRIS.NET [212.110.129.130]) by hub.freebsd.org (Postfix) with ESMTP id 71A01153C1 for ; Wed, 5 Jan 2000 05:52:06 -0800 (PST) (envelope-from ru@ucb.crimea.ua) Received: (from ru@localhost) by relay.ucb.crimea.ua (8.9.3/8.9.3/UCB) id PAA15956; Wed, 5 Jan 2000 15:46:30 +0200 (EET) (envelope-from ru) Date: Wed, 5 Jan 2000 15:46:30 +0200 From: Ruslan Ermilov To: Matt Gostick Cc: freebsd-questions@FreeBSD.ORG Subject: Re: ioctl programming probs Message-ID: <20000105154630.I18632@relay.ucb.crimea.ua> Mail-Followup-To: Matt Gostick , freebsd-questions@FreeBSD.ORG References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=M9NhX3UHpAaciwkO X-Mailer: Mutt 0.95.3i In-Reply-To: ; from Matt Gostick on Tue, Dec 28, 1999 at 10:09:30PM -0500 X-Operating-System: FreeBSD 3.3-STABLE i386 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=us-ascii That's why you should have been compile your program with -Wall and read netintro(4). Beware, that broadcast address is only meaningful on broadcast interfaces, and dstaddr is only meaningful on P2P interfaces. On Tue, Dec 28, 1999 at 10:09:30PM -0500, Matt Gostick wrote: > > I'm trying to make a simple little program that gets the ip address of a > given interface. I'm using ioctl to do this and am having a wierd problem > that I can't figure out. Any help is appretiated. > > >From what I understand about ioctl ... the below program should display > the interface name, ip address, destination address and the broadcast > address. Unfortuanely it's not. It's not crashing ... it just always > prints: > > name : lo0 > addr : 16.2.0.0 > dstaddr : 16.2.0.0 > broadaddr : 16.2.0.0 > > I've tried this on two different FreeBSD-3.2 machines with the same > result, even the same IP's. I've even tried switching the interface > names to something different, and am still getting the same IP's. > > I have searched newsgroups and mailing lists only to come up with no > solution. I was hoping that those familiar with ioctl under FreeBSD will > spot my mistake in a couple of seconds... :) I'm new to it so any help is > very much appretiated. > > /* --------------------------------------- */ > [...] > > /* ------------------------------------ */ > > > Thanks, > Matt -- Ruslan Ermilov Sysadmin and DBA of the ru@ucb.crimea.ua United Commercial Bank, ru@FreeBSD.org FreeBSD committer, +380.652.247.647 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="get_if_ip.c" #include #include #include #include #include #include #include #include #include int main(void) { int fd; struct ifreq ifr; /* Open a socket to use for ioctl(2). */ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) err(1, "socket"); strcpy(ifr.ifr_name, "lo0"); /* Get if address. */ if (ioctl(fd, SIOCGIFADDR, &ifr, sizeof(ifr)) == -1) err(1, "ioctl(SIOCGIFADDR)"); printf("name : %s\n", ifr.ifr_name); printf("addr : %s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); /* Get destination address. */ if (ioctl(fd, SIOCGIFDSTADDR, &ifr, sizeof(ifr)) == -1) warn("ioctl(SIOCGIFDSTADDR)"); else printf("dstaddr : %s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_dstaddr)->sin_addr)); /* Get broadcast address. */ if (ioctl(fd, SIOCGIFBRDADDR, &ifr, sizeof(ifr)) == -1) warn("ioctl(SIOCGIFBRDADDR)"); else printf("broadaddr : %s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_broadaddr)->sin_addr)); close(fd); return 0; } --M9NhX3UHpAaciwkO-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message