diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index ac56bc51f..beab9ec9a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +2005-06-17 Corinna Vinschen + + * cygwin.din (inet_pton): Export. + (inet_ntop): Export. + * net.cc (cygwin_inet_pton): Implement inet_pton for AF_INET for now. + (cygwin_inet_ntop): Implement inet_ntop for AF_INET for now. + * include/arpa/inet.h (inet_pton): Declare. + (inet_ntop): Declare. + * include/cygwin/version.h: Bump API minor number. + 2005-06-17 Corinna Vinschen * fhandler.h (fhandler_union): Add missing members corresponding to diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 22caf377b..22c991be4 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -324,8 +324,10 @@ herror = cygwin_herror SIGFE hstrerror = cygwin_hstrerror NOSIGFE inet_addr = cygwin_inet_addr SIGFE inet_aton = cygwin_inet_aton SIGFE +inet_pton = cygwin_inet_pton SIGFE inet_network = cygwin_inet_network SIGFE inet_ntoa = cygwin_inet_ntoa SIGFE +inet_ntop = cygwin_inet_ntop SIGFE cygwin_internal NOSIGFE cygwin32_internal = cygwin_internal NOSIGFE listen = cygwin_listen SIGFE diff --git a/winsup/cygwin/include/arpa/inet.h b/winsup/cygwin/include/arpa/inet.h index 284e98e40..f7db90021 100644 --- a/winsup/cygwin/include/arpa/inet.h +++ b/winsup/cygwin/include/arpa/inet.h @@ -26,6 +26,8 @@ struct in_addr inet_makeaddr (unsigned long , unsigned long); in_addr_t inet_netof (struct in_addr); in_addr_t inet_network (const char *); char *inet_ntoa (struct in_addr); +int inet_pton (int, const char *, void *); +const char *inet_ntop (int, const void *, char *, size_t); #endif #ifdef __cplusplus diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 3046c2104..88d95da0c 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -257,12 +257,13 @@ details. */ 128: Export pselect. 129: Export mkdtemp. 130: Export strtoimax, strtoumax, llabs, imaxabs, lldiv, imaxdiv. + 131: Export inet_ntop, inet_pton. */ /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 130 +#define CYGWIN_VERSION_API_MINOR 131 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 00951a49d..23989dd10 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -2259,3 +2259,49 @@ cygwin_sendmsg (int fd, const struct msghdr *msg, int flags) syscall_printf ("%d = sendmsg (%d, %p, %x)", res, fd, msg, flags); return res; } + +/* See "UNIX Network Programming, Networing APIs: Sockets and XTI", + W. Richard Stevens, Prentice Hall PTR, 1998. */ +extern "C" int +cygwin_inet_pton (int family, const char *strptr, void *addrptr) +{ + if (family == AF_INET) + { + struct in_addr in_val; + + if (cygwin_inet_aton (strptr, &in_val)) + { + memcpy (addrptr, &in_val, sizeof (struct in_addr)); + return 1; + } + return 0; + } + set_errno (EAFNOSUPPORT); + return -1; +} + +/* See "UNIX Network Programming, Networing APIs: Sockets and XTI", + W. Richard Stevens, Prentice Hall PTR, 1998. */ +extern "C" const char * +cygwin_inet_ntop (int family, const void *addrptr, char *strptr, size_t len) +{ + const u_char *p = (const u_char *) addrptr; + + if (__check_null_invalid_struct_errno (strptr, len)) + return NULL; + if (family == AF_INET) + { + char temp[64]; /* Big enough for 4 ints ... */ + + __small_sprintf (temp, "%u.%u.%u.%u", p[0], p[1], p[2], p[3]); + if (strlen (temp) >= len) + { + set_errno (ENOSPC); + return NULL; + } + strcpy (strptr, temp); + return strptr; + } + set_errno (EAFNOSUPPORT); + return NULL; +}