title: send a message to a remote rsyslog in c++
body: <p>Is there a way to send a message to a remote syslog in c++ code?</p>
  
  <p>equivalent to this line in linux command:</p>
  
  <pre><code>nc -w0 -u 192.168.1.1 514 &lt;&lt;&lt; "logging from remote"
  </code></pre>
  
  <p>This code supposed to do the some thing with socket but it doesn't work. </p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  int listenfd = 0, connfd = 0,n;
  struct sockaddr_in serv_addr;
      struct hostent *server;
  
  
  char sendBuff[1025];
  sprintf(sendBuff,"bla bla");
  
  time_t ticks; 
  
  listenfd = socket(AF_INET, SOCK_DGRAM , 0);
  memset(&amp;serv_addr, '0', sizeof(serv_addr));
  memset(sendBuff, '0', sizeof(sendBuff)); 
  
  serv_addr.sin_family = AF_INET;
  server = gethostbyname("192.168.1.108");
  bcopy((char *)server-&gt;h_addr, (char *)&amp;serv_addr.sin_addr.s_addr, server-&gt;h_length);
  
  //serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(514); 
  
      if ((n=connect(connfd,(const sockaddr*)&amp;serv_addr,sizeof(serv_addr))) &lt; 0){
              printf(" Connection to has failed Server ");
      }
  
  
  bind(listenfd, (struct sockaddr*)&amp;serv_addr, sizeof(serv_addr)); 
  
  listen(listenfd, 10); 
  
  while(1)
  {
      connfd = accept(listenfd, (struct sockaddr*)NULL, NULL); 
  
      write(connfd, sendBuff, strlen(sendBuff)); 
  
      close(connfd);
      sleep(60);
  }
  </code></pre>
  
  <p>}</p>