Re: Re: POSIX 1003.1-2001 gethostname(2)
| From: | Ilia Alshanetsky | Date: | Tue, 30 Dec 2008 15:09:57 +0000 |
| Subject: | Re: Re: POSIX 1003.1-2001 gethostname(2) | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42408@lists.php.net to get a copy of this message | ||
The gethostname() is a POSIX function and therefor should be available on windows as well as any other posix complaint system. The php_uname() function uses a radically different code between Win32 and Linux and therefor is not guaranteed to return the same equivalents, if win32 supports (which it should) the gethostname() function, the return values across all oses will be consistent.
The 4k buffer is used for safety and if the size is not sufficient the function will return an error.
On 29-Dec-08, at 11:54 PM, M. Karpelès wrote:
Isn't this whole function the same as calling php_uname('n') ? According to gethostname()'s manpage on Linux: The GNU C library implements gethostname() as a library function that calls uname(2) and copies up to len bytes from the returned nodename field into name. php_uname('n') is already implementing this, so why adding gethostname() ? (also I belive php_uname() works on windows, dunno if the hostname option works). A final note about using HOST_NAME_MAX if we still want to add gethostname(), according to BSD manpages: The gethostname() function conforms to IEEE Std 1003.1-2001 (``POSIX.1''). Callers should be aware that {HOST_NAME_MAX} may be variable or infinite, but is guaranteed to be no less than {_POSIX_HOST_NAME_MAX}. On older systems, this limit was defined in the non-standard header <sys/param.h> as MAXHOSTNAMELEN, and counted the terminating null. The sethostname() function and the error returns for gethostname() are not standardized. Allocating a buffer of size "infinite" in the stack looks like a bad idea. Anyway a machine with an hostname over 4kB is really unlikely. It also won't work if the value is variable (or we would have to allocate this on the heap with emalloc). Mark Le lundi 29 décembre 2008 à 23:51 -0300, Cristian Rodríguez a écrit :Ilia AlshanetskyIlia Alshanetsky escribió:--PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php+ char buf[4096];Shouldnt that be char buf[HOST_NAME_MAX + 1] ?