![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| IP Networking Questions involving TCP/IP, Routers, Hubs, Network protocols, etc go here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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?
|
|
#5
|
|||
|
|||
|
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?
|
|
#6
|
|||
|
|||
|
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? |
|
#7
|
||||
|
||||
|
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>] |
||||
| Google The UNIX and Linux Forums |