git-svn-id: http://172.17.0.253/svn/soft_pkgs/sys_nicmonitor@146 09c3743a-b0dd-45d3-b506-aa74c7a2a6ef
38 lines
1.2 KiB
C
38 lines
1.2 KiB
C
#include "mnic.h"
|
|
|
|
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
|
{
|
|
int bytes;
|
|
int sock_sd;
|
|
int val;
|
|
char error_str[200];
|
|
struct sockaddr_in recever;
|
|
socklen_t sock_len;
|
|
|
|
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
|
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
|
record_log(error_str);
|
|
return;
|
|
}
|
|
val=1;
|
|
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
|
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
|
record_log(error_str);
|
|
return;
|
|
}
|
|
/* init socket*/
|
|
recever.sin_family = AF_INET;
|
|
recever.sin_port = htons(socket_port);
|
|
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
|
sock_len = sizeof(recever);
|
|
/* send alarm*/
|
|
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
|
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
|
record_log(error_str);
|
|
return;
|
|
}
|
|
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
|
//record_log(error_str);
|
|
close(sock_sd);
|
|
}
|