[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Communications Programming Concepts


Sending Data on an ATM Socket PVC Client Example Program

This program must be compiled with the -D_BSD and -lbsd options. For example, use the cc prog.c -o prog -D_BSD -lbsd command.

/*
 *
 * ATM Sockets PVC Client Example
 *
 * This program opens a PVC and sends data on it.
 *
 */

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/ndd_var.h>
#include <sys/atmsock.h>
#define BUFF_SIZE    8192
char    buff[BUFF_SIZE];
main(argc, argv)
        int argc;
        char *argv[];
{
   int                     s;       // Socket file descriptor
   int                     error;   // Function return code
   sockaddr_ndd_atm_t      addr;    // ATM Socket Address

  // Create a socket in the AF_NDD domain of type SOCK_CONN_DGRAM
  // and NDD_PROT_ATM protocol.
  s = socket(AF_NDD, SOCK_CONN_DGRAM, NDD_PROT_ATM);
  if (s == -1) {         // Socket either returns the file descriptor
      perror("socket");  // or a -1 to indicate an error.
      exit(-1);
   }
  // The bind command associates this socket with a particular
  // ATM device, as specified by addr.sndd_atm_nddname.
  addr.sndd_atm_len = sizeof(addr);
  addr.sndd_atm_family = AF_NDD;
  strcpy( addr.sndd_atm_nddname, "atm0" ); // The name of the ATM device
                                          // which is to be used.
  error = bind( s, (struct sockaddr *)&addr, sizeof(addr) );
  if (error) {         // An error from bind would indicate the
     perror("bind");   // requested ATM device is not available.
     exit(-1);         // Check smitty devices.
   } /* endif */

  // To open a PVC, the addr.sndd_atm_vc_type field of the
  // sockaddr_ndd_atm is set to CONN_PVC.  The VPI and VCI are
  // specified in the fields sndd_atm_addr.number.addr[0] and
  // sndd_atm_addr.number.addr[1].

  addr.sndd_atm_vc_type = CONN_PVC;         // Indicates PVC
   addr.sndd_atm_addr.number.addr[0] = 0;    // VPI
   addr.sndd_atm_addr.number.addr[1] = 15;   // VCI
   error = connect( s, (struct sockaddr *)&addr, sizeof(addr) );
   if (error) {            // A connect error may indicate that
      perror("connect");   // the VPI/VCI is already in use.
      exit(-1);
   } /* endif */
   while (1) {
      error = send( s, buff, BUFF_SIZE, 0 );
      if (error < 0 ) {                      // Send returns -1 to
         perror("send");                     // to indicate an error.
         exit(-1);                           // The errno is set an can
      } else {                               // be displayed with perror.
         printf("sent %d bytes\n", error );  // Or it returns the number
      }                                      // of bytes transmitted
      sleep(1);      // Just sleep 1 second, then send more data.
   } /* endwhile */
   exit(0);
}


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]