From owner-freebsd-questions Tue Dec 28 19:17:19 1999 Delivered-To: freebsd-questions@freebsd.org Received: from thunk.crazylogic.net (thunk.crazylogic.net [199.45.111.154]) by hub.freebsd.org (Postfix) with ESMTP id 3F83D1516F for ; Tue, 28 Dec 1999 19:17:16 -0800 (PST) (envelope-from matt@crazylogic.net) Received: from localhost (matt@localhost) by thunk.crazylogic.net (8.9.3/8.9.3) with ESMTP id WAA40727 for ; Tue, 28 Dec 1999 22:09:30 -0500 (EST) (envelope-from matt@crazylogic.net) Date: Tue, 28 Dec 1999 22:09:30 -0500 (EST) From: Matt Gostick To: freebsd-questions@freebsd.org Subject: ioctl programming probs Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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. /* --------------------------------------- */ #include #include #include #include #include int main (void) { int fd; struct ifreq ifr; /* open a socket to use for ioctl */ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { perror("socket"); return -1; } strcpy(ifr.ifr_name, "lo0"); /* get if address */ if (ioctl(fd, SIOCGIFADDR, &ifr, sizeof(ifr)) == -1) { close(fd); perror("ioctl"); return -1; } printf("name : %s\n", ifr.ifr_name); printf("addr : %s\n", inet_ntoa(ifr.ifr_addr)); printf("dstaddr : %s\n", inet_ntoa(ifr.ifr_dstaddr)); printf("broadaddr : %s\n", inet_ntoa(ifr.ifr_broadaddr)); close(fd); return 0; } /* ------------------------------------ */ Thanks, Matt To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message