How to get a fqn hostname

Jan H. Schrewe jschrewe at
Mon Oct 8 14:51:31 BST 2001

Werner Modenbach wrote:

> On Montag, 8. Oktober 2001 14:12 Jan H. Schrewe wrote / Am Montag, 8. Oktober 
> 2001 14:12 schrieb Jan H. Schrewe:
>>Werner Modenbach wrote:
>>>On Montag, 8. Oktober 2001 13:15 Jan H. Schrewe wrote / Am Montag, 8.
>>>2001 13:15 schrieb Jan H. Schrewe:
>>>>Werner Modenbach wrote:
>>>>>First of all sorry for the OT question.
>>>>>In programming a server using Qt classes I need to know the
>>>>>fqn hostname of the system.
>>>>>The QSocket method address() allways returns "".
>>>>>Going to gethostname(...) and getdomainname(...) delivers domainname "".
>>>>>uname(...) also returns an empty domainname.
>>>>>Any hints? I've no idea where else to look for a solution.
>>>>>- Werner -
>>>>try gethostbyname(3) the function is called gethostbyaddress. I don't
>>>>really know if this is the fqdn but it should be a starting point
>>>For this to work I need to know the numerical address which I also don't
>>>- Werner -
>>the man-page of dnsdomainname (a shell command) says:
>>"Technically: The FQDN is the name gethostbyname(2) returns
>>for the host name returned  by  gethostname(2).   The  DNS
>>domain name is the part after the first dot."
>>I don't know if gethostname(...) returns works for you, but this does sound
>>like it shuold work (although never tried it :-)
> My fqn is ""
> gethostname(...)   gives "werner"
> getdomainname(...) gives ""

Try gethostbyname(3) after you called gethostname.

> The shell command 'dnsdomainname' gives "" but there is no library 
> function like that.
> - Werner - 

Here is a small prgram that should help you (for me it works fine):

#include <unistd.h>
#include <netdb.h>

int main () {
   char hostname[100];
   int length = 100;
   struct hostent *he;

   gethostname( hostname, length );
   printf( "Hostname: %s\n", hostname );

   he = gethostbyname( hostname );
   printf( "FQN-Hostname: %s\n", he->h_name );


hope that helps


to unsubscribe from this list send an email to kdevelop-request at with the following body:
unsubscribe »your-email-address«

More information about the KDevelop mailing list