Allow the folders in the About Wireshark/Folders list to be double clicked on to...
[obnox/wireshark/wip.git] / inet_ntop.c
index ff80e4e1f86bf14b9f84764284d3b69a93d3a941..19173877c920369a0c8e81f7af036aaf16615421 100644 (file)
  * SOFTWARE.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$Id: inet_ntop.c,v 1.2 1999/10/14 06:55:08 guy Exp $";
+static char rcsid[] = "$Id$";
 #endif /* LIBC_SCCS and not lint */
 
-#include "config.h"
-
+#ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
-#include <sys/socket.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>                /* needed to define AF_ values on UNIX */
+#endif
 
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>          /* needed to define AF_ values on Windows */
+#define EAFNOSUPPORT    WSAEAFNOSUPPORT
+#endif
+
+#ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
+#endif
+
+#ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
+#endif
+
+#ifdef HAVE_ARPA_NAMESER_H
 #include <arpa/nameser.h>
+#endif
 
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 
-#ifdef NEED_SNPRINTF_H
-# ifdef HAVE_STDARG_H
-#  include <stdarg.h>
-# else
-#  include <varargs.h>
-# endif
-# include "snprintf.h"
-#endif
-
 #include "inet_v6defs.h"
 
+#include <glib.h>
+
 #ifndef NS_INADDRSZ
 #define NS_INADDRSZ    4
 #endif
@@ -108,8 +124,12 @@ inet_ntop4(src, dst, size)
 {
        static const char fmt[] = "%u.%u.%u.%u";
        char tmp[sizeof "255.255.255.255"];
+       int nprinted;
 
-       if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]) > size) {
+       nprinted = g_snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
+       if (nprinted < 0)
+               return (NULL);  /* we assume "errno" was set by "g_snprintf()" */
+       if ((size_t)nprinted > size) {
                errno = ENOSPC;
                return (NULL);
        }
@@ -195,10 +215,10 @@ inet_ntop6(src, dst, size)
                        tp += strlen(tp);
                        break;
                }
-               tp += sprintf(tp, "%x", words[i]);
+               tp += g_snprintf(tp, sizeof tmp - (tp - tmp), "%x", words[i]);
        }
        /* Was it a trailing run of 0x00's? */
-       if (best.base != -1 && (best.base + best.len) == 
+       if (best.base != -1 && (best.base + best.len) ==
            (NS_IN6ADDRSZ / NS_INT16SZ))
                *tp++ = ':';
        *tp++ = '\0';