Date: Mon, 16 Sep 2002 22:41:46 +0800 From: Leslie Jackson <int@softhome.net> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 16 Sep 2002 09:54:45 +0100 Bruce M Simpson <bms@spc.org> 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 <sys/types.h> #include <sys/socket.h> #include <net/if.h> #include <netinet/in.h> #include <sys/ioctl.h> #include <arpa/inet.h> #include <string.h> #include <stdio.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020916224146.52e31c8c.int>