Subject: Re: SIOCAIFADDR vs ifconfig
To: Tomas Berndtsson <tomber@packetfront.com>
From: Andrew Brown <atatat@atatdot.net>
List: tech-net
Date: 09/24/2001 09:54:45
--xHFwDpU9dbj6ez1V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
>> >ifconfig lo0 192.168.127.26 netmask 255.255.255.0 alias
>>
>> And if you do:
>> ifconfig lo0 192.168.127.26 netmask 255.255.255.255 alias
>
>Same thing. When I set with ifconfig, it works. When I set with my
>program, using SIOCAIFADDR, it doesn't work, even if the output from
>netstat -rn and ifconfig -A lo0 is exactly the same.
this program works for me. see if you rip out the bits you need.
--
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org * "ah! i see you have the internet
twofsonet@graffiti.com (Andrew Brown) that goes *ping*!"
andrew@crossbar.com * "information is power -- share the wealth."
--xHFwDpU9dbj6ez1V
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="siocaifaddr.c"
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
int
main(int argc, char *argv[])
{
int s;
struct ifaliasreq ifaliasreq;
struct sockaddr_in *in;
s = socket(PF_INET, SOCK_STREAM, 0);
memset(&ifaliasreq, 0, sizeof(ifaliasreq));
sprintf(ifaliasreq.ifra_name, "lo0");
in = (struct sockaddr_in *) &ifaliasreq.ifra_addr;
in->sin_family = AF_INET;
in->sin_len = sizeof(ifaliasreq.ifra_addr);
in->sin_addr.s_addr = inet_addr("192.168.127.26");
in = (struct sockaddr_in *) &ifaliasreq.ifra_mask;
in->sin_family = AF_INET;
in->sin_len = sizeof(ifaliasreq.ifra_mask);
in->sin_addr.s_addr = inet_addr("255.255.255.255");
if (ioctl(s, SIOCAIFADDR, &ifaliasreq) == -1)
perror("SIOCAIFADDR");
return (0);
}
--xHFwDpU9dbj6ez1V--