This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Net - getaddrinfo() uses DNS


Index: net/common/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/common/current/ChangeLog,v
retrieving revision 1.21
diff -u -5 -p -b -r1.21 ChangeLog
--- net/common/current/ChangeLog	25 Feb 2003 14:43:42 -0000	1.21
+++ net/common/current/ChangeLog	5 Mar 2003 21:00:15 -0000
@@ -1,5 +1,10 @@
+2003-03-05  Gary Thomas  <gary at mlbassoc dot com>
+
+	* src/getaddrinfo.c: Allow getaddrinfo() to use DNS gethostbyXXX()
+	routines if DNS is present.  Also, eliminate some debug messages.
+
 2003-02-25  Andrew Lunn  <andrew dot lunn at ascom dot ch>
 
 	* src/getserv.c: Added a servent structure for SNTP.
 
 2003-02-24  Jonathan Larmour  <jifl at eCosCentric dot com>
Index: net/common/current/src/getaddrinfo.c
===================================================================
RCS file: /misc/cvsfiles/ecos-opt/net/net/common/current/src/getaddrinfo.c,v
retrieving revision 1.1
diff -u -5 -p -b -r1.1 getaddrinfo.c
--- net/common/current/src/getaddrinfo.c	20 May 2002 22:25:05 -0000	1.1
+++ net/common/current/src/getaddrinfo.c	5 Mar 2003 21:00:35 -0000
@@ -30,10 +30,11 @@
 
 #include <sys/param.h>
 #include <sys/socket.h>           // PF_xxx
 #include <netinet/in.h>           // IPPROTO_xx
 #include <net/netdb.h>
+#include <netdb.h>                // DNS support routines
 #include <errno.h>
 #include <cyg/infra/cyg_ass.h>
 
 extern int  sprintf(char *, const char *, ...);
 extern long strtol(const char *, char **, int);
@@ -44,19 +45,20 @@ extern void free(void *);
 // This routine is the real meat of the host->address translation
 static int
 _getaddr(struct addrinfo *ai, const char *node, 
          const struct addrinfo *hints, int family, int port)
 {
+    struct hostent *_hent;
+
     switch (family) {
     case AF_INET:
     {
         struct sockaddr_in *sa;
         sa = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
         ai->ai_addr = (struct sockaddr *)sa;
         ai->ai_addrlen = sizeof(*sa);
         if (ai->ai_addr == (struct sockaddr *)NULL) {
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
             return EAI_MEMORY;
         }
         sa->sin_family = AF_INET;
         sa->sin_len = sizeof(*sa);
         sa->sin_port = htons(port);
@@ -65,27 +67,30 @@ _getaddr(struct addrinfo *ai, const char
                 sa->sin_addr.s_addr = htonl(INADDR_ANY);
             } else {
                 sa->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
             }
         } else {
+            _hent = gethostbyname(node);
+            if (_hent) {
+                memcpy(&sa->sin_addr.s_addr, _hent->h_addr, sizeof(struct in_addr));
+            } else {
             // For now, only numeric "presentation" addresses supported
             if (!inet_pton(AF_INET, (char *)node, (char *)&sa->sin_addr.s_addr)) {
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
                 return EAI_FAIL;  // Couldn't resolve name
             }
         }
     }
+    }
     break;
 #ifdef CYGPKG_NET_INET6
     case AF_INET6:
     {
         struct sockaddr_in6 *sa;
         sa = (struct sockaddr_in6 *)malloc(sizeof(struct sockaddr_in6));
         ai->ai_addr = (struct sockaddr *)sa;
         ai->ai_addrlen = sizeof(*sa);
         if (ai->ai_addr == (struct sockaddr *)NULL) {
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
             return EAI_MEMORY;
         }
         sa->sin6_family = AF_INET6;
         sa->sin6_len = sizeof(*sa);
         sa->sin6_port = htons(port);
@@ -96,11 +101,10 @@ _getaddr(struct addrinfo *ai, const char
                 sa->sin6_addr = in6addr_loopback;
             }
         } else {
             // For now, only numeric "presentation" addresses supported
             if (!inet_pton(AF_INET6, (char *)node, (char *)&sa->sin6_addr)) {
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
                 return EAI_FAIL;  // Couldn't resolve name
             }
         }
     }
     break;
@@ -128,11 +132,10 @@ getaddrinfo(const char *nodename, const 
         dflt_hints.ai_protocol = 0;
         hints = &dflt_hints;
     }
     // Prevalidate parameters
     if ((nodename == (char *)NULL) && (servname == (char *)NULL)) {
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
         return EAI_NONAME;
     }
     switch (hints->ai_family) {
     case PF_UNSPEC:
     case PF_INET:
@@ -142,17 +145,15 @@ getaddrinfo(const char *nodename, const 
     case PF_INET6:
         family = AF_INET6;
         break;
 #endif
     default:
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
         return EAI_FAMILY;
     }
     // Allocate the first/primary result
     *res = ai = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
     if (ai == (struct addrinfo *)NULL) {
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
         return EAI_MEMORY;
     }
     // Handle request
     if (hints->ai_protocol != 0) {
         proto = getprotobynumber(hints->ai_protocol);
@@ -169,20 +170,18 @@ getaddrinfo(const char *nodename, const 
             protoname = "udp";
             ai->ai_socktype = SOCK_DGRAM;
             break;
         default:
             freeaddrinfo(ai);
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
             return EAI_SOCKTYPE;
         }
         // See if this is just a port #
-        if ((port = strtol(servname, 0, 0)) > 0) {
+        if ((port = strtol(servname, 0, 0)) >= 0) {
             ai->ai_socktype = hints->ai_socktype;
             if (hints->ai_socktype == 0) {
                 // Need to have complete binding type/port
                 freeaddrinfo(ai);
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
                 return EAI_SERVICE;
             }
         } else {
             struct servent *serv = (struct servent *)NULL;
 
@@ -193,19 +192,17 @@ getaddrinfo(const char *nodename, const 
                     serv = getservbyname(servname, protoname);
                 }
             }
             if (serv == (struct servent *)NULL) {
                 freeaddrinfo(ai);
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
                 return EAI_SERVICE;
             }
             port = ntohs(serv->s_port);      
         }
         proto = getprotobyname(protoname);
         if (hints->ai_protocol && (hints->ai_protocol != proto->p_proto)) {
             freeaddrinfo(ai);
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
             return EAI_SOCKTYPE;
         }
         ai->ai_protocol = proto->p_proto;
     }
     // Iterate through address types and create addresses
@@ -220,11 +217,10 @@ getaddrinfo(const char *nodename, const 
     if (hints->ai_family == PF_UNSPEC) {
         // Add IPv6 address as well
         struct addrinfo *nai = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
         if (nai == (struct addrinfo *)NULL) {
             freeaddrinfo(ai);
-            diag_printf("Error at %s.%d\n", __FUNCTION__, __LINE__);
             return EAI_MEMORY;
         }
         ai->ai_next = nai;
         nai->ai_family = PF_INET6;
         nai->ai_socktype = ai->ai_socktype;


-- 
------------------------------------------------------------
Gary Thomas                 |
MLB Associates              |  Consulting for the
+1 (970) 229-1963           |    Embedded world
http://www.mlbassoc.com/    |
email: <gary at mlbassoc dot com>  |
gpg: http://www.chez-thomas.org/gary/gpg_key.asc
------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]