public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Grant Edwards <grant.b.edwards@gmail.com>
To: ecos-discuss@ecos.sourceware.org
Subject: [ECOS] Re: Does FreeBSD stack support multiple IP addresses?
Date: Tue, 15 Mar 2016 14:56:00 -0000	[thread overview]
Message-ID: <nc97qc$3a2$1@ger.gmane.org> (raw)
In-Reply-To: <56E7ED7F.6020205@televic.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

      reply	other threads:[~2016-03-15 14:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-19 16:35 [ECOS] " Grant Edwards
2016-02-19 18:12 ` [ECOS] " Grant Edwards
2016-02-22  8:50   ` Lambrecht Jürgen
2016-02-22 15:05     ` Grant Edwards
2016-02-23  8:09       ` Lambrecht Jürgen
2016-02-23 15:59         ` Grant Edwards
     [not found]           ` <DUB109-W90FA10A08EE609DF0BB91393A50@phx.gbl>
2016-02-24 16:47             ` Grant Edwards
2016-03-15 11:10           ` Lambrecht Jürgen
2016-03-15 14:56             ` Grant Edwards [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='nc97qc$3a2$1@ger.gmane.org' \
    --to=grant.b.edwards@gmail.com \
    --cc=ecos-discuss@ecos.sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).