This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
Re: gethostbyname() problem?
- From: Yitzchak Scott-Thoennes <sthoenna at efn dot org>
- To: cygwin-patches at cygwin dot com
- Date: Sun, 6 Feb 2005 15:01:29 -0800
- Subject: Re: gethostbyname() problem?
- Organization: bs"d
- References: <200502051240.j15CevQ32345@webmail.web-mania.com> <4205D6D1.70D38D40@dessent.net> <20050206110530.GR19096@cygbert.vinschen.de>
On Sun, Feb 06, 2005 at 12:05:30PM +0100, Corinna Vinschen wrote:
> On Feb 6 00:35, Brian Dessent wrote:
> > - static int a, b, c, d;
> > + static int a, b, c, d, n;
> >
> > sig_dispatch_pending ();
> > if (check_null_str_errno (name))
> > return NULL;
> >
> > - if (sscanf (name, "%d.%d.%d.%d", &a, &b, &c, &d) == 4)
> > + if (sscanf (name, "%d.%d.%d.%d%n", &a, &b, &c, &d, &n) == 4 && (unsigned)n == strlen (name))
>
> Thanks for the patch, Brian. Do you also have a nice ChangeLog entry
> for me?
I've always done this like below; then the n==strlen(name) check isn't
needed (since the ==4 verifies that %c wasn't used). Even using the
%n, there's no reason to make n static, is there?
2005-02-06 Yitzchak Scott-Thoennes <sthoenna@efn.org>
* net.cc (cygwin_gethostbyname): Treat as hostname even if
beginning with "%d.%d.%d.%d"
--- winsup/cygwin/net.cc.orig 2004-04-11 10:41:17.000000000 -0700
+++ winsup/cygwin/net.cc 2005-02-06 13:49:42.783942400 -0800
@@ -997,12 +997,13 @@ cygwin_gethostbyname (const char *name)
static char *tmp_aliases[1];
static char *tmp_addr_list[2];
static int a, b, c, d;
+ char dummy;
sig_dispatch_pending ();
if (check_null_str_errno (name))
return NULL;
- if (sscanf (name, "%d.%d.%d.%d", &a, &b, &c, &d) == 4)
+ if (sscanf (name, "%d.%d.%d.%d%c", &a, &b, &c, &d, &dummy) == 4)
{
/* In case you don't have DNS, at least x.x.x.x still works */
memset (&tmp, 0, sizeof (tmp));