-/* $OpenBSD: sysctl.c,v 1.157 2008/04/28 11:52:53 norby Exp $ */
+/* $OpenBSD: sysctl.c,v 1.158 2008/07/09 20:20:46 djm Exp $ */
/* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */
/*
#if 0
static const char sccsid[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95";
#else
-static const char rcsid[] = "$OpenBSD: sysctl.c,v 1.157 2008/04/28 11:52:53 norby Exp $";
+static const char rcsid[] = "$OpenBSD: sysctl.c,v 1.158 2008/07/09 20:20:46 djm Exp $";
#endif
#endif /* not lint */
char names[BUFSIZ];
int lastused;
+/* Maximum size object to expect from sysctl(3) */
+#define SYSCTL_BUFSIZ 8192
+
struct list {
struct ctlname *list;
int size;
int64_t quadval;
struct list *lp;
int mib[CTL_MAXNAME];
- char *cp, *bufp, buf[BUFSIZ];
+ char *cp, *bufp, buf[SYSCTL_BUFSIZ];
(void)strlcpy(buf, string, sizeof(buf));
bufp = buf;
break;
}
}
- size = BUFSIZ;
+ size = SYSCTL_BUFSIZ;
if (sysctl(mib, len, buf, &size, newval, newsize) == -1) {
if (flags == 0)
return;
return;
}
if (special & BADDYNAMIC) {
- in_port_t port, lastport;
+ u_int port, lastport;
u_int32_t *baddynamic = (u_int32_t *)buf;
if (!qflag) {
(void)printf("%s%s", string,
newsize ? ": " : equ);
lastport = 0;
- for (port = IPPORT_RESERVED/2; port < IPPORT_RESERVED;
- port++)
+ for (port = 0; port < 65536; port++)
if (DP_ISSET(baddynamic, port)) {
- (void)printf("%s%hd",
+ (void)printf("%s%u",
lastport ? "," : "", port);
lastport = port;
}
fputs(" -> ", stdout);
baddynamic = (u_int32_t *)newval;
lastport = 0;
- for (port = IPPORT_RESERVED/2;
- port < IPPORT_RESERVED; port++)
+ for (port = 0; port < 65536; port++)
if (DP_ISSET(baddynamic, port)) {
- (void)printf("%s%hd",
+ (void)printf("%s%u",
lastport ? "," : "", port);
lastport = port;
}
in_port_t port;
size_t size;
char action, *cp;
+ const char *errstr;
if (strchr((char *)*newvalp, '+') || strchr((char *)*newvalp, '-')) {
size = sizeof(newbaddynamic);
if (*cp != '+' && *cp != '-')
errx(1, "cannot mix +/- with full list");
action = *cp++;
- port = atoi(cp);
- if (port < IPPORT_RESERVED/2 || port >= IPPORT_RESERVED)
- errx(1, "invalid port, range is %d to %d",
- IPPORT_RESERVED/2, IPPORT_RESERVED-1);
+ port = strtonum(cp, 0, 65535, &errstr);
+ if (errstr != NULL)
+ errx(1, "port is %s: %s", errstr, cp);
if (action == '+')
DP_SET(newbaddynamic, port);
else
} else {
(void)memset((void *)newbaddynamic, 0, sizeof(newbaddynamic));
while (*newvalp && (cp = strsep((char **)newvalp, ", \t")) && *cp) {
- port = atoi(cp);
- if (port < IPPORT_RESERVED/2 || port >= IPPORT_RESERVED)
- errx(1, "invalid port, range is %d to %d",
- IPPORT_RESERVED/2, IPPORT_RESERVED-1);
+ port = strtonum(cp, 0, 65535, &errstr);
+ if (errstr != NULL)
+ errx(1, "port is %s: %s", errstr, cp);
DP_SET(newbaddynamic, port);
}
}
sysctl_malloc(char *string, char **bufpp, int mib[], int flags, int *typep)
{
int indx, stor, i;
- char *name, bufp[BUFSIZ], *buf, *ptr;
+ char *name, bufp[SYSCTL_BUFSIZ], *buf, *ptr;
struct list lp;
size_t size;
mib[2] = indx;
if (mib[2] == KERN_MALLOC_BUCKET) {
if ((name = strsep(bufpp, ".")) == NULL) {
- size = BUFSIZ;
+ size = SYSCTL_BUFSIZ;
stor = mib[2];
mib[2] = KERN_MALLOC_BUCKETS;
buf = bufp;
*typep = CTLTYPE_STRING;
return (3);
} else if (mib[2] == KERN_MALLOC_KMEMSTATS) {
- size = BUFSIZ;
+ size = SYSCTL_BUFSIZ;
stor = mib[2];
mib[2] = KERN_MALLOC_KMEMNAMES;
buf = bufp;
size_t sdlen = sizeof(snsrdev);
if (*bufpp == NULL) {
- char buf[BUFSIZ];
+ char buf[SYSCTL_BUFSIZ];
/* scan all sensor devices */
for (dev = 0; dev < MAXSENSORDEVICES; dev++) {
void
print_sensordev(char *string, int mib[], u_int mlen, struct sensordev *snsrdev)
{
- char buf[BUFSIZ];
+ char buf[SYSCTL_BUFSIZ];
enum sensor_type type;
if (mlen == 3) {
-/* $OpenBSD: in_pcb.h,v 1.64 2008/07/03 15:46:24 henning Exp $ */
+/* $OpenBSD: in_pcb.h,v 1.65 2008/07/09 20:20:46 djm Exp $ */
/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */
/*
/* macros for handling bitmap of ports not to allocate dynamically */
#define DP_MAPBITS (sizeof(u_int32_t) * NBBY)
-#define DP_MAPSIZE (howmany(IPPORT_RESERVED/2, DP_MAPBITS))
-#define DP_SET(m, p) ((m)[((p) - IPPORT_RESERVED/2) / DP_MAPBITS] |= (1 << ((p) % DP_MAPBITS)))
-#define DP_CLR(m, p) ((m)[((p) - IPPORT_RESERVED/2) / DP_MAPBITS] &= ~(1 << ((p) % DP_MAPBITS)))
-#define DP_ISSET(m, p) ((m)[((p) - IPPORT_RESERVED/2) / DP_MAPBITS] & (1 << ((p) % DP_MAPBITS)))
+#define DP_MAPSIZE (howmany(65536, DP_MAPBITS))
+#define DP_SET(m, p) ((m)[(p) / DP_MAPBITS] |= (1 << ((p) % DP_MAPBITS)))
+#define DP_CLR(m, p) ((m)[(p) / DP_MAPBITS] &= ~(1 << ((p) % DP_MAPBITS)))
+#define DP_ISSET(m, p) ((m)[(p) / DP_MAPBITS] & (1 << ((p) % DP_MAPBITS)))
/* default values for baddynamicports [see ip_init()] */
-#define DEFBADDYNAMICPORTS_TCP { 587, 749, 750, 751, 871, 0 }
-#define DEFBADDYNAMICPORTS_UDP { 623, 664, 749, 750, 751, 0 }
+#define DEFBADDYNAMICPORTS_TCP { 587, 749, 750, 751, 871, 2049, 0 }
+#define DEFBADDYNAMICPORTS_UDP { 623, 664, 749, 750, 751, 2049, 0 }
struct baddynamicports {
u_int32_t tcp[DP_MAPSIZE];