00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #include <stdio.h>
00025 #include <stddef.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <sys/types.h>
00029 #include <sys/socket.h>
00030 #include <netinet/in.h>
00031 #include <arpa/inet.h>
00032 #include <unistd.h>
00033
00034 #include "eripc.h"
00035 #include "eripclog.h"
00036 #include "eripcprivate.h"
00037 #include "eripcclient.h"
00038
00039 int erIpcSndCommand(erClientChannel_t channel, erIpcCmd_t * cmd)
00040 {
00041 char szBuffer[TB_MAXCHARONLINE];
00042 int i;
00043 int len;
00044
00045 if (channel == NULL || cmd == NULL)
00046 {
00047 ERIPC_ERRORPRINTF("Illegal parameters: channel [%p] cmd [%p]", channel, cmd);
00048 return -1;
00049 }
00050
00051 snprintf(szBuffer, sizeof(szBuffer), "%d", cmd->cc);
00052
00053 for (i = 0; i < cmd->nArg; i++)
00054 {
00055 len = strlen(szBuffer);
00056 snprintf(szBuffer + len, sizeof(szBuffer) - len, ",%s", cmd->arg[i]);
00057 }
00058 return erIpcSndMessage(channel, szBuffer);
00059 }
00060
00061 int erIpcSndMessage(erClientChannel_t channel, char *szMsg)
00062 {
00063 int sockfd;
00064 struct sockaddr_in serverAdr;
00065 erInternalClientChannel_t *clientChannel;
00066
00067 if (channel == NULL || szMsg == NULL)
00068 {
00069 ERIPC_ERRORPRINTF("Illegal parameters: channel [%p] szMsg [%p]", channel, szMsg);
00070 return -1;
00071 }
00072
00073 clientChannel = (erInternalClientChannel_t *) channel;
00074 sockfd = clientChannel->sockfd;
00075 serverAdr = clientChannel->serverAdr;
00076
00077 sendto(sockfd, szMsg, strlen(szMsg), 0, (struct sockaddr *) &serverAdr, sizeof(serverAdr));
00078 return 0;
00079 }
00080