/*---------------------------------------------------------------------+ | Copyright (c) 1995, SAS Institute Inc. | | Unpublished - All Rights Reserved | | S A S / C S A M P L E | | | | NAME: GETHID | | LANGUAGE: C | | PURPOSE: This program uses the socket call, gethostid() to | | return the 32-bit Internet Address for the local host. | | Additional details on this socket function may be | | found in the SAS/C Library Reference Vol 2, Third | | Edition, Release 6.00. | | NOTES: The local host must have an operational TCPIP stack. | | MVS - | | COMPILE, LINK, EXECUTE: SUBMIT prefix.SAMPLE.AUX(LC370CLG) | | NOTES: "prefix" is the SAS/C installation defined high-level | | qualifier. | | TSO - | | COMPILE: LC370 CLIST | | LINK: CLK370 CLIST | | EXECUTE: CALL 'your.load.lib(GETHID)' | | CMS - | | COMPILE: LC370 | | LINK: CLINK GETHID (GENMOD | | EXECUTE: GETHID | +---------------------------------------------------------------------*/ #include #include #include #include #include #include main() { struct in_addr in; /*---------------------------------------------------------------------+ | gethostid() returns the 32-bit internet address as an unsigned long. | +---------------------------------------------------------------------*/ in.s_addr = gethostid(); if (in.s_addr == INADDR_NONE) { perror("gethostid failed"); return EXIT_FAILURE; } /*---------------------------------------------------------------------+ | convert the unsigned long to a string in dotted decimal and print. | +---------------------------------------------------------------------*/ printf("Local Host IP Address is: %s\n",inet_ntoa(in)); return EXIT_SUCCESS; }