$NetBSD$
--- bgpctl/bgpctl.c.orig	2006-01-24 17:28:03.000000000 +0200
+++ bgpctl/bgpctl.c	2007-05-07 21:54:21.000000000 +0300
@@ -20,7 +20,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <net/if.h>
-#include <net/if_media.h>
+#include "if_media.h"
 #include <net/if_types.h>
 
 #include <err.h>
@@ -29,7 +29,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 #include <util.h>
+#else /* defined(__FreeBSD__) || defined(__DragonFly__) */
+#include <libutil.h>
+#endif
 
 #include "bgpd.h"
 #include "session.h"
@@ -42,7 +46,7 @@
 	NV_TIMERS
 };
 
-__dead void	 usage(void);
+ void	 usage(void);
 int		 main(int, char *[]);
 char		*fmt_peer(const struct peer_config *, int);
 void		 show_summary_head(void);
@@ -82,7 +86,7 @@
 
 struct imsgbuf	*ibuf;
 
-__dead void
+ void
 usage(void)
 {
 	extern char	*__progname;
@@ -395,7 +399,7 @@
 		s = fmt_peer(&p->conf, nodescr);
 		if (strlen(s) >= 20)
 			s[20] = 0;
-		printf("%-20s %5u %10llu %10llu %5u %-8s ",
+		printf("%-20s %d %" PRIu64 " %" PRIu64 " %d  %-8s ",
 		    s, p->conf.remote_as,
 		    p->stats.msg_rcvd_open + p->stats.msg_rcvd_notification +
 		    p->stats.msg_rcvd_update + p->stats.msg_rcvd_keepalive +
@@ -582,17 +586,17 @@
 {
 	printf("  Message statistics:\n");
 	printf("  %-15s %-10s %-10s\n", "", "Sent", "Received");
-	printf("  %-15s %10llu %10llu\n", "Opens",
+	printf("  %-15s %" PRIu64 " %" PRIu64 "\n", "Opens",
 	    p->stats.msg_sent_open, p->stats.msg_rcvd_open);
-	printf("  %-15s %10llu %10llu\n", "Notifications",
+	printf("  %-15s %" PRIu64 " %" PRIu64 "\n", "Notifications",
 	    p->stats.msg_sent_notification, p->stats.msg_rcvd_notification);
-	printf("  %-15s %10llu %10llu\n", "Updates",
+	printf("  %-15s %" PRIu64 " %" PRIu64 "\n", "Updates",
 	    p->stats.msg_sent_update, p->stats.msg_rcvd_update);
-	printf("  %-15s %10llu %10llu\n", "Keepalives",
+	printf("  %-15s %" PRIu64 " %" PRIu64 "\n", "Keepalives",
 	    p->stats.msg_sent_keepalive, p->stats.msg_rcvd_keepalive);
-	printf("  %-15s %10llu %10llu\n", "Route Refresh",
+	printf("  %-15s %" PRIu64 " %" PRIu64 "\n", "Route Refresh",
 	    p->stats.msg_sent_rrefresh, p->stats.msg_rcvd_rrefresh);
-	printf("  %-15s %10llu %10llu\n", "Total",
+	printf("  %-15s %" PRIu64 " %" PRIu64 "\n", "Total",
 	    p->stats.msg_sent_open + p->stats.msg_sent_notification +
 	    p->stats.msg_sent_update + p->stats.msg_sent_keepalive +
 	    p->stats.msg_sent_rrefresh,
@@ -1032,8 +1036,12 @@
 {
 	static char	buf[16];
 
+#if defined(__OpenBSD__)
 	if (fmt_scaled(num, buf) == -1)
-		snprintf(buf, sizeof(buf), "%lldB", num);
+#else /* defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) */
+	if (humanize_number(buf, 16, num, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL) == -1)
+#endif
+		snprintf(buf, sizeof(buf), "%" PRId64 "B", num);
 
 	return (buf);
 }
@@ -1047,28 +1055,28 @@
 	case IMSG_CTL_SHOW_RIB_MEM:
 		memcpy(&stats, imsg->data, sizeof(stats));
 		printf("RDE memory statistics\n");
-		printf("%10lld IPv4 network entries using %s of memory\n",
+		printf("%" PRId64 " IPv4 network entries using %s of memory\n",
 		    stats.pt4_cnt, fmt_mem(stats.pt4_cnt *
 		    sizeof(struct pt_entry4)));
 		if (stats.pt6_cnt != 0)
-			printf("%10lld IPv6 network entries using "
+			printf("%" PRId64 " IPv6 network entries using "
 			    "%s of memory\n", stats.pt6_cnt,
 			    fmt_mem(stats.pt6_cnt * sizeof(struct pt_entry6)));
-		printf("%10lld prefix entries using %s of memory\n",
+		printf("%" PRId64 " prefix entries using %s of memory\n",
 		    stats.prefix_cnt, fmt_mem(stats.prefix_cnt *
 		    sizeof(struct prefix)));
-		printf("%10lld BGP path attribute entries using %s of memory\n",
+		printf("%" PRId64 " BGP path attribute entries using %s of memory\n",
 		    stats.path_cnt, fmt_mem(stats.path_cnt *
 		    sizeof(struct rde_aspath)));
-		printf("%10lld BGP AS-PATH attribute entries using "
-		    "%s of memory,\n\t   and holding %lld references\n",
+		printf("%" PRId64 " BGP AS-PATH attribute entries using "
+		    "%s of memory,\n\t   and holding %" PRId64 " references\n",
 		    stats.aspath_cnt, fmt_mem(stats.aspath_size),
 		    stats.aspath_refs);
-		printf("%10lld BGP attributes entries using %s of memory\n",
+		printf("%" PRId64 " BGP attributes entries using %s of memory\n",
 		    stats.attr_cnt, fmt_mem(stats.attr_cnt *
 		    sizeof(struct attr)));
-		printf("\t   and holding %lld references\n", stats.attr_refs);
-		printf("%10lld BGP attributes using %s of memory\n",
+		printf("\t   and holding %" PRId64 " references\n", stats.attr_refs);
+		printf("%" PRId64 " BGP attributes using %s of memory\n",
 		    stats.attr_dcnt, fmt_mem(stats.attr_data));
 		printf("RIB using %s of memory\n", fmt_mem(
 		    stats.pt4_cnt * sizeof(struct pt_entry4) +
