Imported Upstream version 2.7
[ossec-hids.git] / src / client-agent / sendmsg.c
1 /* @(#) $Id: ./src/client-agent/sendmsg.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
7  * This program is a free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General Public
9  * License (version 2) as published by the FSF - Free Software
10  * Foundation
11  */
12
13
14 #include "shared.h"
15 #include "agentd.h"
16
17 #include "os_net/os_net.h"
18
19
20 /* Sends a message to the server */
21 int send_msg(int agentid, char *msg)
22 {
23     int msg_size;
24     char crypt_msg[OS_MAXSTR +1];
25
26     msg_size = CreateSecMSG(&keys, msg, crypt_msg, agentid);
27     if(msg_size == 0)
28     {
29         merror(SEC_ERROR,ARGV0);
30         return(-1);
31     }
32
33     /* Send msg_size of crypt_msg */
34     if(OS_SendUDPbySize(logr->sock, msg_size, crypt_msg) < 0)
35     {
36         merror(SEND_ERROR,ARGV0, "server");
37         sleep(1);
38         return(-1);
39     }
40
41     return(0);
42 }
43