Unix questions - get hostname and gethostbyname error

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > February 2004 > get hostname and gethostbyname error





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author get hostname and gethostbyname error
usc

2004-02-13, 10:34 am

hi

I am using solaris 9 and I want to get the ip of local machine by
using gethostbyname it is giving following error, same error is given
by getsockname
.. gethostname works it returns the name but gethostbyname does not, I
have been strugling with it any help is appreciated

g++ ssock.c -o ssock
Undefined first referenced
symbol in file
getsockname /var/tmp/ccc3g7n6.o
bind /var/tmp/ccc3g7n6.o
socket /var/tmp/ccc3g7n6.o
ld: fatal: Symbol referencing errors. No output written to ssock
collect2: ld returned 1 exit status


same error with gethostbyname

g++ h1.c -o h6
Undefined first referenced
symbol in file
gethostbyname /var/tmp/ccQAySIc.o
ld: fatal: Symbol referencing errors. No output written to h6
collect2: ld returned 1 exit status


clive
Sean Burke

2004-02-14, 4:33 pm


uscttrojan@yahoo.com (usc) writes:

> hi
>
> I am using solaris 9 and I want to get the ip of local machine by
> using gethostbyname it is giving following error, same error is given
> by getsockname
> . gethostname works it returns the name but gethostbyname does not, I
> have been strugling with it any help is appreciated
>
> g++ ssock.c -o ssock
> Undefined first referenced
> symbol in file
> getsockname /var/tmp/ccc3g7n6.o
> bind /var/tmp/ccc3g7n6.o
> socket /var/tmp/ccc3g7n6.o
> ld: fatal: Symbol referencing errors. No output written to ssock
> collect2: ld returned 1 exit status
>
>
> same error with gethostbyname
>
> g++ h1.c -o h6
> Undefined first referenced
> symbol in file
> gethostbyname /var/tmp/ccQAySIc.o
> ld: fatal: Symbol referencing errors. No output written to h6
> collect2: ld returned 1 exit status


You're missing a library. The trick is to pay careful
attention to the line right below SYNOPSIS in the man page:

NAME
gethostbyname, gethostbyname_r, gethostbyaddr,
gethostbyaddr_r, gethostent, gethostent_r, sethostent,
endhostent - get network host entry

SYNOPSIS
cc [ flag ... ] file ... -lnsl [ library ... ]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!----^^^^^

#include <netdb.h>

-SEan
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com