Friday, August 26, 2011

Using the socket getdomainname(2) Function

getdomainname system call or getdomainname example

The getdomainname(2) function is another convenience function to allow the programmer to inquire about the host's NIS domain name, where the program is executing. The following is the function synopsis:

#include <unistd.h>
int getdomainname(char *name,size_t len);

This function is identical in use to the gethostname(2) function. The two arguments are
  • The buffer name, which is to receive the domain name and is at least len bytes in length.
  • The buffer length (len), in bytes, of the buffer name.

Again, the function returns zero when successful. The value -1 is returned when there is an error. External variable errno contains the error code for the failure. The Linux man page indicates that the getdomainname(2) function internally uses the uname (2) function to obtain and return the NIS domain name.


Sample Code:
Using getdomainname function sample C code

No comments:

Post a Comment