getaddrinfo() issue
Last Post 07 Feb 2013 06:44 AM by Chris Hird. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Chris Hird
Veteran Member
Veteran Member
Posts:2276

--
21 Jan 2013 10:40 AM

Hi

 

I have a slight issue with the API getaddrinfo(). I have used the following code to test the API.

 

#include 
#include 
#include 
#include 
#include 
#include                 /* CEE date functions */
#ifndef   NI_MAXHOST
#define   NI_MAXHOST 1025
#endif

int main(int argc,char **argv) {
int error;
int junkl;                        /* Int holder */
double secs;                      /* Secs holder */
char Time_Stamp[18];              /* Time Stamp holder */
unsigned char junk2[23];          /* Junk char string */
struct addrinfo *result;
struct addrinfo *res;

CEELOCT(&junkl, &secs,junk2,NULL);
CEEDATM(&secs,"YYYYMMDDHHMISS999",Time_Stamp,NULL);
printf("Start = %s\n",Time_Stamp);
/* resolve the domain name into a list of addresses */ 
error = getaddrinfo(argv[1], NULL, NULL, &result);
/* time now */
CEELOCT(&junkl, &secs,junk2,NULL);
CEEDATM(&secs,"YYYYMMDDHHMISS999",Time_Stamp,NULL);
printf("After getaddrinfo = %s\n",Time_Stamp); 
if(error != 0) {
   fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
   exit(EXIT_FAILURE);
   }
/* loop over all returned results and do inverse lookup */ 
for(res = result; res != NULL; res = res->ai_next) {
   char hostname[NI_MAXHOST] = "";
   error = getnameinfo(res->ai_addr,
                       res->ai_addrlen,
                       hostname,
                       NI_MAXHOST,
                       NULL,
                       0,
                       0);
   if(error != 0) {
      fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
      }
   if(*hostname != '\0')
      printf("hostname: %s\n", hostname);
   CEELOCT(&junkl, &secs,junk2,NULL);
   CEEDATM(&secs,"YYYYMMDDHHMISS999",Time_Stamp,NULL);
   printf("After getnameinfo = %s\n",Time_Stamp);
   }
freeaddrinfo(result);
return 0;
}   
I have a system which I removed the Domain information from (CHGTCPDMN) so it is set to blanks. I did this after finding the problem with the Domain Information set with very slow responses from the API. I have another system which has the Domain Information still set which I used as a comparison check.

 First test was run on the system with the Domain information set. This has the HOSTNAME set to ‘SHIELD3’ and DMNNAME set to ‘SHIELD.LOCAL’ In all cases the HOSTNAME is set in the HOSTS file.

 The test called the program in the following format call chlib/tstaddrinf ‘shield3’.

 Here is the output.

[quote]

Start = 20130121122025252             

After getaddrinfo = 20130121122033419 

hostname: SHIELD3.SHIELD.LOCAL        

After getnameinfo = 20130121122033420 

[/quote] So as you can see it is taking 8 seconds to resolve the name.

The next test was run on the system with the Domain Information set to BLANK. But the HOST table does have ‘SHIELD4’ in the list.

 This is the format of the request  call chlib/tstaddrinf ‘shield4’.

 [quote]

Start = 20130121122427999            

After getaddrinfo = 20130121122428002

hostname: SHIELD4                     

After getnameinfo = 20130121122428002

 [/quote]

So as you can see the response was sub second!

Then I looked to see if other requests which are also in the HOST Table would respond as quickly.

 Format of the request call chlib/tstaddrinf 'www4.ha4i.shield.local'.

 Here is the output.

 [quote]

Start = 20130121122647896           

After getaddrinfo = 20130121122656112

hostname: SHIELD4                   

After getnameinfo = 20130121122656112

 [/quote]

As you can see it is not taking 8 seconds to resolve the name!

I came across this problem when using another product so I have never used this API before, but I have read through the manuals to determine why and it offers no solution??  Does anyone here know why this would be happening and if it is working as designed? The Wiki description of the standard implementation also offers no advice as to why it should take so long to resolve the name when the Domain Information is set.

Any help would be gratefully received.

Chris..

 

Chris Hird Shield Advanced Solutions Ltd Home of JQG4i, HA4i and DR4i. http://www.shieldadvanced.com
Chris Hird
Veteran Member
Veteran Member
Posts:2276

--
21 Jan 2013 10:42 AM
This formatter still sucks! No wonder its getting less and less people using it! if anyone needs to know more let me know!
Chris Hird Shield Advanced Solutions Ltd Home of JQG4i, HA4i and DR4i. http://www.shieldadvanced.com
Chris Hird
Veteran Member
Veteran Member
Posts:2276

--
07 Feb 2013 06:44 AM
OK

This is a known issue when you move to V6R1 and above. The solution requires the getaddrinfo() API to be coded to fall back to IPV4 addresses if the IPV6 addresses are not configured. Otherwise when the IPV6 request comes back with no match it will automatically go out to the DNS for name resolution which is where the 8 second delay is coming from.

Chris...
Chris Hird Shield Advanced Solutions Ltd Home of JQG4i, HA4i and DR4i. http://www.shieldadvanced.com
You are not authorized to post a reply.

Acceptable Use Policy