[AGENT++] AGENTPP Digest, Vol 140, Issue 6

Jochen Katz katz at agentpp.com
Sun Oct 23 22:36:32 CEST 2016


Hi,

> snmpmsg.cpp:
> int unload( Pdu &pdu,                    // Pdu returned
> ->
> snmpmsg.cpp (L767):
>       IpAddress ipaddress(buffer);
> ->
> address.cpp:
> 
>    IpAddress::IpAddress(const char *inaddr)
> 
> (L261)    valid_flag = parse_address(inaddr);
> 
> (L854) error = getaddrinfo(inaddr, 0, &hints, &res);

ok, I did not think about this, as IpAddress is called with a numeric
address.

> // This statement get an error code as -9, which means:
> 
> # define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */
> 
> I guess this is caused by my local machine is configured to only use IPv6
> and the address I got is in IPv4 format.

Yes, this is the reason. And it will also fail the other way round:
parsing of IPv6 addresses on IPv4-only systems. So below is a patch that
moves the internal parsing functions for IPv4 and IPv6 to the top of
parse_address(). Maybe there is a better solution, but for the moment it
should work.

> In address.cpp, only when the macro "#ifdef HAVE_GETADDRINFO (L843)" is
> enabled can the statement "(L854) error = getaddrinfo(inaddr, 0, &hints,
> &res);" take effect. But I have no idea why this marco is enabled here.

If your system supports it, the configure script will set this define in
config.h, and Franks VS configuration also sets it in the included config.h.

> Otherwise, the address won't be parsed in this way.

This is the older parsing code. It was thought that the getaddrinfo()
function can do all-in-one and should have an optimized parsing code for
IP addresses.

Regards,
  Jochen


Index: src/address.cpp
===================================================================
--- src/address.cpp     (revision 3179)
+++ src/address.cpp     (working copy)
@@ -840,6 +840,20 @@

   addr_changed = true;

+  // initialize the friendly_name member variable
+  memset(iv_friendly_name, 0, sizeof(char) * MAX_FRIENDLY_NAME);
+  iv_friendly_name_status = 0;
+
+  // is this a dotted IP notation string or a friendly name
+  if (parse_dotted_ipstring(inaddr))
+  {
+    return true; // since this is a valid dotted string don't do any DNS
+  }
+  else if (parse_coloned_ipstring(inaddr))
+  {
+    return true; // since this is a valid ipv6 string don't do any DNS
+  }
+
 #ifdef HAVE_GETADDRINFO
   struct addrinfo hints, *res = 0;
   int error;
@@ -917,23 +931,6 @@

   char ds[61];

-  // intialize the friendly_name member variable
-  memset(iv_friendly_name, 0, sizeof(char) * MAX_FRIENDLY_NAME);
-  iv_friendly_name_status = 0;
-
-  // is this a dotted IP notation string or a friendly name
-  if (parse_dotted_ipstring(inaddr))
-  {
-    // since this is a valid dotted string don't do any DNS
-    return true;
-  }
-  else if (parse_coloned_ipstring(inaddr))
-  {
-    // since this is a valid ipv6 string don't do any DNS
-    return true;
-  }
-  else // not a dotted string, try to resolve it via DNS
-  {
 #if defined (CPU) && CPU == PPC603
   int lookupResult = hostGetByName(inaddr);

@@ -1065,7 +1062,7 @@
       return false;
     }
 #endif //PPC603
-  }  // end else not a dotted string
+
 #endif // HAVE_GETADDRINFO
   return true;
 }




More information about the AGENTPP mailing list