From d039f38d0d117aa7a539cbc6c6b1fb592050eb12 Mon Sep 17 00:00:00 2001 From: brooks Date: Tue, 24 Sep 2002 17:35:08 +0000 Subject: 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 ": " 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. --- sys/net/if.c | 14 ++++++++++++++ sys/net/if_var.h | 1 + 2 files changed, 15 insertions(+) (limited to 'sys') diff --git a/sys/net/if.c b/sys/net/if.c index 25b8dc8..699278b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -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"); diff --git a/sys/net/if_var.h b/sys/net/if_var.h index bd9ebfd..a54ab5b 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -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); -- cgit v1.1