Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jun 2002 09:57:52 -0600
From:      John E Hein <jhein@timing.com>
To:        kevin@wooten.com
Cc:        hackers@FreeBSD.ORG
Subject:   Retrieving interface MAC address
Message-ID:  <15632.43520.992789.967232@brain.timing.com>
In-Reply-To: <15632.43255.450681.215587@brain.timing.com>
References:  <bulk.29178.20020619081331@hub.freebsd.org> <15632.43255.450681.215587@brain.timing.com>

next in thread | previous in thread | raw e-mail | index | archive | help
John E Hein wrote at 09:53 -0600 on Jun 19:
 > "Kevin D. Wooten" <kevin@wooten.com> wrote at 13:41:02 -0700 on 18 Jun 2002:
 >  > Thanks getifaddrs() works great, just one more thing is there a simple 
 >  > way to tell the difference between "real" interfaces and virtual ones? I 
 >  > could obviously exclude the easy ones ( i.e. lo, lp, faith, ... ) by 
 >  > looking at the name, but I am not sure how many different virtual 
 >  > interfaces there are ( or will be ).
 > 
 > This gets link interfaces and further checks for just ethernet types:
 > 
 > get_if_name(char if_name[IFNAMSIZ])
 > {
 >     struct ifaddrs   *ifaphead;
 > 
 >     if (getifaddrs(&ifaphead) != 0)
 >         perror("get_if_name: getifaddr() failed");
 >     else
 >     {
 >         bool              found = false;
 >         struct ifaddrs   *ifap;
 > 
 >         for (ifap = ifaphead; ifap && !found; ifap = ifap->ifa_next)
 >         {
 >             if ((ifap->ifa_addr->sa_family == AF_LINK)
 >                 && (((struct sockaddr_dl *) ifap->ifa_addr)->sdl_type ==
 >                     IFT_ETHER))
 >             {
 >                 found = true;
 >                 strlcpy(if_name, ifap->ifa_name, IFNAMSIZ);
 >                 printf("found ethernet if: %s\n", if_name);
 >             }
 >         }
 >         if (!found)
 >         {
 >             fprintf(stderr, "get_if_name: did not find ethernet if\n");
 >             strlcpy(if_name, "", IFNAMSIZ);
 >         }
 >     }
 > }

Minor correction... that just finds the first match (which was just
 what my app needed ;).

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?15632.43520.992789.967232>