From owner-freebsd-hackers Mon Sep 16 7:41:57 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B238337B401 for ; Mon, 16 Sep 2002 07:41:55 -0700 (PDT) Received: from jive.SoftHome.net (jive.SoftHome.net [66.54.152.27]) by mx1.FreeBSD.org (Postfix) with SMTP id 18D7B43E6E for ; Mon, 16 Sep 2002 07:41:55 -0700 (PDT) (envelope-from int@softhome.net) Received: (qmail 7467 invoked by uid 417); 16 Sep 2002 14:41:54 -0000 Received: from shunt-smtp-out-0 (HELO softhome.net) (172.16.3.12) by shunt-smtp-out-0 with SMTP; 16 Sep 2002 14:41:54 -0000 Received: from int.homeunix.org ([218.58.82.222]) (AUTH: LOGIN int@softhome.net) by softhome.net with esmtp; Mon, 16 Sep 2002 08:41:53 -0600 Date: Mon, 16 Sep 2002 22:41:46 +0800 From: Leslie Jackson To: freebsd-hackers@freebsd.org Subject: Re: ioctl & SIOCDIFADDR Message-Id: <20020916224146.52e31c8c.int@softhome.net> In-Reply-To: <20020916085445.GA11460@spc.org> References: <20020916114315.7feb4bac.int@softhome.net> <20020916085445.GA11460@spc.org> X-Mailer: Sylpheed version 0.7.6 (GTK+ 1.2.10; i386-portbld-freebsd4.6) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, 16 Sep 2002 09:54:45 +0100 Bruce M Simpson wrote: > On Mon, Sep 16, 2002 at 11:43:15AM +0800, Leslie Jackson wrote: > > I can specify an specific IP, say, "192.168.0.2", for SIOCDIFADDR to > > delete. But how can i specify this "default address"(said in the > > netintor(4)) to"delete the first address of the interface"? > > Try 0.0.0.0. (aka INADDR_ANY). > > BMS Failed using that way. (SIOCDIFADDR: can't assign requested addressed) The following is the simple code: /* * Delete an IP address of lo0 */ #include #include #include #include #include #include #include #include int main(void) { int s; struct ifaliasreq ifaliasreq; struct sockaddr_in *in; s = socket(PF_INET, SOCK_STREAM, 0); memset(&ifaliasreq, 0, sizeof(ifaliasreq)); strncpy(ifaliasreq.ifra_name, "lo0", sizeof(ifaliasreq.ifra_name)); in = (struct sockaddr_in *) &ifaliasreq.ifra_addr; in->sin_family = AF_INET; in->sin_len = sizeof(ifaliasreq.ifra_addr); /* * if i use "0.0.0.0" or INADDR_ANY", i'd get this error: * SIOCDIFADDR: can't assign requested addressed * * in->sin_addr.s_addr = htonl(INADDR_ANY); * in->sin_addr.s_addr = inet_addr("0.0.0.0"); */ /* okay if using a specific IP */ in->sin_addr.s_addr = inet_addr("127.0.0.1"); if (ioctl(s, SIOCDIFADDR, &ifaliasreq) == -1) perror("SIOCDIFADDR"); return (0); } Something missed or wrong? Thanks for any insights. -- Leslie Jackson To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message