“<>”丢失有什么问题
what wrong with "<>" missing
我编写了一个程序来将系统日志发送到远程 sever.Part 我的代码如下:
sprintf(syslogBuf,"<%d>LogTime=\"%s\";user=\"%s\";IP=\"%s\";Sip=\"%s\";OpType=\"%s\";OpResult=\"%d\";OpText=\"%s %s\"",
pri,p[0],p[1],IP,p[2],p[3],flag,p[1],p[3]);
并且我使用 sendto()
发送 syslogBuf
到远程 sylog sever.But 服务器收到的是:
LogTime="2015-10-20 14:33:57";user="root";IP="127.0.1.12";Sip="127.0.1.14";OpType="show meminfo";OpResult="0";OpText="root show meminfo"
为什么<%d>
错过了?
发送码如下:
if(UdpSendData(sockfd,syslogBuf,strlen(syslogBuf),syslogServer,SYSLOGPORT) == -1);
perror("send failed");
UdpSendData:
int UdpSendData(int sockfd,const char *buf, UINT32 dataLen, char *remoteIP, int remotePort)
{
struct sockaddr_in RemoteAddr;
int len;
if( sockfd <= -1)
{
printf("%s send fail,sock error.\n",__FUNCTION__);
return -1;
}
if((buf == NULL)||(remoteIP==NULL))
{
printf("%s send fail,buf error or remote ip error.\n",__FUNCTION__);
return -1;
}
//printf("udp send remote ip %s port %d.\n",remoteIP,remotePort);
memset(&RemoteAddr,0,sizeof(RemoteAddr));
RemoteAddr.sin_family = AF_INET;
RemoteAddr.sin_port = htons( remotePort );
RemoteAddr.sin_addr.s_addr = inet_addr( remoteIP );
int addrLen = sizeof(RemoteAddr);
len = sendto(sockfd, buf, dataLen, 0, (struct sockaddr*)&RemoteAddr, addrLen);
if (len <= 0)
{
printf("%s udp send to %s %d fail.\n",__FUNCTION__,remoteIP,remotePort);
return -1;
}
return len;
}
<%d>
已发送,但系统日志将其解释为优先级标记而不是消息的一部分。您可以简单地改用 [%d]
或 (%d)
.
我编写了一个程序来将系统日志发送到远程 sever.Part 我的代码如下:
sprintf(syslogBuf,"<%d>LogTime=\"%s\";user=\"%s\";IP=\"%s\";Sip=\"%s\";OpType=\"%s\";OpResult=\"%d\";OpText=\"%s %s\"",
pri,p[0],p[1],IP,p[2],p[3],flag,p[1],p[3]);
并且我使用 sendto()
发送 syslogBuf
到远程 sylog sever.But 服务器收到的是:
LogTime="2015-10-20 14:33:57";user="root";IP="127.0.1.12";Sip="127.0.1.14";OpType="show meminfo";OpResult="0";OpText="root show meminfo"
为什么<%d>
错过了?
发送码如下:
if(UdpSendData(sockfd,syslogBuf,strlen(syslogBuf),syslogServer,SYSLOGPORT) == -1);
perror("send failed");
UdpSendData:
int UdpSendData(int sockfd,const char *buf, UINT32 dataLen, char *remoteIP, int remotePort)
{
struct sockaddr_in RemoteAddr;
int len;
if( sockfd <= -1)
{
printf("%s send fail,sock error.\n",__FUNCTION__);
return -1;
}
if((buf == NULL)||(remoteIP==NULL))
{
printf("%s send fail,buf error or remote ip error.\n",__FUNCTION__);
return -1;
}
//printf("udp send remote ip %s port %d.\n",remoteIP,remotePort);
memset(&RemoteAddr,0,sizeof(RemoteAddr));
RemoteAddr.sin_family = AF_INET;
RemoteAddr.sin_port = htons( remotePort );
RemoteAddr.sin_addr.s_addr = inet_addr( remoteIP );
int addrLen = sizeof(RemoteAddr);
len = sendto(sockfd, buf, dataLen, 0, (struct sockaddr*)&RemoteAddr, addrLen);
if (len <= 0)
{
printf("%s udp send to %s %d fail.\n",__FUNCTION__,remoteIP,remotePort);
return -1;
}
return len;
}
<%d>
已发送,但系统日志将其解释为优先级标记而不是消息的一部分。您可以简单地改用 [%d]
或 (%d)
.