[SunHELP] Basic port programming

Anthony J. Gabrielson agabriel at home.tzo.org
Wed May 15 12:24:12 CDT 2002


Hello all,
	Trying to do some basic port programming and build on just a small
piece of code so I can understand it.  My solaris box is giving me a bit
of headache.  I'm taking, which runs fine under linux and cygwin and
compile it - it has other ideas.  Here are the errors I'm getting:
bash-2.03$ gcc getip.c
Undefined                       first referenced
 symbol                             in file
gethostbyname                       /var/tmp/cctNqaTN.o
inet_ntoa                           /var/tmp/cctNqaTN.o
herror                              /var/tmp/cctNqaTN.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


Here is the code (grabbed from a website and knowen to work)
/*
** getip.c -- a hostname lookup demo
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
    struct hostent *h;

    if (argc != 2) {  // error check the command line
        fprintf(stderr,"usage: getip address\n");
        exit(1);
    }

    if ((h=gethostbyname(argv[1])) == NULL) {  // get the host info
        herror("gethostbyname");
        exit(1);
    }

    printf("Host name  : %s\n", h->h_name);
    printf("IP Address : %s\n", inet_ntoa(*((struct in_addr
*)h->h_addr)));
   
   return 0;
}

So I'm looking for ideas on why solaris gcc doesn't like this.  If anyone
knows, please fill me in....

Thanks,
Anthony



More information about the SunHELP mailing list