Merge branch 'master' of git.mesalab.cn:AV_BACKEND/frag_rssb

# Conflicts:
#	src/main.c
This commit is contained in:
dumeijied
2018-10-09 11:06:08 +08:00
25 changed files with 1567 additions and 23 deletions

View File

@@ -19,7 +19,7 @@
#include "hard_keepalive.h"
int udp_socket_recv(int sockfd, uint32_t *src_ip, uint8_t *buf, uint32_t buf_size)
int udp_socket_recv(int sockfd, uint32_t *src_ip, uint16_t *src_port, uint8_t *buf, uint32_t buf_size)
{
if (NULL == buf) return -1;
@@ -32,7 +32,8 @@ int udp_socket_recv(int sockfd, uint32_t *src_ip, uint8_t *buf, uint32_t buf_siz
perror("recvfrom");
return -1;
}
*src_ip = ((struct sockaddr_in *)&their_addr)->sin_addr.s_addr;
*src_ip = ((struct sockaddr_in *)&their_addr)->sin_addr.s_addr;
*src_port = ((struct sockaddr_in *)&their_addr)->sin_port;
return numbytes;
}
@@ -92,17 +93,6 @@ int create_recv_udp_socket(uint16_t port)
return sockfd;
}
int create_send_udp_socket()
{
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (-1 == sockfd)
{
return -1;
}
return sockfd;
}
void* thread_hard_keepalive(void *param)
{
char buf[1500] = {0};
@@ -110,12 +100,12 @@ void* thread_hard_keepalive(void *param)
bfd_port_t* bfd_port = (bfd_port_t*)param;
int size = 0;
uint32_t src_ip = 0;
uint16_t src_port = 0;
int send_rec = 0;
fd_set rset;
int recv_pkt_sd = create_recv_udp_socket(htons(bfd_port->recv_port));
int send_pkt_sd = create_send_udp_socket();
if(-1==recv_pkt_sd || -1==send_pkt_sd)
if(-1==recv_pkt_sd)
{
printf("hard_keepalive create socket error.\n");
return NULL;
@@ -131,16 +121,16 @@ void* thread_hard_keepalive(void *param)
}
if(FD_ISSET(recv_pkt_sd, &rset))
{
size = udp_socket_recv(recv_pkt_sd, &src_ip, (unsigned char*)buf, sizeof(buf));
size = udp_socket_recv(recv_pkt_sd, &src_ip, &src_port, (unsigned char*)buf, sizeof(buf));
if(size>0)
{
/*<2A><><EFBFBD><EFBFBD>discriminator*/
memcpy(discriminator_temp, buf+MY_ID_OFFSET, ID_SIZE);
memcpy(buf+MY_ID_OFFSET, buf+YOUR_ID_OFFSET, ID_SIZE);
memcpy(buf+YOUR_ID_OFFSET, discriminator_temp, ID_SIZE);
send_rec = udp_socket_send(send_pkt_sd,
send_rec = udp_socket_send(recv_pkt_sd,
src_ip,
htons(bfd_port->send_port),
src_port,
(char*)buf,size);
if(-1==send_rec)
{

View File

@@ -43,7 +43,7 @@ const char* frag_rssb_version_time = "2018-08-13T09:00:00";
const char* frag_rssb_version_des = "MESA@iie rssb_maskey";
int FRAG_RSSB_VERSION_1_0_20181008 = 0;
const char* frag_rssb_version_time_in = "2018-09-27";
const char* frag_rssb_version_time_in = "2018-10-08";
const char* frag_rssb_version_des_in = "hard balance";
void frag_rssb_history()
{
@@ -756,7 +756,6 @@ int read_conf_and_init(const char* filename)
MESA_load_profile_uint_def(filename, "WLB", "wlb_report_interval", (unsigned int*)&g_frag_cfg.wlb_report_interval,10);
MESA_load_profile_uint_def(filename, "WLB", "enable_override", (unsigned int*)&g_frag_cfg.enable_override,0);
MESA_load_profile_uint_def(filename, "WLB", "bfd_recv_port", (unsigned int*)&g_frag_cfg.bfd_recv_port,0);
MESA_load_profile_uint_def(filename, "WLB", "bfd_send_port", (unsigned int*)&g_frag_cfg.bfd_send_port,0);
/*send bizman :<3A><>ƴװ<C6B4><D7B0>ǰ<EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>˿<EFBFBD>*/
MESA_load_profile_short_def(filename, "NETWORK", "BizmanAckPort", (short*)&g_frag_cfg.bizman_ack_port,22084);
@@ -1297,11 +1296,10 @@ int main(int argc, char **argv)
}
}
if(g_frag_cfg.bfd_recv_port>0 && g_frag_cfg.bfd_send_port>0)
if(g_frag_cfg.bfd_recv_port>0)
{
bfd_port_t bfd_port;
bfd_port.recv_port = g_frag_cfg.bfd_recv_port;
bfd_port.send_port = g_frag_cfg.bfd_send_port;
hard_keepalive_run(&bfd_port);
}

View File

@@ -242,7 +242,6 @@ typedef struct frag_rssb_configure_s
int16_t save_media;
uint32_t bfd_recv_port;
uint32_t bfd_send_port;
}frag_rssb_configure_t;
typedef struct frag_rssb_status_s

View File

@@ -0,0 +1,198 @@
#ifndef _AV_SENDBACK_H
#define _AV_SENDBACK_H
/*ħ<><C4A7>*/
#define AV_MAGIC_VALUE 0x8739
/*<2A><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>*/
#define AV_TYPE_META 0x01
#define AV_TYPE_DATA 0x02
#define AV_TYPE_RESULT 0x11
/*Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define PROTOCOL_DEFAULT 0x00
#define PROTOCOL_HTTP 0x01
#define PROTOCOL_SMTP 0x02
#define PROTOCOL_POP3 0x03
#define PROTOCOL_IMAP 0x04
#define PROTOCOL_FTP 0x05
#define PROTOCOL_HTTP_PIC 0x06
#define PROTOCOL_RTSP_RDT 0x07
#define PROTOCOL_RTSP_RTP 0x08
#define PROTOCOL_MMS 0x09
#define PROTOCOL_RTMP 0x0A
#define PROTOCOL_SIP 0x0B
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_UNKNOWN 0x00
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>Ƶ֧<C6B5>ֵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_VIDEO 0x01
#define MEDIA_TYPE_WMV 0x02
#define MEDIA_TYPE_MPG 0x03
#define MEDIA_TYPE_FLV 0x04
#define MEDIA_TYPE_RMFF 0x05
#define MEDIA_TYPE_AVI 0x06
#define MEDIA_TYPE_SWF 0x07
#define MEDIA_TYPE_MPG4 0x08
#define MEDIA_TYPE_AIFF 0x09
#define MEDIA_TYPE_OGG 0x0A
#define MEDIA_TYPE_DRC 0x0B
#define MEDIA_TYPE_DIRECTSHOW 0x0C
#define MEDIA_TYPE_FLIC 0x0E
#define MEDIA_TYPE_INDEO 0x0F
#define MEDIA_TYPE_MKV 0x10
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>Ƶ֧<C6B5>ֵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_AUDIO 0x20
#define MEDIA_TYPE_MP3 0x21
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:ͼƬ֧<C6AC>ֵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_IMAGE 0x30
#define MEDIA_TYPE_JPG 0x31
#define MEDIA_TYPE_BMP 0x32
#define MEDIA_TYPE_GIF 0x33
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:ʵʱ<CAB5><CAB1>ý<EFBFBD><C3BD>֧<EFBFBD>ֵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_MMS 0x40
#define MEDIA_TYPE_RTSP_RDT 0x41
#define MEDIA_TYPE_RTSP_RTP 0x42
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ֧<C6B5>ֵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_OSMF 0x50
#define MEDIA_TYPE_HLS 0x51
/*ý<><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:VOIP֧<50>ֵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><E0BCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MEDIA_TYPE_AUDIO_UNKNOWN 0x60
#define MEDIA_TYPE_AUDIO_G711_ULAW 0x61
#define MEDIA_TYPE_AUDIO_G711_ALAW 0x62
#define MEDIA_TYPE_AUDIO_G722 0x63
#define MEDIA_TYPE_AUDIO_G723 0x64
#define MEDIA_TYPE_AUDIO_G726_40 0x65
#define MEDIA_TYPE_AUDIO_G726_32 0x66
#define MEDIA_TYPE_AUDIO_G726_24 0x67
#define MEDIA_TYPE_AUDIO_G726_16 0x68
#define MEDIA_TYPE_AUDIO_AAL2_G726_40 0x69
#define MEDIA_TYPE_AUDIO_AAL2_G726_32 0x6A
#define MEDIA_TYPE_AUDIO_AAL2_G726_24 0x6B
#define MEDIA_TYPE_AUDIO_AAL2_G726_16 0x6C
#define MEDIA_TYPE_AUDIO_G728 0x6D
#define MEDIA_TYPE_AUDIO_G729D 0x6E
#define MEDIA_TYPE_AUDIO_G729E 0x6F
#define MEDIA_TYPE_AUDIO_GSM 0x70
#define MEDIA_TYPE_AUDIO_GSM_EFR 0x71
#define MEDIA_TYPE_AUDIO_ILBC 0x72
#define MEDIA_TYPE_AUDIO_AMR 0x73
#define MEDIA_TYPE_AUDIO_AMR_WB 0x74
#define MEDIA_TYPE_AUDIO_SILK 0x75
#define MEDIA_TYPE_AUDIO_LPC 0x76
#define MEDIA_TYPE_AUDIO_LPC1016 0x77
#define MEDIA_TYPE_AUDIO_LPC1015 0x78
#define MEDIA_TYPE_AUDIO_L16 0x79
#define MEDIA_TYPE_AUDIO_SPEEX 0x7A
#define MEDIA_TYPE_AUDIO_L8 0x7B
#define MEDIA_TYPE_AUDIO_MPA 0x7C
#define MEDIA_TYPE_AUDIO_DVI4 0x7D
#define MEDIA_TYPE_AUDIO_VDVI 0x7E
#define MEDIA_TYPE_AUDIO_CN 0x7F
#define MEDIA_TYPE_AUDIO_RED 0x80
#define MEDIA_TYPE_AUDIO_QCELP 0x81
#define MEDIA_TYPE_AUDIO_EVRC0 0x82
#define MEDIA_TYPE_AUDIO_EVRCB0 0x83
#define MEDIA_TYPE_AUDIO_G729 0x84
#define MEDIA_TYPE_AUDIO_VIVOX 0x85
/*ָ<><D6B8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
/*ָ<><D6B8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-VOIPѡ<50><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define OPT_SIP_SEND_RATE_INFO 0x71 /*VOIP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
/*==================================<3D><>Ϣͷ<CFA2><CDB7>==============================================*/
typedef struct msg_head_s
{
uint16_t magic;
uint16_t m_type;
uint32_t c_len; //<2F><>Ϣ<EFBFBD><EFBFBD><E5B3A4>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣͷ<CFA2><CDB7>)
}msg_head_t;
/*==================================ָ<><D6B8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>==============================================*/
typedef struct msg_meta_s
{
char pid[8]; //ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD>ȡ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
uint64_t proglen; //<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڳ<D6BD><DAB3>ȣ<EFBFBD>Ϊ0<CEAA><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>δ֪
uint32_t capip; // <20><>ȡ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>IP
uint8_t protocol; // <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t mediatype; // <20><><EFBFBD>ܵ<EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t data_flag; // <20><><EFBFBD>ݱ<EFBFBD>־
uint8_t opt_num; // ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}msg_meta_t;
/*<2A>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><E6B6A8><EFBFBD><EFBFBD>
struct opt_unit_t
{
uint32_t opt_len; //<2F><><EFBFBD><EFBFBD>opt_len<65><6E>opt_type<70><65>opt_value
uint8_t opt_type;
char* opt_value;
};
*/
/*==================================<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>==============================================*/
typedef struct av_data_s
{
char pid[8]; // <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD>ȡ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
uint16_t frag_seq; // <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Ƭ:Ƭ<><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> VOIP:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int64_t offset:48; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>е<EFBFBD>ƫ<EFBFBD><C6AB>λ<EFBFBD><CEBB>
//char* avs; // <20><>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}av_data_t;
/*VOIP<49><50>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ*/
struct voip_header_t
{
uint32_t time_stamp; // <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint32_t sequence;
//char* data; //VOIP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
/*RTSP/RTMP<4D><50>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ*/
struct sdp_data_packet
{
char sdp[8]; // <20><>Ϊ"RTSP_SDP"
uint32_t sdp_len; // Ϊsdp<64><70><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//char * data; // sdp<64><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
/*RTSP sdp<64><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ*/
struct rtsp_data_packet
{
uint32_t flag; // RTSP<53><50><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ͷ<EFBFBD><CDB7>־ 0x46464646 "FFFF"
uint8_t type; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>1 for RDT<44><54>2 for RTP
uint8_t channel; // <20><><EFBFBD>ݵ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>
uint16_t len; // <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//char * data; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
/*RTMP sdp<64><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ*/
struct rtmp_data_packet
{
uint32_t flag; // RTMP<4D><50><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ͷ<EFBFBD><CDB7>־ 0x52544D50"RTMP"
uint32_t av_type:8; // <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ͣ<EFBFBD>8 for Audio, 9 for Video
uint32_t cs_id:24; // Chunk Stream ID
uint32_t timestamp; // ʱ<><CAB1><EFBFBD><EFBFBD>
uint32_t len; // <20><><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ֶγ<D6B6><CEB3>ȣ<EFBFBD>20<32>ֽ<EFBFBD>)
uint32_t stream_id; // <20><>ID
//char * data; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
/*MMS<4D><53>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ*/
struct mms_data_packet
{
uint32_t frame_flag; // <20><>Ϊ0x46464646 "FFFF"
uint32_t data_len; // Ϊ<><CEAA><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//char * data; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>H<EFBFBD><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>D<EFBFBD><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
};
/*==================================<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>==================================================*/
typedef struct msg_result_s
{
char pid[8]; // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD>ȡ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
int servicetype; // ҵ<><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint32_t cfgid; // <20><><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>ID<49><44>ֵΪ0<CEAA><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>δ֪<CEB4><D6AA><EFBFBD><EFBFBD>
int8_t level; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷȣ<C5B6> [0, 100]
uint8_t pad[7]; // Ԥ<><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//char* logindex; // <20><><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ĵ洢·<E6B4A2><C2B7>URL<52><4C><EFBFBD><EFBFBD>"/0"<22><><EFBFBD><EFBFBD>
}msg_result_t;
#endif

View File

@@ -0,0 +1,41 @@
# CREATED by Guo Le, 08/23/2010
#
CC = gcc
PROGRAM = sendsurvey
CFLAGS = -g -Wall
INCLUDE = -I. -I./common
LDFLAGS = -lpthread -Wall
OBJS = backend.o
DEPLOY_DIR = /home/ictsoft/fake_backend
BUILD_DIR = ./debug
.PHONY : all clean
all: $(PROGRAM)
sendsurvey: sendsurvey.c
gcc $(INCLUDE) $(LDFLAGS) -g -Wall sendsurvey.c common.a -o sendsurvey
$(OBJS): %.o: %.c
$(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@
clean:
$(RM) *.o $(PROGRAM)
localdeploy: $(PROGRAM)
@echo "- Kill previous process ---------------------------------------------"
@-killall -vq backend_video backend_audio;
@echo "---------------------------------------------------------------------"
@echo "- Check deploy dir --------------------------------------------------"
@if [ ! -d "$(DEPLOY_DIR)" ]; \
then echo "DEPLOY_DIR doesn't exist!"; mkdir -p $(DEPLOY_DIR); \
else echo "DEPLOY_DIR exist, remove all"; fi
@-rm -rfv $(DEPLOY_DIR)/*
@echo "---------------------------------------------------------------------"
@echo "- Deploy ------------------------------------------------------------"
@cp -rv $(BUILD_DIR)/* $(DEPLOY_DIR)
@echo "---------------------------------------------------------------------"
@echo "- Run ---------------------------------------------------------------"
@cd $(DEPLOY_DIR); ./r2;
@ps au | grep -e "backend" | grep -v grep

Binary file not shown.

View File

@@ -0,0 +1,24 @@
# CREATED by Guo Le, 08/23/2010
#
CC = gcc
PROGRAM =
CFLAGS = -g -Wall -D_DEBUG_
LDFLAGS =
OBJS = input.o output.o loadprof.o log.o error.o ioctl_op.o
.PHONY : all clean
all: common.a
$(OBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
common.a: $(OBJS)
ar -r $@ $^
cp $@ ../preprocessor/lib/libcommon.a
cp $@ ../pktgen
clean:
$(RM) *.o common.a

View File

@@ -0,0 +1,25 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef _DEBUG_
#define DEBUG_MESSAGE(msg) \
fprintf(stderr, "[Debug]: %s(%d) " msg "\n", __FILE__, __LINE__)
#define DEBUG_PRINTF(fmt,...) \
fprintf(stderr, "[Debug]: %s(%d) " fmt, __FILE__, __LINE__, __VA_ARGS__)
#else
#define DEBUG_MESSAGE(msg)
#define DEBUG_PRINTF(fmt,...)
#endif /* _DEBUG_ */
#ifdef _DEBUG_VERBOSE_
#define DEBUG_WRAP(msg) msg
#else
#define DEBUG_WRAP(msg)
#endif /* _DEBUG_VERBOSE_ */
#endif // #define _DEBUG_H_

View File

@@ -0,0 +1,25 @@
// error.c
//
//
//
// MODIFIED by
// CREATED by Guo Le, 09/16/2010
#include "error.h"
int error_flags = 0;
void setabort()
{
error_flags |= ERROR_FLAG_ABORT;
}
void unsetabort()
{
error_flags &= ~ERROR_FLAG_ABORT;
}
int isabort()
{
return error_flags & ERROR_FLAG_ABORT ? 1 : 0;
}

View File

@@ -0,0 +1,17 @@
#ifndef _ERROR_H_
#define _ERROR_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#define ERROR_FLAG_ABORT 0x1
#define ERROR_MESSAGE(msg) \
fprintf(stderr, "[Error]: " msg "\n")
void setabort();
void unsetabort();
int isabort();
#endif // #define _DEBUG_H_

View File

@@ -0,0 +1,114 @@
// input.c
//
//
//
// MODIFIED by
// CREATED by Guo Le, 09/11/2010
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/un.h>
#include <stddef.h>//offsetof
#include "input.h"
int input_udp_init(uint16_t port)
{
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (-1 == sockfd) {
//DEBUG_PRINTF("listener: socket %s", strerror());
perror("listener: socket");
return -1;
}
struct sockaddr_in my_addr; /* my address information */
my_addr.sin_family = AF_INET; /* host byte order */
my_addr.sin_port = port; /* short, network byte order */
my_addr.sin_addr.s_addr = INADDR_ANY; /* auto-fill with my IP */
bzero(&(my_addr.sin_zero), 8); /* zero the rest of the struct */
if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
//DEBUG_PRINTF("listener: bind %s", strerror());
perror("listener: bind");
close(sockfd);
return -1;
}
/*
if(fcntl(sockfd, F_SETFL, O_NONBLOCK) == -1) {
close(sockfd);
perror("fcntl");
return -1;
}
*/
return sockfd;
}
void input_udp_clear(int sockfd)
{
close(sockfd);
}
int input_udp_recv(int sockfd, uint32_t *src_ip, uint8_t *buf, uint32_t buf_size)
{
if (NULL == buf)
return -1;
int numbytes;
struct sockaddr_storage their_addr;
socklen_t addr_len = sizeof their_addr;
//printf("listener: waiting to recvfrom...\n");
if ((numbytes = recvfrom(sockfd, buf, buf_size , 0,
(struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
return -1;
}
*src_ip = ((struct sockaddr_in *)&their_addr)->sin_addr.s_addr;
return numbytes;
}
int init_input_un_socket(const char* file_name)
{
int sd=-1;
int len;
struct sockaddr_un un;
if(strlen(file_name)+8>sizeof(un.sun_path))
{
printf("Unix-domain socket file name too long.\n");
return -1;
}
sd=socket(AF_UNIX,SOCK_DGRAM,0);
if(sd<0)
{
printf("Get Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
memset(&un,0,sizeof(un));
un.sun_family=AF_UNIX;
snprintf(un.sun_path,sizeof(un.sun_path),"%s",file_name);
len=offsetof(struct sockaddr_un,sun_path)+strlen(un.sun_path);
unlink(un.sun_path);
if(0>bind(sd,(struct sockaddr*)&un,len))
{
printf("Bind Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
return sd;
}
int named_unix_domain_socket_recv(int un_sd,char*buf,int buf_len)
{
int recv_len=0;
struct sockaddr_storage sa;
socklen_t sa_len;
recv_len=recvfrom(un_sd,buf,buf_len,0,(struct sockaddr*)&sa,&sa_len);
return recv_len;
}

View File

@@ -0,0 +1,13 @@
#ifndef _INPUT_H_
#define _INPUT_H_
#include <stdint.h>
int input_udp_init(uint16_t port);
void input_udp_clear(int sockfd);
int input_udp_recv(int sockfd, uint32_t *src_ip, uint8_t *buf, uint32_t buf_size);
int init_input_un_socket(const char* file_name);
int named_unix_domain_socket_recv(int un_sd,char*buf,int buf_len);
#endif /* _INPUT_H_ */

View File

@@ -0,0 +1,45 @@
// ioctl_op.c
//
//
//
// MODIFIED by
// CREATED by Guo Le, 11/29/2010
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include "debug.h"
unsigned int getipbyifname(const char *ifname)
{
int sockfd;
struct ifreq ifr;
unsigned int ip;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (-1 == sockfd) {
perror("socket");
goto error;
}
strcpy(ifr.ifr_name,ifname);
if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) {
perror("ioctl");
goto error;
}
ip = ((struct sockaddr_in*)&(ifr.ifr_addr))->sin_addr.s_addr;
close(sockfd);
return ip;
error:
close(sockfd);
return INADDR_NONE;
}

View File

@@ -0,0 +1,6 @@
#ifndef _IOCTL_OP_H_
#define _IOCTL_OP_H_
unsigned int getipbyifname(const char *ifname);
#endif /*_IOCTL_OP_H_*/

View File

@@ -0,0 +1,452 @@
// loadprof.c
//
// general routines to read in profile
//
// CREATED by Guo Le, 2010-12-15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <ctype.h>
#include "loadprof.h"
#ifdef WIN32
#define strncasecmp(x,y,z) memicmp(x,y,z)
#endif
// seek specified section in initialization file,
// file read pointer at beginning of next line
//
// Return:
// >= 0 : success
// < 0 : error
static int seek_section(
FILE *fp, // [IN] initialization file descriptor
const char *section) // [IN] section name in initialization file
{
char line[MAX_PROF_LINE];
unsigned int i, j;
char *pc;
i = strlen(section);
while (NULL != fgets(line, MAX_PROF_LINE, fp)) {
pc = line;
while (' ' == *pc || '\t' == *pc)
pc++; // cut prefixal space chars
if (SECTION_PRE != *pc)
continue;
pc ++;
j = strlen(pc);
if (j < (i + 1) || SECTION_POST != pc[i])
continue;
if (strncasecmp(section, pc, i))
continue;
return 0;
}
return -1;
}
// seek specified key in initialization file
//
// Return:
// >= 0 : success
// < 0 : error
static int seek_key(
FILE *fp, // [IN] initialization file descriptor
const char *key, // [IN] key name in initialization file
char *line) // [OUT] key value string
{
unsigned int i, j;
char *pc;
i = strlen(key);
*line = '\0';
while (NULL != fgets(line, MAX_PROF_LINE, fp)) {
pc = line;
while (' ' == *pc || '\t' == *pc)
pc++; // cut prefixal space chars
if (SECTION_PRE == *pc) // next section
return -1;
j = strlen(pc);
if (j < i)
continue;
if (strncasecmp(key, pc, i))
continue;
pc += i;
while (' ' == *pc || '\t' == *pc)
pc++;
if (VALUE_SET != *pc)
continue;
pc++;
j = strlen(pc);
if (j < 1)
return 0;
memmove(line, pc, j);
line[j] = '\0';
return 1;
}
return -1;
}
// Read in specified integer value
//
// Return:
// >= 0 : success
// < 0 : error, val is set to default
int profile_read_int(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
int *val, // [OUT] returned value
int dval) // [IN] default value
{
char line[MAX_PROF_LINE];
FILE *fp;
*val = dval;
fp = fopen(file, "r");
if (NULL == fp)
return -1;
if (seek_section(fp, section) < 0) {
fclose(fp);
return -2;
}
if (seek_key(fp, key, line) < 0) {
fclose(fp);
return -3;
}
*val = strtol(line, NULL, 0);
return 0;
}
// Read in specified unsigned integer value
//
// Return:
// >= 0 : success
// < 0 : error, val is set to default
int profile_read_uint(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
unsigned int *val, // [OUT] returned value
unsigned int dval) // [IN] default value
{
char line[MAX_PROF_LINE];
FILE *fp;
*val = dval;
fp = fopen(file, "r");
if (NULL == fp)
return -1;
if (seek_section(fp, section) < 0) {
fclose(fp);
return -2;
}
if (seek_key(fp, key, line) < 0) {
fclose(fp);
return -3;
}
*val = strtoul(line, NULL, 0);
return 0;
}
// Read in specified string value,
// if value string is too long to return, extra chars truncated.
// prefix/postfix space chars cutted,
// space chars: ' ', '\t'
//
// Return:
// >= 0 : length of val
// < 0 : error, str is set to default
int profile_read_string(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
char *str, // [OUT] returned string
size_t size, // [IN] buffer size(bytes)
const char *dstr) // [IN] default string
{
char line[MAX_PROF_LINE];
FILE *fp;
size_t i;
char *pc;
if (0 == size) {
*str = '\0';
return 0;
}
i = strlen(dstr);
if (i > size - 1) {
return -1;
}
strcpy(str, dstr);
fp = fopen(file, "r");
if (NULL == fp)
return -1;
if (seek_section(fp, section) < 0) {
fclose(fp);
return -2;
}
if (seek_key(fp, key, line) < 0) {
fclose(fp);
return -3;
}
fclose(fp);
pc = line;
while (' ' == *pc || '\t' == *pc)
pc++; // cut prefixal space chars
i = strlen(pc);
if (i < 1)
return 0;
if ('\n' == pc[i - 1])
i --; // cut pending '\n'
while (' ' == pc[i - 1] || '\t' == pc[i - 1]) {
i --; // cut pending space chars
if (i < 1) {
*str = '\0';
return 0;
}
}
if (i > size - 1)
i = size - 1; // truncate extra chars
memcpy(str, pc, i);
str[i] = '\0';
return i;
}
int profile_read_nbyte_hex(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
unsigned char *bytes,
size_t size) // [IN] buffer size(bytes)
{
char str[MAX_PROF_LINE];
if (profile_read_string(file, section, key, str, MAX_PROF_LINE, "") < 0)
return 0;
char *p = str;
uint8_t num;
size_t count = 0;
while (0 != *p) {
if (strncasecmp("0x", p, 2)) break;
p += 2;
num = 0;
while((*p >= '0' && *p <= '9') ||
(*p >= 'a' && *p <= 'f') ||
(*p >= 'A' && *p <= 'F')) {
if (*p >= 'a' && *p <= 'f')
num = num * 16 + (*p - 'a' + 10);
else if (*p >= 'A' && *p <= 'F')
num = num * 16 + (*p - 'A' + 10);
else
num = num * 16 + (*p - '0');
p++;
}
bytes[count++] = num;
if (count == size) break;
while (' ' == *p || '\t' == *p || SEP_ITEM == *p) p++;
}
return count;
}
//
// Return:
// >= 0 : num of successfully converted network address.
// < 0 : error,
int profile_read_naddr(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
addr4_t *addrs, // [OUT] returned string
size_t size) // [IN] buffer size(num of addr4_t)
{
char str[MAX_PROF_LINE];
if (profile_read_string(file, section, key, str, MAX_PROF_LINE, "") < 0)
return 0;
char *s, *e;
char buf[20];
in_addr_t ip;
e = str;
size_t count = 0;
while ('\0' != *e) {
s = e;
while((*e >= '0' && *e <= '9') || '.' == *e) e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
if (inet_pton(AF_INET, buf, &ip) <= 0)
break;
addrs[count].s_addr = ip;
while (' ' == *e || '\t' == *e || SEP_IP_PORT == *e) e++;
s = e;
while(*e >= '0' && *e <= '9') e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
addrs[count].sin_port = htons(atoi(buf));
if (++count == size)
break;
while (' ' == *e || '\t' == *e || SEP_ITEM == *e) e++;
}
return count;
}
int profile_read_naddrdev(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
addr4dev_t *addrdevs, // [OUT] returned string
size_t size) // [IN] buffer size(num of addr4_t)
{
char str[MAX_PROF_LINE];
if (profile_read_string(file, section, key, str, MAX_PROF_LINE, "") < 0)
return 0;
char *s, *e;
char buf[20];
in_addr_t ip;
e = str;
size_t count = 0;
while ('\0' != *e) {
s = e;
while((*e >= '0' && *e <= '9') || '.' == *e) e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
if (inet_pton(AF_INET, buf, &ip) <= 0)
break;
addrdevs[count].s_addr = ip;
while (' ' == *e || '\t' == *e || SEP_IP_PORT == *e) e++;
s = e;
while(*e >= '0' && *e <= '9') e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
addrdevs[count].sin_port = htons(atoi(buf));
while (' ' == *e || '\t' == *e || SEP_IP_PORT == *e) e++;
s = e;
while(!isspace(*e) && SEP_ITEM != *e) e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
strcpy(addrdevs[count].dev, buf);
if (++count == size)
break;
while (' ' == *e || '\t' == *e || SEP_ITEM == *e) e++;
}
return count;
}
int profile_read_nstring(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
char *strings, // [OUT] returned string
size_t string_size,
size_t string_num) // [IN] buffer size(num of strigns)
{
int count=0;
char str[MAX_PROF_LINE];
if (profile_read_string(file, section, key, str, MAX_PROF_LINE, "") < 0)
return 0;
char* string_begin=str;
char* string_end=strchr(string_begin,',');
while(string_end!=NULL&&string_num>count)
{
memcpy(strings+count*string_size,string_begin,string_end-string_begin);
count++;
string_begin=string_end+1;
string_end=strchr(string_end+1,',');
}
memcpy(strings+count*string_size,string_begin,strlen(str)-(string_begin-str));
count++;
return count;
}
//
// Return:
// >= 0 : num of successfully converted network address.
// < 0 : error,
int profile_read_nip(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
in_addr_t *ips, // [OUT] returned string
size_t size)// [IN] buffer size(num of in_addr_t)
{
char str[MAX_PROF_LINE];
if (profile_read_string(file, section, key, str, MAX_PROF_LINE, "") < 0)
return 0;
char *s, *e;
char buf[20];
in_addr_t ip;
e = str;
size_t count = 0;
while ('\0' != *e) {
s = e;
while((*e >= '0' && *e <= '9') || '.' == *e) e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
if (inet_pton(AF_INET, buf, &ip) <= 0)
break;
ips[count] = ip;
if (++count == size)
break;
while (' ' == *e || '\t' == *e || SEP_ITEM == *e) e++;
}
return count;
}
//
// Return:
// >= 0 : num of successfully converted network address.
// < 0 : error,
int profile_read_nport(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
in_port_t *ports, // [OUT]
size_t size)// [IN] buffer size
{
char str[MAX_PROF_LINE];
if (profile_read_string(file, section, key, str, MAX_PROF_LINE, "") < 0)
return 0;
char *s, *e;
char buf[20];
e = str;
size_t count = 0;
while ('\0' != *e) {
s = e;
while((*e >= '0' && *e <= '9') || '.' == *e) e++;
strncpy(buf, s, e-s);
buf[e-s] = 0;
ports[count] = htons(atoi(buf));
if (++count == size)
break;
while (' ' == *e || '\t' == *e || SEP_ITEM == *e) e++;
}
return count;
}

View File

@@ -0,0 +1,120 @@
#ifndef SLIB_LOADPROF_H
#define SLIB_LOADPROF_H
#include <netinet/in.h>
#define MAX_PROF_LINE 1024 /* MAX bytes in a single line */
#define COMMENT_CHAR '#' /* comments line prefix */
#define SECTION_PRE '[' /* section name prefix */
#define SECTION_POST ']' /* section name postfix */
#define VALUE_SET '=' /* set key value operator */
#define SEP_ITEM ','
#define SEP_IP_PORT ':'
typedef struct addr4 {
in_addr_t s_addr;
in_port_t sin_port;
in_port_t __align;
} addr4_t;
#define DEV_NAME_MAX 10
typedef struct addr4dev {
in_addr_t s_addr;
in_port_t sin_port;
char dev[DEV_NAME_MAX];
} addr4dev_t;
// Read in specified integer value
//
// Return:
// >= 0 : success
// < 0 : error, val is set to default
int profile_read_int(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
int *val, // [OUT] returned value
int dval); // [IN] default value
// Read in specified unsigned integer value
//
// Return:
// >= 0 : success
// < 0 : error, val is set to default
int profile_read_uint(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
unsigned int *val, // [OUT] returned value
unsigned int dval); // [IN] default value
// Read in specified string value,
// if value string is too long to return, extra chars truncated.
// prefix/postfix space chars cutted,
// space chars: ' ', '\t'
//
// Return:
// >= 0 : length of val
// < 0 : error, str is set to default
int profile_read_string(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
char *str, // [OUT] returned string
size_t size, // [IN] buffer size(bytes)
const char *dstr); // [IN] default string
int profile_read_nbyte_hex(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
unsigned char *bytes,
size_t size); // [IN] buffer size(bytes)
int profile_read_naddr(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
addr4_t *addrs, // [OUT] returned string
size_t size); // [IN] buffer size(num of addr4_t)
int profile_read_naddrdev(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
addr4dev_t *addrdevs, // [OUT] returned string
size_t size); // [IN] buffer size(num of addr4_t)
int profile_read_nip(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
in_addr_t *ips, // [OUT] returned string
size_t size); // [IN] buffer size(num of in_addr_t)
// Return:
// >= 0 : num of successfully converted network address.
// < 0 : error,
int profile_read_nport(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
in_port_t *ports, // [OUT]
size_t size);// [IN] buffer size
int profile_read_nstring(
const char *file, // [IN] initialization file path
const char *section, // [IN] section name in initialization file
const char *key, // [IN] keyword name in initialization file
char *strings, // [OUT] returned string
size_t string_size,
size_t string_num);
#endif /* #ifndef SLIB_LOADPROF_H */

View File

@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include "log.h"
FILE *log_init(const char *fname)
{
FILE *fp = fopen(fname,"ab+");
if (!fp) {
fprintf(stderr, "log init error: %s\n", strerror(errno));
exit(0);
}
return fp;
}
void log_clear(FILE *fp)
{
if (fp)
fclose(fp);
}
void write_local_log(FILE * fp,const char *fmt,...)
{
if(!fp) return;
struct tm * now;
time_t currTime;
time(&currTime);
char strTime[32];
now = localtime(&currTime);
if(!fp) return ;
memset(strTime,0,sizeof(strTime));
strftime(strTime,sizeof(strTime),"%Y-%m-%d %H:%M:%S",now);
fprintf(fp,"%s\t",strTime);
va_list ap;
va_start(ap,fmt);
vfprintf(fp,fmt,ap);
va_end(ap);
fputc('\n',fp);
fflush(fp);
}// end of WriteLocalLog

View File

@@ -0,0 +1,12 @@
#ifndef _LOG_H_
#define _LOG_H_
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
FILE *log_init(const char *fname);
void log_clear(FILE *fp);
void write_local_log(FILE * fp,const char *fmt,...);
#endif /*_LOG_H_ */

View File

@@ -0,0 +1,206 @@
// output.c
//
//
//
// MODIFIED by
// CREATED BY Guo Le, 08/24/2010
// use sendnto instead of sendto, zhengchao@iie.ac.cn 2012-05-30
// add Unix-domain sokcet,zhengchao@iie.ac.cn 2012-06-04
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/un.h>
#include <stddef.h>//offsetof
#include "debug.h"
#include "output.h"
int output_udp_init()
{
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (-1 == sockfd) {
DEBUG_PRINTF("udpout_init: socket %s\n", strerror(errno));
return -1;
}
return sockfd;
}
void output_udp_clear(int sockfd)
{
close(sockfd);
}
// send udp packet
int output_udp_send(int sockfd, uint32_t addr, uint16_t port, uint8_t *data, int datalen)
{
struct sockaddr_in dst_addr; /* connector's address information */
dst_addr.sin_family = AF_INET; /* host byte order */
dst_addr.sin_port = port; /* short, network byte order */
dst_addr.sin_addr.s_addr = addr;
bzero(&(dst_addr.sin_zero), 8); /* zero the rest of the struct */
int to_send_len=datalen;
int already_sended_len=0;
while(to_send_len>0)
{
already_sended_len=sendto(sockfd,data,
to_send_len-already_sended_len,
0,
(struct sockaddr *)&(dst_addr),
sizeof(dst_addr));
if(already_sended_len==-1)
{
if((EAGAIN == errno)||( EINTR == errno )|| (EWOULDBLOCK==errno))
{
continue;
}
else
{
DEBUG_MESSAGE("udpout_send: loss data");
return -1;
}
}
to_send_len-=already_sended_len;
}
return already_sended_len;
}
int output_udp_init_connect(uint32_t addr, uint16_t port, char *dev)
{
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (-1 == sockfd) {
DEBUG_PRINTF("udpout_init_connect: socket %s\n", strerror(errno));
return -1;
}
struct sockaddr_in dst_addr; /* connector's address information */
dst_addr.sin_family = AF_INET; /* host byte order */
dst_addr.sin_port = port; /* short, network byte order */
dst_addr.sin_addr.s_addr = addr;
bzero(&(dst_addr.sin_zero), 8); /* zero the rest of the struct */
if (-1 == connect(sockfd, (struct sockaddr*)&dst_addr, sizeof(dst_addr)))
{
DEBUG_PRINTF("udpout_init_connect: error in connect %s\n", strerror(errno));
return -1;
}
if (dev) {
struct ifreq interface;
strncpy(interface.ifr_ifrn.ifrn_name, dev, IFNAMSIZ);
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, sizeof(interface)) < 0) {
DEBUG_PRINTF("SO_BINDTODEVICE failed %s\n", strerror(errno));
return -1;
}
}
return sockfd;
}
void output_udp_clear_connect(int sockfd)
{
close(sockfd);
}
// send udp packet
int output_udp_send_connect(int sockfd, uint8_t *data, int datalen)
{
int to_send_len=datalen;
int already_sended_len=0;
while(to_send_len>0)
{
already_sended_len= send(sockfd, data, datalen, 0);
if(already_sended_len==-1)
{
if((EAGAIN == errno)||( EINTR == errno )|| (EWOULDBLOCK==errno))
{
continue;
}
else
{
printf("udpout_send_connect: loss data %s\n",strerror(errno));
DEBUG_MESSAGE("udpout_send_connect: loss data");
return -1;
}
}
to_send_len-=already_sended_len;
}
return already_sended_len;
}
int init_output_un_socket(const char* file_name)
{
int sd=-1;
int len;
struct sockaddr_un un;
struct timeval send_timeout;
int send_buf_size=1024*1024*4;
if(strlen(file_name)+8>sizeof(un.sun_path))
{
printf("Unix-domain socket file name too long.\n");
return -1;
}
sd=socket(AF_UNIX,SOCK_DGRAM,0);
if(sd<0)
{
printf("Get Unix-domain socket error:%s\n",strerror(errno));
return -1;
}/*
flags=fcntl(sd,F_GETFL);
flags|=O_NONBLOCK;
if(fcntl(sd,F_SETFL,flags)==-1)
{
printf("Set Unix-domain socket error:%s",strerror(errno));
return -1;
}*/
send_timeout.tv_sec=0;
send_timeout.tv_usec=100000;
memset(&un,0,sizeof(un));
un.sun_family=AF_UNIX;
if(-1==setsockopt(sd,SOL_SOCKET,SO_SNDTIMEO,&send_timeout,sizeof(send_timeout)))
{
printf("Set Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
if(-1==setsockopt(sd,SOL_SOCKET,SO_SNDBUF,&send_buf_size,sizeof(send_buf_size)))
{
printf("Set Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
snprintf(un.sun_path,sizeof(un.sun_path),"%s",file_name);
len=offsetof(struct sockaddr_un,sun_path)+strlen(un.sun_path);
unlink(un.sun_path);
if(0>bind(sd,(struct sockaddr*)&un,len))
{
printf("Bind Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
return sd;
}
int named_unix_domain_socket_send(int un_sd,struct sockaddr_un *dest_un,const char*data,int datalen)
{
int to_send_len=datalen;
int already_sended_len=0;
int sock_addr_len=offsetof(struct sockaddr_un,sun_path)+strlen(dest_un->sun_path);
while(to_send_len>0)
{
already_sended_len= sendto(un_sd, data, datalen,0,(struct sockaddr*)dest_un, sock_addr_len);
if(already_sended_len==-1)
{
//DEBUG_PRINTF("Unix-domain send data: loss data %s\n",strerror(errno));
return -1;
}
to_send_len-=already_sended_len;
}
return already_sended_len;
}

View File

@@ -0,0 +1,18 @@
#ifndef _OUTPUT_H_
#define _OUTPUT_H_
#include <stdint.h>
#include <sys/un.h>
// send udp packet
int output_udp_init();
void output_udp_clear(int sockfd);
int output_udp_send(int sockfd, uint32_t addr, uint16_t port, uint8_t *data, int datalen);
int output_udp_init_connect(uint32_t addr, uint16_t port, char *dev);
void output_udp_clear_connect(int sockfd);
int output_udp_send_connect(int sockfd, uint8_t *data, int datalen);
int init_output_un_socket(const char* file_name);
int named_unix_domain_socket_send(int un_sd,struct sockaddr_un *dest_un,const char*data,int datalen);
#endif /* _OUTPUT_H_ */

Binary file not shown.

View File

@@ -0,0 +1,90 @@
//gcc -g -Wall un_server.c -o un_server
#include <stdio.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/un.h>
/*
memset(&(g_pproc->un_backend_addr),0,sizeof(g_pproc->un_backend_addr));
strcpy(g_pproc->un_backend_addr[i].sun_path,back_end_file_name);
g_pproc->un_backend_addr[i].sun_family=AF_UNIX;
*/
int init_named_unix_domain_socket(const char* file_name)
{
int sd=-1;
int len;
struct sockaddr_un un;
if(strlen(file_name)+8>sizeof(un.sun_path))
{
printf("Unix-domain socket file name too long.\n");
return -1;
}
sd=socket(AF_UNIX,SOCK_DGRAM,0);
if(sd<0)
{
printf("Get Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
memset(&un,0,sizeof(un));
un.sun_family=AF_UNIX;
snprintf(un.sun_path,sizeof(un.sun_path),"%s",file_name);
len=offsetof(struct sockaddr_un,sun_path)+strlen(un.sun_path);
unlink(un.sun_path);
if(0>bind(sd,(struct sockaddr*)&un,len))
{
printf("Bind Unix-domain socket error:%s\n",strerror(errno));
return -1;
}
return sd;
}
int named_unix_domain_socket_send(int un_sd,struct sockaddr_un *dest_un,const char*data,int datalen)
{
int to_send_len=datalen;
int already_sended_len=0;
int sock_addr_len=offsetof(struct sockaddr_un,sun_path)+strlen(dest_un->sun_path);
while(to_send_len>0)
{
already_sended_len= sendto(un_sd, data, datalen,0,(struct sockaddr*)dest_un, sock_addr_len);
if(already_sended_len==-1)
{
printf("Unix-domain send data: loss data %s\n",strerror(errno));
return -1;
}
to_send_len-=already_sended_len;
}
return already_sended_len;
}
int main()
{
int sd=-1;
char buf[2048];
int recv_len=0;
struct sockaddr_storage sa;
socklen_t sa_len;
char* recv_file_name="/home/zhengchao/recv_preproc";
unsigned long long stat_recv_bytes=0,stat_recv_pkts=0;
unsigned long long mult_tmp=0;
int i=0;
sd=init_named_unix_domain_socket(recv_file_name);
while(1)
{
recv_len=recvfrom(sd,buf,sizeof(buf),0,(struct sockaddr*)&sa,&sa_len);
stat_recv_bytes+=recv_len;
stat_recv_pkts++;
for(i=1;i<stat_recv_pkts%10;i++)
{
mult_tmp*=i;
mult_tmp%=7827368423;
}
// printf("%d %llu\n",recv_len,stat_recv_pkts);
}
}

View File

@@ -0,0 +1,8 @@
ʹ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ƴװ<C6B4><D7B0><EFBFBD>ս<EFBFBD><D5BD><EFBFBD><EFBFBD><EFBFBD>socket PID service_type configID level logurl
<EFBFBD><EFBFBD><EFBFBD>
./sendsurvey /home/mesasoft/frag_rssb/un_recv 11111111111111 37 212 100 192.168.1.1:/home/lishu/test.txt
logurl<EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>д
./sendsurvey /home/mesasoft/frag_rssb/un_recv 11111111111111111 0 0 0

Binary file not shown.

View File

@@ -0,0 +1,94 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <pthread.h>
#include "./common/output.h"
#include "AV_sendback.h"
#define BUF_SIZE 1024
#define OPT_IMG_FP 0x10
#define OPT_IMG_LEN 0x14
struct image_fp_t
{
unsigned int offset;
unsigned char fingerprint[128];
};
/***********************************************
*Function: Add option to buf,return actual add size
*Note:This function is used for 505 sendback option create.
*Author:zhengchao@iie.ac.cn
*Date:2012-11-03
***********************************************/
int add_opt_505(char *buf,unsigned int buf_len, unsigned char opt_type,const char*opt_cont,unsigned int opt_cont_len)
{
char *ptr;
unsigned int this_opt_len=sizeof(opt_type)+sizeof(unsigned int)+opt_cont_len;
if(buf==NULL||buf_len<=0)
return 0;
if(this_opt_len>buf_len)
{
return 0;
}
ptr=buf;
*(unsigned int *)ptr = opt_cont_len+sizeof(opt_type)+sizeof(opt_cont_len);
ptr += sizeof(unsigned int);
*(unsigned char *)ptr = opt_type;
ptr += sizeof(unsigned char);
memcpy(ptr, opt_cont, opt_cont_len);
return this_opt_len;
}
int main (int argc, char *argv[])
{
if(argc!=6 && argc!=7)
{
printf("input error\n");
return 0;
}
char buf_survey[BUF_SIZE] = {0};
int w_offset=sizeof(msg_head_t)+sizeof(msg_result_t);
msg_head_t *mh_survey = (msg_head_t*)buf_survey;
msg_result_t *msi_survey = (msg_result_t *)(buf_survey + sizeof(msg_head_t));
struct sockaddr_un un_backend_addr;
memset(buf_survey, 0, BUF_SIZE);
mh_survey->magic = AV_MAGIC_VALUE;
mh_survey->m_type = AV_TYPE_RESULT;
mh_survey->c_len = sizeof(msg_result_t);
*((uint64_t *)msi_survey->pid) = strtoull(argv[2], NULL, 0);
msi_survey->servicetype = atoi(argv[3]);
msi_survey->cfgid = atoi(argv[4]);
msi_survey->level = atoi(argv[5]);
int fd_survey = init_output_un_socket("./un_tmp");
if (fd_survey < 0) {
printf("socket error!");
exit(1);
}
memset(&(un_backend_addr),0,sizeof(un_backend_addr));
strcpy(un_backend_addr.sun_path,argv[1]);
un_backend_addr.sun_family=AF_UNIX;
printf("param num: %d\n", argc);
if(argc==7)
{
w_offset += 1024-strlen(argv[6]) + sprintf(buf_survey + w_offset, argv[6]);
}
else
{
w_offset += 1024;
}
printf("pid:%lu, service:%d, configID:%u, level:%d, logindex:%s\n", *((uint64_t *)msi_survey->pid), msi_survey->servicetype, msi_survey->cfgid, msi_survey->level, argv[6]);
mh_survey->c_len = w_offset-sizeof(msg_head_t);
named_unix_domain_socket_send(fd_survey,&un_backend_addr, buf_survey, w_offset);
return 0;
}