*
* Usage: fortune -h give all info
*
- * $Id: FortuneClient.c,v 1.4 2003/05/02 09:55:13 piccardi Exp $
- *
****************************************************************/
/*
* Include needed headers
*/
-#include <sys/types.h> /* predefined types */
-#include <unistd.h> /* include unix standard library */
-#include <arpa/inet.h> /* IP addresses conversion utiliites */
-#include <stdio.h> /* include standard I/O library */
-#include <errno.h>
-#include <fcntl.h>
+#include <sys/types.h> /* primitive system data types */
+#include <unistd.h> /* unix standard library */
+#include <stdio.h> /* standard I/O library */
+#include <stdlib.h> /* C standard library */
+#include <errno.h> /* error definitions and routines */
+#include <fcntl.h> /* file control functions */
+#include <string.h> /* C strings library */
+#include <limits.h> /* system limits constants, types and functions */
#include "macros.h"
* Main code beginning
*
* ***********************************************************/
- snprintf(fifoname, 80, "/tmp/fortune.%d", getpid()); /* compose name */
- if (mkfifo(fifoname, 0622)) { /* open client fifo */
+ snprintf(fifoname, 80, "/tmp/fortune.%d", getpid()); /* compose name */
+ if (mkfifo(fifoname, 0622)) { /* open client fifo */
if (errno!=EEXIST) {
perror("Cannot create well known fifo");
exit(-1);
}
}
- fifo_server = open(fortunefilename, O_WRONLY); /* open server fifo */
+ fifo_server = open(fortunefilename, O_WRONLY); /* open server fifo */
if (fifo_server < 0) {
perror("Cannot open well known fifo");
exit(-1);
}
debug("%s\n", fifoname);
nread = write(fifo_server, fifoname, strlen(fifoname)+1); /* write name */
- close(fifo_server); /* close server fifo */
- fifo_client = open(fifoname, O_RDONLY); /* open client fifo */
+ close(fifo_server); /* close server fifo */
+ fifo_client = open(fifoname, O_RDONLY); /* open client fifo */
if (fifo_client < 0) {
perror("Cannot open well known fifo");
exit(-1);
}
- nread = read(fifo_client, buffer, sizeof(buffer)); /* read answer */
- printf("%s", buffer); /* print fortune */
- close(fifo_client); /* close client */
+ nread = read(fifo_client, buffer, sizeof(buffer)); /* read answer */
+ printf("%s", buffer); /* print fortune */
+ close(fifo_client); /* close client */
unlink(fifoname); /* remove client fifo */
}
/*
* routine to print usage info and exit
*/
void usage(void) {
- printf("Elementary fortune server\n");
+ printf("Elementary fortune client\n");
printf("Usage:\n");
- printf(" fortune [-h] [-f] \n");
+ printf(" fortune [-h] \n");
printf(" -h print this help\n");
- printf(" -f filename set file for fortunes\n");
exit(1);
}