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