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