inet_pton() error. Does Cygwin support inet_pton()?

Fernando Barsoba fbarsoba@verizon.net
Fri Jun 17 17:38:00 GMT 2005


 Thanks for the code to René...! I'll try it right away..!

Thanks again,

Fernando




cygwin-help@cygwin.com wrote:


  If you don't need IPv6 in your application you can add tbe following 
implementation:

  #ifdef __CYGWIN__

  /* From:
  *  UNIX Network Programming: Sockets Introduction
  *  By Andrew M. Rudoff, Bill Fenner, W. Richard Stevens.
  *  Prentice Hall PTR. Feb 27, 2004.
  */
  #define INET_ADDRSTRLEN       16       /* for IPv4 dotted-decimal */

  int inet_pton(int family, const char *strptr, void *addrptr)
  {
     if (family == AF_INET) {
         struct in_addr in_val;

         if (inet_aton(strptr, &in_val)) {
             memcpy(addrptr, &in_val, sizeof(struct in_addr));
             return (1);
         }
         return (0);
     }
     errno = EAFNOSUPPORT;
     return (-1);
  }

  const char *inet_ntop(int family, const void *addrptr, char *strptr, 
size_t len)
  {
     const u_char *p = (const u_char *) addrptr;

     if (family == AF_INET) {
         char    temp[INET_ADDRSTRLEN];

         snprintf(temp, sizeof(temp), "%d.%d.%d.%d", p[0], p[1], p[2], 
p[3]);
         if (strlen(temp) >= len) {
             errno = ENOSPC;
             return (NULL);
         }
         strcpy(strptr, temp);
         return (strptr);
     }
     errno = EAFNOSUPPORT;
     return (NULL);
  }

  #endif


  I've used this and getaddrinfo() from the postgress port to compile 
clamsmtpd,
  and it works fine.

  HTH,





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list