17#include <sys/socket.h>
18#include <netinet/in.h>
23#include "../dlib/dlib.h"
24#include "../dpip/dpip.h"
26#define MSG_ERR(...) printf("** ERROR **: " __VA_ARGS__);
35 fprintf(stderr,
"Control program for the Dillo plugin daemon\n"
36 "Usage: %s {stop|register|chat}\n\n", prgname);
52 char *fname, *rcline = NULL, *tail;
56 if ((In = fopen(fname,
"r")) == NULL) {
58 }
else if ((rcline =
dGetline(In)) == NULL) {
59 MSG_ERR(
"[Dpi_read_comm_keys] empty file: %s\n", fname);
61 *port = strtol(rcline, &tail, 10);
62 for (i = 0; *tail && isxdigit(tail[i+1]); ++i)
73int main(
int argc,
char *argv[])
75 int sockfd, portno, n;
76 struct sockaddr_in serv_addr;
86 MSG_ERR(
"main: Can't read dpid's port number\n");
90 sockfd = socket(AF_INET, SOCK_STREAM, 0);
92 error(
"ERROR opening socket");
93 memset(&serv_addr, 0,
sizeof(serv_addr));
94 serv_addr.sin_family = AF_INET;
95 serv_addr.sin_addr.s_addr = inet_addr(
"127.0.0.1");
97 serv_addr.sin_port = htons(portno);
98 if (connect(sockfd, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr)) < 0)
99 error(
"ERROR connecting");
101 snprintf(buffer,
sizeof(buffer),
"<cmd='auth' msg='%s' '>",
SharedKey);
102 n = write(sockfd, buffer, strlen(buffer));
104 error(
"ERROR writing to socket");
106 if (strcmp(argv[1],
"stop") == 0) {
108 }
else if (strcmp(argv[1],
"register") == 0) {
110 }
else if (strcmp(argv[1],
"chat") == 0) {
111 printf(
"Please enter the message: ");
112 memset(buffer,0,256);
113 if (fgets(buffer,255,stdin) == NULL)
114 MSG_ERR(
"dpidc: Can't read the message\n");
116 MSG_ERR(
"main: Unknown operation '%s'\n", argv[1]);
121 n = write(sockfd,buffer,strlen(buffer));
123 error(
"ERROR writing to socket");
char * dGetline(FILE *stream)
Get a line from a FILE stream.
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
int dClose(int fd)
Close a FD handling EINTR.
char * dGethomedir(void)
Return the home directory in a static string (don't free)
static char SharedKey[32]
static int Dpi_read_comm_keys(int *port)
Read dpid's communication keys from its saved file.
static void print_usage(const char *prgname)
static void error(char *msg)