getnetname Subroutine

Important: The subroutine is exported from both the libc and the libnsl libraries.

getnetname Subroutine Exported from the libc Library

Purpose

Installs the network name of the caller in the array specified by the name parameter.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

getnetname ( name)
char name [MAXNETNAMELEN];

Description

The getnetname subroutine installs the caller's unique, operating-system-independent network name in the fixed-length array specified by the name parameter.

Parameters

Item Description
name Specifies the network name (or netname) of the server process owner. The name parameter can be either the host name derived from the host2netname subroutine or the user name derived from the user2netname subroutine.

Return Values

Upon successful completion, this subroutine returns a value of 1. If unsuccessful, it returns a value of 0.

getnetname Subroutine Exported from the libnsl Library

Purpose

Generates the operating-system-independent network name of the caller.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
getnetname ( name)
char *name;

Description

The getnetname subroutine, which belongs to the secure RPC category, is used in applications that use the AUTH_DES authentication flavor. This subroutine generates the network name (or netname) of the caller. If the caller has root authority, the net name of the host machine is generated.

Parameters

Item Description
name Represents the network name of the caller.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

#include <rpc/rpc.h>
int main()
{
  char name[255]; /* contains netname of owner of server process */
  char rhost[255]; /* Remote host name on which server resides */ 
  rpcprog_t  PROGNUM = 0x3fffffffL;
  rpcvers_t  PROGVER = 0x1L;
  
  if(!getnetname(name))
  {
    fprintf(stderr,"getnetname() error\n");
    exit(1);
  }

  /* Create a client handle for remote host rhost for PROGNUM & PROGVER on tcp transport */
  clnt = clnt_create(rhost, PROGNUM, PROGVER, "tcp");
  if (clnt == (CLIENT *) NULL) {
    fprintf(stderr,"client_create() error\n");
    exit(1);
  }

  clnt->cl_auth = authdes_seccreate(name, 80, rhost, (des_block *)NULL);

  /* 
   * Make a call to clnt_call() subroutine 
   */

  /* Destroy the authentication handle */
  auth_destroy(clnt->cl_auth);
  
  /* Destroy the client handle in the end */
  clnt_destroy(clnt);

  return 0;
}