summary refs log tree commit diff
path: root/manual/socket.texi
diff options
context:
space:
mode:
Diffstat (limited to 'manual/socket.texi')
-rw-r--r--manual/socket.texi45
1 files changed, 37 insertions, 8 deletions
diff --git a/manual/socket.texi b/manual/socket.texi
index b9102c62e1..d77e556214 100644
--- a/manual/socket.texi
+++ b/manual/socket.texi
@@ -1284,13 +1284,42 @@ pointer and the size of the buffer in the @var{buf} and @var{buflen}
 parameters.
 
 A pointer to the buffer, in which the result is stored, is available in
-@code{*@var{result}} after the function call successfully returned.
-Success is signalled by a zero return value.  If the function failed the
-return value is an error number.  In addition to the errors defined for
-@code{gethostbyname} it can also be @code{ERANGE}.  In this case the
-call should be repeated with a larger buffer.  Additional error
-information is not stored in the global variable @code{h_errno} but
-instead in the object pointed to by @var{h_errnop}.
+@code{*@var{result}} after the function call successfully returned.  If
+an error occurs or if no entry is found, the pointer @code{*var{result}
+is a null pointer.  Success is signalled by a zero return value.  If the
+function failed the return value is an error number.  In addition to the
+errors defined for @code{gethostbyname} it can also be @code{ERANGE}.
+In this case the call should be repeated with a larger buffer.
+Additional error information is not stored in the global variable
+@code{h_errno} but instead in the object pointed to by @var{h_errnop}.
+
+Here's a small example:
+@smallexample
+struct hostent *
+gethostname (char *host)
+@{
+  struct hostent hostbuf, *hp;
+  size_t hstbuflen;
+  char *tmphstbuf;
+  int res;
+  int herr;
+
+  hstbuflen = 1024;
+  tmphstbuf = malloc (hstbuflen);
+
+  while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
+                                 &hp, &herr)) == ERANGE)
+    @{
+      /* Enlarge the buffer.  */
+      hstbuflen *= 2;
+      tmphstbuf = realloc (tmphstbuf, hstbuflen);
+    @}
+  /*  Check for errors.  */
+  if (res || hp == NULL)
+    return NULL;
+  return hp->h_name;
+@}
+@end smallexample
 @end deftypefun
 
 @comment netdb.h
@@ -1314,7 +1343,7 @@ Internet address, use @code{AF_INET6}.
 
 Similar to the @code{gethostbyname_r} function, the caller must provide
 buffers for the result and memory used internally.  In case of success
-the funciton returns zero.  Otherwise the value is an error number where
+the function returns zero.  Otherwise the value is an error number where
 @code{ERANGE} has the special meaning that the caller-provided buffer is
 too small.
 @end deftypefun