LJ Archive

Listing 2. Ringing the Phone

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/telephony.h>
#include <linux/ixjuser.h>


int
main(int argc, char *argv[])
{
  int ixj=-1;
  char pname[80], maxrings;

  if(argc >= 2)
    sprintf(pname, "%s", argv[1]);
  else
    sprintf(pname, "/dev/phone0");

  printf("Opening %s\n",pname);
  ixj = open(pname, O_RDWR);

  if(ixj<1)
  {
    printf("Error opening device %s\n",pname);
    perror("open ");
    exit(-1);
  }

  if(argc >= 3)
    maxrings = atoi(argv[2]);
  else
    maxrings = 2;

  ioctl(ixj, PHONE_MAXRINGS, maxrings);

  if(!ioctl(ixj, PHONE_RING))
  {
    printf("No Answer\n");
  }
  else
  {
  printf("Phone answered\n");
  }
  close(ixj);
}
LJ Archive