Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Off -topic - newbie C programming question
At 11:07 am +0100 19/5/00, John Dunn wrote:
>Can anyone provide me with a quick bit of code to demonstrate how to call
>the gethostname routine (this is on AIX), and display the result.
It is not really AIX specific, but here is a very simple example:
#include <stdlib.h>
int main ( void ) {
char *thename;
int thelen = 20, theresult;
theresult = gethostname(thename,thelen);
printf("The hostname is %s and gethostname() returned %d\n",thename,theresult);
exit(0);
}
Notice that gethostname() does not return the name, it puts the name in the first argument which is a pointer to an array of char. It returns a simple 0 or 1 for 'no error' or 'error' respectively.
HTH Paul Miller
-
Carib Data Limited
<mailto:millerp_at_caribdata.co.uk>
<http://www.caribdata.co.uk>
Received on Fri May 19 2000 - 05:49:16 CDT
![]() |
![]() |