This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: Does FreeBSD stack support multiple IP addresses?
- From: Grant Edwards <grant dot b dot edwards at gmail dot com>
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Tue, 15 Mar 2016 14:56:12 +0000 (UTC)
- Subject: Re: Does FreeBSD stack support multiple IP addresses?
- Authentication-results: sourceware.org; auth=none
- References: <na7g8p$a83$1 at ger dot gmane dot org> <na7lte$o4d$1 at ger dot gmane dot org> <56CACBE1 dot 6040103 at televic dot com> <naf83u$plg$1 at ger dot gmane dot org> <56CC139C dot 4080601 at televic dot com> <nahvk4$pjt$1 at ger dot gmane dot org> <56E7ED7F dot 6020205 at televic dot com>
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