Chapter Contents

Previous

Next
getclientid

getclientid



Gets the Calling Application Identifier

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTIONS
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <sys/types.h>
#include <sys/socket.h>

int getclientid(int domain, struct clientid *clientid);


DESCRIPTION

getclientid gets the identifier of the calling application. domain is AF_INET . clientid is a pointer to the clientid structure, which is filled on return from the call. getclientid is used in the givesocket and takesocket calls, which enable cooperative processes to pass socket descriptors to each other.

Note:    getclientid is only supported with non-integrated sockets. However, starting with SAS/C Release 7.00, the getclientid function is supported for integrated sockets.  [cautionend]


RETURN VALUE

If getclientid succeeds, it returns a 0 . Otherwise, it returns a -1 and sets errno to indicate the type of error.


CAUTIONS

For nonintegrated sockets, the getclientid function returns the subtaskname member of the clientid structure with a task identifier consisting of EBCDIC characters, for example, "SASCL08c" (0xE2C1E2C3D3F0F883).

For integrated sockets, starting with SAS/C Release 7.00, the getclientid function returns the subtaskname member of the clientid structure with a task identifier containing binary data, for example, 0x0000030F634E98.

The nonintegrated socket version of the getclientid function is the default version for releases prior to SAS/C Release 7.00. However, starting with SAS/C Release 7.00, programs will use integrated sockets by default if running under OS/390 Version 2 Release 5 or greater. Thus, any code that depends on subtaskname containing printable EBCDIC characters may fail.


PORTABILITY

getclientid is not portable to UNIX operating systems. On a UNIX operating system, sockets can be transferred from parent to child processes when the child process has been created via the fork system call.


EXAMPLE

In this example, getclientid returns the client ID from TCP/IP.

#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>

   /* These three application routines implement communication  */
   /* between the parent task and this task. They use a means   */
   /* other than sockets to communicate.                        */
fromparent(void *, size_t);
toparent(void *, size_t);
postparent(void);

   /* This routine receives a socket from its parent            */
   /* task and store the descriptor into the integer pointed    */
   /* to by "s".                                                */
recvsock(int *s)
{
   struct clientid id;

      /* Get the clientid from TCP/IP.                          */
   if (getclientid (AF_INET, &id)==-1) {
      perror ("Can't get client ID");
      return -1;
   }

      /* Pass clientid to parent.                               */
   toparent(&id,sizeof(id));

      /* Get socket descriptor number from parent.              */
   fromparent(s, sizeof(*s));

      /* Take socket from parent.                               */
   if (takesocket(&id, *s)==-1) {
      perror ("takesocket failed");
      return -1;
   }

      /* Tell parent that takesocket is completed.              */
   postparent();
   return 0;
}


RELATED FUNCTIONS

getclientpid, givesocket , givesocket_pid, takesocket , takesocket_pid


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.