Subject: Re: getaddrinfo

From: "Chirag H. Shroff" <[email-masked]>
Date: Fri, 2 Aug 2002 12:44:07 -0700 (MST)

Thanks for your reply. I included the defination when i added again i got the 
following message:

baja{shroff}% gcc tcp_connect.c -lsocket -lnsl -lresolv -lc
Undefined                       first referenced
 symbol                             in file
getaddrinfo                         /var/tmp/cc0PNKdp.o
gai_strerror                        /var/tmp/cc0PNKdp.o
freeaddrinfo                        /var/tmp/cc0PNKdp.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

from my prev experiences i know that when we dont add a library corresponding
to the function call we get the above message. I am trying a lot to find the
library but i am not able to.

Which library do i need to add? Where am I going wrong? Please help.

Thanks a lot.

Chirag

> From [email-masked] Fri Aug  2 11:42 MST 2002
> X-Autogenerated: Mirror
> X-Mirrored-by: <[email-masked]> (Chirag Shroff)
> Date: Fri, 02 Aug 2002 14:42:34 -0400
> From: Bill Cote USG <[email-masked]>
> User-Agent: Mozilla/5.0 (X11; U; OSF1 alpha; en-US; rv:0.9.4) Gecko/20011025 Netscape6/6.2
> X-Accept-Language: en-us
> MIME-Version: 1.0
> To: "Chirag H. Shroff" <[email-masked]>
> Subject: Re: getaddrinfo
> Content-Transfer-Encoding: 7bit
> 
> It looks like you don't have the getaddrinfo struct defined in any of 
> your headers.  Check those out to make sure that it's in there (should 
> be in netdb.h).  If not, you may need to include a different one
> 
> Chirag H. Shroff wrote:
> 
> > The following is an example from R Stevens book "UNP". I am having difficulties
> > with the code shown below. 
> > 
> > When I try to compile it using......
> > 
> > 	gcc tcp_connect.c -lsocket -lnsl -lresolv -lc
> > 
> > I get the following error messages....
> > 		
> > baja{shroff}% gcc tcp_connect.c -lsocket -lnsl -lresolv -lc
> > tcp_connect.c: In function `tcp_connect':
> > tcp_connect.c:38: storage size of `hints' isn't known
> > tcp_connect.c:40: sizeof applied to an incomplete type
> > tcp_connect.c:53: dereferencing pointer to incomplete type
> > tcp_connect.c:53: dereferencing pointer to incomplete type
> > tcp_connect.c:53: dereferencing pointer to incomplete type
> > tcp_connect.c:56: dereferencing pointer to incomplete type
> > tcp_connect.c:56: dereferencing pointer to incomplete type
> > tcp_connect.c:61: dereferencing pointer to incomplete type
> > 
> > I think these errors are due to the use of getaddrinfo. I am very new to socket
> > programming. I'll be greatful if someone can tell me where i am going wrong.
> > 
> > Thanks a lot,
> > 
> > Chirag
> > 
> > 
> > 
> > #include <stdio.h>
> > #include <sys/types.h>
> > #include <sys/socket.h>
> > #include <netinet/in.h>
> > #include <netdb.h>
> > #include <arpa/inet.h>
> > #include <time.h>
> > #include <fcntl.h>
> > #include <errno.h>
> > 
> > //#include "addrinfo.h"
> > 
> > #define ERROR -1
> > #define OK     1 
> > #define TRUE   1
> > 
> > 
> > /********************************************************************************
> > * tcp_connect - client task
> > *
> > *
> > * RETURNS: OK or ERROR
> > */
> > 
> > int tcp_connect (const char *host, const char *serv) {
> > 
> >     int sockfd, n;
> >     struct addrinfo     hints, *res, *ressave;
> > 
> >     bzero (&hints, sizeof (struct addrinfo));
> >     hints.ai_family = AF_UNSPEC;
> >     hints.ai_socktype = SOCK_STREAM;
> > 
> >     if ((n = getaddrinfo (host, serv, &hints, &res)) != 0) {
> >       printf ("tcp_connect error for %s, %s: %s\n\n",host,serv,gai_strerror(n));      return ERROR;
> >     }
> > 
> >     ressave = res;
> > 
> >     do {
> > 
> >         if((sockfd=socket (res->ai_family,res->ai_socktype,res->ai_protocol))<0)            continue;
> > 
> >         if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0)
> >             break;              // connected.
> > 
> >         close (sockfd); // connect was not successful, so ignore this socket.
> > 
> >     } while ((res = res->ai_next) != NULL);
> > 
> > 
> >     if (res == NULL) {          // connection could not be established.
> >         printf ("tcp_connect error for %s, %s", host,serv);
> >         return ERROR;
> >     }
> > 
> >     freeaddrinfo (ressave);
> > 
> >     return (sockfd);
> > }
> > 
> > int main () {
> >  
> >     tcp_connect ("140.252.7.10", "daytime");
> > 
> >     exit (0);
> > }
> >  
> >  
> > --------------------------------------------------------------------
> > IETF IPng Working Group Mailing List
> > IPng Home Page:                      http://playground.sun.com/ipng
> > FTP archive:                      ftp://playground.sun.com/pub/ipng
> > Direct all administrative requests to [email-masked]
> > --------------------------------------------------------------------
> > 
> > 
> > 
> 
> 
> 
--------------------------------------------------------------------
IETF IPng Working Group Mailing List
IPng Home Page:                      http://playground.sun.com/ipng
FTP archive:                      ftp://playground.sun.com/pub/ipng
Direct all administrative requests to [email-masked]
--------------------------------------------------------------------