1/* 2 * "$Id:$" 3 * 4 * Simple tool to showing how to send the answer command to the efax deamon. 5 * 6 * Copyright 2006 by Apple Computer Inc., all rights reserved. 7 */ 8 9#include <sys/socket.h> 10#include <sys/un.h> 11#include <string.h> 12#include <stdlib.h> 13#include <stdio.h> 14#include <unistd.h> 15 16static void usage(); 17 18int main(int argc, char * argv[]) 19{ 20 int c, 21 fd; 22 char command[3] = "?\n"; 23 struct sockaddr_un saddr; 24 25 while ((c = getopt(argc, argv, "ac?")) != -1) 26 { 27 switch (c) 28 { 29 case 'a': 30 case 'c': 31 command[0] = (char)c; 32 break; 33 } 34 } 35 36 if (command[0] == '?') 37 usage(); 38 39 bzero(&saddr, sizeof(saddr)); 40 saddr.sun_family = AF_LOCAL; 41 strlcpy(saddr.sun_path, "/var/run/efax", sizeof(saddr.sun_path)); 42 43 fd = socket(AF_LOCAL, SOCK_STREAM, 0); 44 if (connect(fd, (struct sockaddr *)&saddr, SUN_LEN(&saddr)) < 0) { 45 perror("connect"); 46 exit(1); 47 } 48 49 write(fd, command, strlen(command)); 50 close(fd); 51 52 return 0; 53} 54 55static void usage() 56{ 57 static char usage_msg[] = 58 "Usage: efaxtest [-a] [-c]\n" \ 59 " -a Send answer command to daemon\n" \ 60 " -c Send cancel command to daemon\n"; 61 62 fputs(usage_msg, stderr); 63 exit(1); 64} 65