summaryrefslogtreecommitdiff
path: root/usr.sbin/mrouted/inet.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-04-02 20:43:20 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-04-02 20:43:20 +0000
commitcc02109b2224e09e0afd52462b7cefdd21cba4df (patch)
tree559740096b3dd154645829255022935bfb4183a9 /usr.sbin/mrouted/inet.c
parent1229b08a41cb0455441509e3bc20934ee825f8ab (diff)
sprintf killing; millert ok
Diffstat (limited to 'usr.sbin/mrouted/inet.c')
-rw-r--r--usr.sbin/mrouted/inet.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/usr.sbin/mrouted/inet.c b/usr.sbin/mrouted/inet.c
index 2b11d43a1c5..eadbcfa9321 100644
--- a/usr.sbin/mrouted/inet.c
+++ b/usr.sbin/mrouted/inet.c
@@ -16,10 +16,11 @@
/*
* Exported variables.
*/
-char s1[19]; /* buffers to hold the string representations */
-char s2[19]; /* of IP addresses, to be passed to inet_fmt() */
-char s3[19]; /* or inet_fmts(). */
-char s4[19];
+#define SNAMLEN 19
+char s1[SNAMLEN]; /* buffers to hold the string representations */
+char s2[SNAMLEN]; /* of IP addresses, to be passed to inet_fmt() */
+char s3[SNAMLEN]; /* or inet_fmts(). */
+char s4[SNAMLEN];
/*
@@ -108,7 +109,7 @@ inet_fmt(u_int32_t addr, char *s)
register u_char *a;
a = (u_char *)&addr;
- sprintf(s, "%u.%u.%u.%u", a[0], a[1], a[2], a[3]);
+ snprintf(s, SNAMLEN, "%u.%u.%u.%u", a[0], a[1], a[2], a[3]);
return (s);
}
@@ -124,18 +125,21 @@ inet_fmts(u_int32_t addr, u_int32_t mask, char *s)
int bits;
if ((addr == 0) && (mask == 0)) {
- sprintf(s, "default");
+ snprintf(s, SNAMLEN, "default");
return (s);
}
a = (u_char *)&addr;
m = (u_char *)&mask;
bits = 33 - ffs(ntohl(mask));
- if (m[3] != 0) sprintf(s, "%u.%u.%u.%u/%d", a[0], a[1], a[2], a[3],
- bits);
- else if (m[2] != 0) sprintf(s, "%u.%u.%u/%d", a[0], a[1], a[2], bits);
- else if (m[1] != 0) sprintf(s, "%u.%u/%d", a[0], a[1], bits);
- else sprintf(s, "%u/%d", a[0], bits);
+ if (m[3] != 0)
+ snprintf(s, SNAMLEN, "%u.%u.%u.%u/%d", a[0], a[1], a[2], a[3], bits);
+ else if (m[2] != 0)
+ snprintf(s, SNAMLEN, "%u.%u.%u/%d", a[0], a[1], a[2], bits);
+ else if (m[1] != 0)
+ snprintf(s, SNAMLEN, "%u.%u/%d", a[0], a[1], bits);
+ else
+ snprintf(s, SNAMLEN, "%u/%d", a[0], bits);
return (s);
}