This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: inet_pton() error. Does Cygwin support inet_pton()?
- From: René Berber <rberber at prodigy dot net dot mx>
- To: cygwin at cygwin dot com
- Date: Fri, 17 Jun 2005 09:35:59 -0500
- Subject: Re: inet_pton() error. Does Cygwin support inet_pton()?
- References: <00a401c572e8$90d2f250$0302a8c0@SERVER>
Fernando Barsoba wrote:
>
> I'm trying to use the function inet_pton(), but I found the following
> error when trying to build the application with Eclipse/CDT on Cygwin:
[snip]
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,
--
René Berber
--
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/