Add a new helper function if_printf() modeled on device_printf(). The

function takes a struct ifnet pointer followed by the usual printf
arguments and prints "<interfacename>: " before the results of printf.
Since this is the primary form of printf calls in network device drivers
and accounts for most uses of the ifnet menber if_unit, this
significantly simplifies many printf()s.
This commit is contained in:
Brooks Davis 2002-09-24 17:35:08 +00:00
parent be6180cf89
commit fa882e87a5
2 changed files with 15 additions and 0 deletions

View File

@ -55,6 +55,7 @@
#include <sys/syslog.h>
#include <sys/sysctl.h>
#include <sys/jail.h>
#include <machine/stdarg.h>
#include <net/if.h>
#include <net/if_arp.h>
@ -1972,5 +1973,18 @@ ifmaof_ifpforaddr(sa, ifp)
return ifma;
}
int
if_printf(struct ifnet *ifp, const char * fmt, ...)
{
va_list ap;
int retval;
retval = printf("%s%d: ", ifp->if_name, ifp->if_unit);
va_start(ap, fmt);
retval += vprintf(fmt, ap);
va_end(ap);
return (retval);
}
SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers");
SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management");

View File

@ -422,6 +422,7 @@ void if_attach(struct ifnet *);
int if_delmulti(struct ifnet *, struct sockaddr *);
void if_detach(struct ifnet *);
void if_down(struct ifnet *);
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);
void if_unroute(struct ifnet *, int flag, int fam);