home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12114a < prev    next >
Text File  |  1990-07-25  |  2KB  |  95 lines

  1. /*
  2.  * client.c
  3.  *
  4.  *    Basic client process for time accounting system, non-network version.
  5.  *    This process (and those that are linked to it) are run as commands 
  6.  *    and send events to the server process.
  7. */
  8.  
  9. #include <sys/types.h>
  10. #include <sys/socket.h>
  11. #include <netinet/in.h>
  12. #include <netdb.h>
  13. #include <stdio.h>
  14. #include "time_entry.h"
  15.  
  16. main(argc, argv)
  17.     int argc;
  18.     char *argv[];
  19. {
  20.  
  21.     int skt_id,    /* Socket descriptor */
  22.         msg_sock,  /* Socket that will accept messages */
  23.         i,j;
  24.  
  25.     EVENT_TYPE event;
  26.  
  27.     struct sockaddr sa;  /* Socket address structure   */
  28.     char buff[80];
  29.  
  30.         /*
  31.          *  Specify the socket domain and type we want...
  32.         */
  33.         skt_id = socket(AF_UNIX, SOCK_STREAM, 0);
  34.         if(skt_id == -1){
  35.             perror("Can't create socket");
  36.             exit(1);
  37.         }
  38.  
  39.         /*
  40.          *  Now set up the address structure and connect to the socket.
  41.         */
  42.         sa.sa_family = AF_UNIX;
  43.         strcpy(sa.sa_data, SOCKET_NAME);
  44.  
  45.         if(connect(skt_id, &sa, sizeof(sa)) == -1){
  46.             perror("Can't connect to socket");
  47.             exit(1);
  48.         }
  49.  
  50.         build_event(argv[0], &event);
  51.  
  52.         /* 
  53.          * Now, send the event
  54.         */
  55.  
  56.         if(write(skt_id, &event, sizeof(event)) != sizeof(event)){
  57.             perror("Write");
  58.             exit(1);
  59.         }
  60.  
  61.         /* Cleanup */
  62.         close(skt_id);
  63.         exit(0);
  64. }
  65.  
  66. build_event(a, e)
  67.     char *a;        /* Name process was invoked with */
  68.     EVENT_TYPE *e;  /* A time entry event   */
  69. {
  70.  
  71.         if(!strcmp(a, "pi"))             /* A PHONE_IN event */
  72.             e->event_cd = PHONE_IN;
  73.         else if(!strcmp(a, "po"))        /* PHONE_OUT */
  74.             e->event_cd = PHONE_OUT;
  75.         /*
  76.          *  Check any other types...
  77.         */
  78.         else
  79.             e->event_cd = SHUT_DOWN;   /* Default is shut down */
  80.  
  81.         e->bill_flag = 'Y';            /* Billable is the default */
  82.  
  83.         /*
  84.          *  Code here to get the system time (e->event_st), and the
  85.          *  login name of the user (e->logname).  For now, let's just
  86.          *  hard code something...
  87.         */
  88.         e->event_st = 0;
  89.         strcpy(e->logname, "bryang");
  90. }
  91.  
  92.  
  93.  
  94.  
  95.