From 89ee0bfdcdc7c119bc08f5b434d3d99556b56bcd Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 16 Jun 2007 19:59:30 +0000 Subject: [PATCH] Implement an opaque function, if_getanyethermac(), which retrieves MAC information from the first real hardware interface for use by the uuidgen code. --- sys/net/if.c | 27 ++++++++++++++++++++++++++- sys/net/if_var.h | 3 ++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 874896271b..a5d04fb4ad 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -32,7 +32,7 @@ * * @(#)if.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ - * $DragonFly: src/sys/net/if.c,v 1.51 2007/05/13 18:33:58 swildner Exp $ + * $DragonFly: src/sys/net/if.c,v 1.52 2007/06/16 19:59:30 dillon Exp $ */ #include "opt_compat.h" @@ -1854,6 +1854,31 @@ ifmaof_ifpforaddr(struct sockaddr *sa, struct ifnet *ifp) } /* + * This function locates the first real ethernet MAC from a network + * card and loads it into node, returning 0 on success or ENOENT if + * no suitable interfaces were found. It is used by the uuid code to + * generate a unique 6-byte number. + */ +int +if_getanyethermac(uint16_t *node, int minlen) +{ + struct ifnet *ifp; + struct sockaddr_dl *sdl; + + TAILQ_FOREACH(ifp, &ifnet, if_link) { + if (ifp->if_type != IFT_ETHER) + continue; + sdl = IF_LLSOCKADDR(ifp); + if (sdl->sdl_alen < minlen) + continue; + bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, node, + minlen); + return(0); + } + return (ENOENT); +} + +/* * The name argument must be a pointer to storage which will last as * long as the interface does. For physical devices, the result of * device_get_name(dev) is a good choice and for pseudo-devices a diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 8dc1e40d5d..821c5b1071 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -32,7 +32,7 @@ * * From: @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if_var.h,v 1.37 2007/03/24 05:57:49 sephe Exp $ + * $DragonFly: src/sys/net/if_var.h,v 1.38 2007/06/16 19:59:30 dillon Exp $ */ #ifndef _NET_IF_VAR_H_ @@ -465,6 +465,7 @@ void if_detach(struct ifnet *); void if_down(struct ifnet *); void if_link_state_change(struct ifnet *); void if_initname(struct ifnet *, const char *, int); +int if_getanyethermac(uint16_t *, int); int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3); void if_route(struct ifnet *, int flag, int fam); int if_setlladdr(struct ifnet *, const u_char *, int); -- 2.11.4.GIT