From owner-freebsd-hackers Wed Jun 19 8:57:59 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 C891B37B404 for ; Wed, 19 Jun 2002 08:57:54 -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 g5JFvrK71136; Wed, 19 Jun 2002 09:57:53 -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 g5JFvrcq076195; Wed, 19 Jun 2002 09:57:53 -0600 (MDT) (envelope-from jhein@brain.timing.com) Received: (from jhein@localhost) by brain.timing.com (8.12.2/8.12.2/Submit) id g5JFvraY076192; Wed, 19 Jun 2002 09:57:53 -0600 (MDT) (envelope-from jhein) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15632.43520.992789.967232@brain.timing.com> Date: Wed, 19 Jun 2002 09:57:52 -0600 From: John E Hein To: kevin@wooten.com Cc: hackers@FreeBSD.ORG Subject: Retrieving interface MAC address In-Reply-To: <15632.43255.450681.215587@brain.timing.com> References: <15632.43255.450681.215587@brain.timing.com> 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 John E Hein wrote at 09:53 -0600 on Jun 19: > "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); > } > } > } 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