The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
Google UNIX.COM


IP Networking Questions involving TCP/IP, Routers, Hubs, Network protocols, etc go here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
dash after ampersant csecnarf UNIX for Dummies Questions & Answers 2 03-12-2008 12:47 PM
Spicebird: Thunderbird, Lightning, and a dash of collaborative flavor iBot UNIX and Linux RSS News 0 03-07-2008 09:30 AM
Solaris - unknown hostname - how can I change hostname? XNOR UNIX for Dummies Questions & Answers 1 03-29-2007 07:52 PM
double-dash options dhinge Shell Programming and Scripting 1 01-10-2007 07:32 PM
How to remove a file with a leading dash '-' in it's name? GSalisbury UNIX for Advanced & Expert Users 3 05-05-2003 08:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-15-2008
Registered User
 

Join Date: May 2008
Posts: 10
gethostbyname_r returns NULL when hostname has dash

We have a code to find the DNS entry of a host that has a trailing '-' in its url (format example: mysite-.watch.com):

if(gethostbyname_r(host,host_ent,host_buffer,host_buffer_size,&host_error)==NULL)
{
//failed
}

But when remove the '-' from the host name the code does not return failure. IE and nslookup works fine.

What we need to do in such a case?

Last edited by uunniixx; 05-15-2008 at 06:20 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 05-21-2008
Registered User
 

Join Date: May 2008
Posts: 10
Below are my personal findings:


Example 1:

> host nyustern-.collegemailer.com
nyustern-.collegemailer.com has address 209.200.118.155

> host nyustern.collegemailer.com
nyustern.collegemailer.com has address 209.200.118.155

Example 2:

> nslookup nyustern-.collegemailer.com
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: xx.xxx.xx.xxx
Address: xx.xxx.xx.xxx#xx

Non-authoritative answer:
Name: nyustern-.collegemailer.com
Address: 209.200.118.155

> nslookup nyustern.collegemailer.com
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: xx.xxx.xx.xxx
Address: xx.xxx.xx.xxx#xx

Non-authoritative answer:
Name: nyustern.collegemailer.com
Address: 209.200.118.155


Eample 3:

This code uses gethostbyname_r method to determine the address:-

> a.out nyuster-n.collegemailer.com
addresses: 209.200.118.155
> a.out ny-uster-n.collegemailer.com
addresses: 209.200.118.155
> a.out ny-uster-n-.collegemailer.com
unknown host `ny-uster-n-.collegemailer.com'
> a.out ny---uster-n.collegemailer.com
addresses: 209.200.118.155
> a.out nyustern.collegemailer.com
addresses: 209.200.118.155
>

I am unsure whether '-' in hostname ignored or does not has a functionality. In such a case having a trailing '-' is just a corner off case.

Last edited by uunniixx; 05-25-2008 at 02:16 PM.
Reply With Quote
  #3  
Old 05-21-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Looks like that particular domain is running some funky resolver which resolves almost anything. I'd guess their resolver is configured to resolve everything, but has a bug.

Code:
vnix$ host fnordityfnord.collegemailer.com
fnordityfnord.collegemailer.com has address 209.200.118.155
vnix$ host thisabsurdhostnamecouldnotpossiblyexist.collegemailer.com
thisabsurdhostnamecouldnotpossiblyexist.collegemailer.com has address 209.200.118.155
vnix$ host '!*?'.collegemailer.com
!*?.collegemailer.com has address 209.200.118.155
Punycode - Wikipedia, the free encyclopedia has some special cases relating to hyphens in host names.
Reply With Quote
  #4  
Old 05-21-2008
Registered User
 

Join Date: May 2008
Posts: 10
I am quiet unsure now of what extra we need to code here. Is there any library we need to include? How can we resolve this issue?
Reply With Quote
  #5  
Old 05-21-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
What does h_errno say when you get the failure? The man page seems to suggest to use getnameinfo() instead, have you tried that? My version of gethostbyname_r returns an int, do you have a different implementation?
Reply With Quote
  #6  
Old 05-23-2008
Registered User
 

Join Date: May 2008
Posts: 10
I did a sample code:

Code:

#include <netdb.h>
#include <stdio.h>
#include <alloca.h>

int
main (void)
{
struct hostent hostbuf, *hp;
size_t hstbuflen;
char *tmphstbuf;
int res;
int herr;

hstbuflen = 1024;
tmphstbuf = (char *)alloca (hstbuflen);

res = gethostbyname_r ("nyustern-.collegemailer.com", &hostbuf, tmphstbuf, hstbuflen, &hp, &herr);
herror("Error");
printf("Hsterror [%s]\n" , hstrerror (h_errno ));

printf ("gethostbyname_r returned: %d\n", res);
printf ("herr: %d\n", herr);
printf ("hp is %s\n", hp == NULL ? "null" : "set");
}

Output:

cc test_host.cpp && a.out

Error: Unknown host
Hsterror [Unknown host]
gethostbyname_r returned: 0
herr: 3
hp is null


The getnameinfo() function takes a socket address as input and returns the corresponding node name and service location.
Can you be more specific regards to my requirement?
Reply With Quote
  #7  
Old 05-23-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
This appears to be illegal according to rfc 952.
RFC 952 (rfc952) - DoD Internet host table specification

Code:
<name>  ::= <let>[*[<let-or-digit-or-hyphen>]<let-or-digit>]
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0