www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/*---------------------------------------------------------------------+
|                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 <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>

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;
}

Copyright (c) 2000 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement