/*---------------------------------------------------------------------+
| Copyright (c) 1995, SAS Institute Inc. |
| Unpublished - All Rights Reserved |
| S A S / C S A M P L E |
| |
| NAME: GETSENT |
| LANGUAGE: C |
| PURPOSE: This program demonstrates the socket calls: |
| endservent(), getservent(), and setservent(). |
| Additional details on these socket functions may be |
| found in the SAS/C Library Reference Vol 2, Third |
| Edition, Release 6.00. |
| NOTES: GETSENT attempts to open a prefix.ETC.SERVICES file to |
| obtain local configuration data. Where "prefix" |
| is defined in the SAS/C Library Reference Vol 2, |
| Third Edition, Release 6.00, Network Administration |
| chapter. |
| 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(GETSENT)' |
| CMS - |
| COMPILE: LC370 |
| LINK: CLINK GETSENT (GENMOD |
| EXECUTE: GETSENT |
+---------------------------------------------------------------------*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#define TRUE 1
main()
{
struct servent *serv;
/*---------------------------------------------------------------------+
| setservent() opens the ETC.SERVICES file |
+---------------------------------------------------------------------*/
setservent(TRUE);
/*---------------------------------------------------------------------+
| getservent() sequentially reads the elements in the ETC.SERVICES file|
+---------------------------------------------------------------------*/
while (serv = getservent())
{
/* Print an entry. */
printf("Name: %-15s Port: %5d Protocol: %-6s\n",
serv->s_name,ntohs(serv->s_port),serv->s_proto);
}
/*---------------------------------------------------------------------+
| endservent() closes ETC.SERVICES |
+---------------------------------------------------------------------*/
endservent();
return EXIT_SUCCESS;
}
|