Require users to provide a length information for inet_ntoa_r,

this is common on other platforms.

Reported by:	pointyhat via kris
This commit is contained in:
Xin LI 2007-06-14 07:13:28 +00:00
parent a742982378
commit 0bb263df82
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=170715
3 changed files with 7 additions and 6 deletions

View File

@ -148,7 +148,7 @@ uint16_t ntohs(uint16_t);
in_addr_t inet_addr(const char *); in_addr_t inet_addr(const char *);
/*const*/ char *inet_ntoa(struct in_addr); /*const*/ char *inet_ntoa(struct in_addr);
char *inet_ntoa_r(struct in_addr, char *buf); char *inet_ntoa_r(struct in_addr, char *buf, socklen_t size);
const char *inet_ntop(int, const void * __restrict, char * __restrict, const char *inet_ntop(int, const void * __restrict, char * __restrict,
socklen_t); socklen_t);
int inet_pton(int, const char * __restrict, void * __restrict); int inet_pton(int, const char * __restrict, void * __restrict);

View File

@ -1,4 +1,4 @@
/* /*-
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
@ -60,9 +60,10 @@ inet_ntoa(struct in_addr in) {
} }
char * char *
inet_ntoa_r(struct in_addr in, char *buf) inet_ntoa_r(struct in_addr in, char *buf, socklen_t size)
{ {
(void) inet_ntop(AF_INET, &in, buf, sizeof("255.255.255.255"));
(void) inet_ntop(AF_INET, &in, buf, size);
return (buf); return (buf);
} }

View File

@ -28,7 +28,7 @@
.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 .\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd June 11, 2007 .Dd June 14, 2007
.Dt INET 3 .Dt INET 3
.Os .Os
.Sh NAME .Sh NAME
@ -62,6 +62,7 @@
.Fo inet_ntoa_r .Fo inet_ntoa_r
.Fa "struct in_addr in" .Fa "struct in_addr in"
.Fa "char *buf" .Fa "char *buf"
.Fa "socklen_t size"
.Fc .Fc
.Ft const char * .Ft const char *
.Fo inet_ntop .Fo inet_ntop
@ -156,7 +157,6 @@ The routine
.Fn inet_ntoa_r .Fn inet_ntoa_r
is the reentrant version of is the reentrant version of
.Fn inet_ntoa . .Fn inet_ntoa .
It requires a buffer large enough to contain an IPv4 address.
The routine The routine
.Fn inet_makeaddr .Fn inet_makeaddr
takes an Internet network number and a local takes an Internet network number and a local