/*---------------------------------------------------------------------+
| Copyright (c) 1995, SAS Institute Inc. |
| Unpublished - All Rights Reserved |
| S A S / C S A M P L E |
| |
| NAME: GSBNM |
| LANGUAGE: C |
| PURPOSE: This program uses the socket call, getservbyname() |
| to obtain the structure, servent. In most cases the |
| returned structure is used to obtain the port for the |
| service. getservbyname() reads the prefix.ETC.SERVICES |
| file. |
| Additional details on this socket function may be |
| found in the SAS/C Library Reference Vol 2, Third |
| Edition, Release 6.00. |
| NOTES: The prefix.ETC.SERVICES file must be properly |
| configured on the local host. |
| NOTES: The input parameters *are* case sensitive. |
| MVS - |
| COMPILE, LINK, EXECUTE: SUBMIT prefix.SAMPLE.AUX(LC370CLG) |
| NOTES: "prefix" is the SAS/C installation defined high-level |
| qualifier. |
| NOTES: on the EXEC statement add a: ,PARM.GO='name proto' |
| Where "name" is the name of the service, ie: ftp |
| and "proto" is the protocol, ie: tcp |
| TSO - |
| COMPILE: LC370 CLIST |
| LINK: CLK370 CLIST |
| EXECUTE: CALL 'your.load.lib(GSBNM)' 'name proto' ASIS |
| NOTES: Where "name" is the name of the service, ie: ftp |
| and "proto" is the protocol, ie: tcp |
| CMS - |
| COMPILE: LC370 |
| LINK: CLINK GSBNM (GENMOD |
| EXECUTE: GSBNM name proto |
| NOTES: Where "name" is the name of the service, ie: ftp |
| and "proto" is the protocol, ie: tcp |
+---------------------------------------------------------------------*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
main(int argc, char *argv[])
{
struct servent *serv;
if (argc < 3)
{
puts("Incorrect parameters. Use:");
puts(" gsbnm service-name protocol-name");
return EXIT_FAILURE;
}
/*---------------------------------------------------------------------+
| getservbyname() - opens the etc.services file and returns the |
| values for the requested service and protocol. |
+---------------------------------------------------------------------*/
serv = getservbyname(argv[1], argv[2]);
if (serv == NULL)
{
printf("Service \"%s\" not found for protocol \"%s\"\n",
argv[1], argv[2]);
return EXIT_FAILURE;
}
/* Print it. */
printf("Name: %-15s Port: %5d Protocol: %-6s\n",
serv->s_name,ntohs(serv->s_port),serv->s_proto);
return EXIT_SUCCESS;
}
|