From owner-freebsd-hackers Wed Jun 19 8:54: 1 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from Daffy.timing.com (daffy.timing.com [206.168.13.218]) by hub.freebsd.org (Postfix) with ESMTP id 8DB8837B40E for ; Wed, 19 Jun 2002 08:53:55 -0700 (PDT) Received: from brain.timing.com (brain.timing.com [206.168.13.195]) by Daffy.timing.com (8.11.3/8.11.3) with ESMTP id g5JFroK71110; Wed, 19 Jun 2002 09:53:50 -0600 (MDT) (envelope-from jhein@timing.com) Received: from brain.timing.com (localhost [127.0.0.1]) by brain.timing.com (8.12.2/8.12.2) with ESMTP id g5JFrocq076177; Wed, 19 Jun 2002 09:53:50 -0600 (MDT) (envelope-from jhein@brain.timing.com) Received: (from jhein@localhost) by brain.timing.com (8.12.2/8.12.2/Submit) id g5JFrRYb076172; Wed, 19 Jun 2002 09:53:27 -0600 (MDT) (envelope-from jhein) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15632.43255.450681.215587@brain.timing.com> Date: Wed, 19 Jun 2002 09:53:27 -0600 From: John E Hein To: kevin@wooten.com Cc: hackers@FreeBSD.ORG Subject: Retrieving interface MAC address In-Reply-To: References: X-Mailer: VM 7.03 under Emacs 21.1.1 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG "Kevin D. Wooten" 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); } } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message