[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replace history's "<remote>" with client's IP

From: Derek Price
Subject: Re: Replace history's "<remote>" with client's IP
Date: Tue, 18 Oct 2005 17:52:41 -0400
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Mark D. Baushke wrote:

>Adding that to the possibity of two decimal represenatations of a 16-bit
>port number means that there needs to be enough space in buf for 
>"xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd ddddd ddddd\0"
>which is 58 characters... allow a few extra for a nice round 64 number...

Why not just Xasprintf the value? I don't see a good reason for using a
fixed length buffer here.

Also, there is no reason to reimplement the code to make the addr into a
string. The POSIX getnameinfo() function already exists to turn a struct
sockaddr * into a printable IP address or FQDN, as you prefer, and it
should already handle both IPV4 & IPV6. I think that is about as current
as it gets and its sister, getaddrinfo() is already in GNULIB, so we
could probably get a reimplementation of getnameinfo() into GNULIB too.
Of course, then you'd have to stick with the fixed length buffer. :)

Reverse lookup could pretty easily be made into a config option like it
is for Apache, since it is slow.

>From the getnameinfo() man page:

In order to assist the programmer in choosing reasonable sizes for the
supplied buffers, <netdb.h> defines the constants
# define NI_MAXHOST 1025
# define NI_MAXSERV 32
The former is the constant MAXDNAME in recent versions of BIND’s
<arpa/nameser.h> header file. The latter is a guess based on the ser-
vices listed in the current Assigned Numbers RFC.

Of course, those numbers are only relevant if you need the port number
or want a reverse lookup on the IP when possible, and the constants are
not portable according to POSIX, but they'd be easy to provide
substitutes for when not defined.



Derek R. Price
CVS Solutions Architect
Ximbiot <http://ximbiot.com>
v: +1 717.579.6168
f: +1 717.234.3125

reply via email to

[Prev in Thread] Current Thread [Next in Thread]