[ECOS] Re: Does FreeBSD stack support multiple IP addresses?
Grant Edwards
grant.b.edwards@gmail.com
Tue Mar 15 14:56:00 GMT 2016
On 2016-03-15, Lambrecht Jürgen <J.Lambrecht@TELEVIC.com> wrote:
> On 02/23/2016 04:59 PM, Grant Edwards wrote:
>> I just re-ran my tests and verified again that I'm able to set the IP
>> and netmask in a single call to ioctl(SIOCAIFADDR). In my tests, I
>> tried:
>>
>> Address Netmask
>> ----------- --------------
>> 11.0.0.104 255.0.0.0
>> 11.0.0.104 255.255.0.0
>> 11.0.0.104 255.255.255.0
>> 11.0.0.104 255.240.0.0
> OK, now I see it: you use
> SIOCAIFADDR
> we use
> SIOCSIFADDR
> (from http://sourceware.org/ml/ecos-discuss/2005-08/msg00015.html)
Yes.
> Where did you learn to use SIOCAIFADDR?
When I was writing a DHCPv6 implimentation, I had found some example
code somewhere that used SIOCAIFADDR_IN6. So, I grepped the stack
source for SIOCAIFADDR.
Below is the function I was using during my testing. The 's'
parameter is a UDP socket file descriptor.
void addInterfaceAddress4(int s, uint32_t ip4addr, uint32_t netmask)
{
struct in_aliasreq ifra;
struct sockaddr_in *addrp, *maskp;
memset(&ifra, 0, sizeof ifra);
strcpy(ifra.ifra_name, "eth0");
addrp = (struct sockaddr_in *) &ifra.ifra_addr;
memset(addrp, 0, sizeof(*addrp));
addrp->sin_family = AF_INET;
addrp->sin_len = sizeof(*addrp);
addrp->sin_port = 0;
maskp = (struct sockaddr_in *) &ifra.ifra_mask;
memset(maskp, 0, sizeof(*maskp));
maskp->sin_family = AF_INET;
maskp->sin_len = sizeof(*maskp);
maskp->sin_port = 0;
addrp->sin_addr.s_addr = htonl(ip4addr);
maskp->sin_addr.s_addr = htonl(netmask);
if (ioctl(s, SIOCAIFADDR, &ifra))
diag_printf("Error setting second 'eth0' IP address (SIOCAIFADDR): %s\n", strerror(errno));
}
I just noticed that the memset(addrp,...) and memset(maskp,...) calls
are redundant (not needed).
--
Grant Edwards grant.b.edwards Yow! ... My pants just went
at on a wild rampage through a
gmail.com Long Island Bowling Alley!!
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list