summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlishu <[email protected]>2018-10-08 16:16:22 +0800
committerlishu <[email protected]>2018-10-08 16:16:22 +0800
commitdc05b5fd01b818daacd870f60238571549b7b339 (patch)
tree7c5336872519fe7f9abe68a7ff14cf277aab2e72
parentf292da01f29e8ccc7d72aad6ca13ee0e4a59c7e4 (diff)
20181008 survey_k
-rw-r--r--src/tool/sendsurvey_k/AV_sendback.h198
-rw-r--r--src/tool/sendsurvey_k/Makefile41
-rw-r--r--src/tool/sendsurvey_k/common.abin0 -> 60528 bytes
-rw-r--r--src/tool/sendsurvey_k/common/Makefile24
-rw-r--r--src/tool/sendsurvey_k/common/debug.h25
-rw-r--r--src/tool/sendsurvey_k/common/error.c25
-rw-r--r--src/tool/sendsurvey_k/common/error.h17
-rw-r--r--src/tool/sendsurvey_k/common/input.c114
-rw-r--r--src/tool/sendsurvey_k/common/input.h13
-rw-r--r--src/tool/sendsurvey_k/common/ioctl_op.c45
-rw-r--r--src/tool/sendsurvey_k/common/ioctl_op.h6
-rw-r--r--src/tool/sendsurvey_k/common/loadprof.c452
-rw-r--r--src/tool/sendsurvey_k/common/loadprof.h120
-rw-r--r--src/tool/sendsurvey_k/common/log.c49
-rw-r--r--src/tool/sendsurvey_k/common/log.h12
-rw-r--r--src/tool/sendsurvey_k/common/output.c206
-rw-r--r--src/tool/sendsurvey_k/common/output.h18
-rw-r--r--src/tool/sendsurvey_k/common/un_serverbin0 -> 12685 bytes
-rw-r--r--src/tool/sendsurvey_k/common/un_server.c90
-rw-r--r--src/tool/sendsurvey_k/readme.txt8
-rw-r--r--src/tool/sendsurvey_k/sendsurveybin0 -> 21516 bytes
-rw-r--r--src/tool/sendsurvey_k/sendsurvey.c94
22 files changed, 1557 insertions, 0 deletions
diff --git a/src/tool/sendsurvey_k/AV_sendback.h b/src/tool/sendsurvey_k/AV_sendback.h
new file mode 100644
index 0000000..e14bb7e
--- /dev/null
+++ b/src/tool/sendsurvey_k/AV_sendback.h
@@ -0,0 +1,198 @@
+#ifndef _AV_SENDBACK_H
+#define _AV_SENDBACK_H
+
+/*ħ��*/
+#define AV_MAGIC_VALUE 0x8739
+
+/*��Ϣ����*/
+#define AV_TYPE_META 0x01
+#define AV_TYPE_DATA 0x02
+#define AV_TYPE_RESULT 0x11
+
+/*������*/
+#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
+
+/*ý������*/
+#define MEDIA_TYPE_UNKNOWN 0x00
+/*ý������:��Ƶ֧�ֵ�ý������*/
+#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
+/*ý������:��Ƶ֧�ֵ�ý������*/
+#define MEDIA_TYPE_AUDIO 0x20
+#define MEDIA_TYPE_MP3 0x21
+/*ý������:ͼƬ֧�ֵ�ý������*/
+#define MEDIA_TYPE_IMAGE 0x30
+#define MEDIA_TYPE_JPG 0x31
+#define MEDIA_TYPE_BMP 0x32
+#define MEDIA_TYPE_GIF 0x33
+/*ý������:ʵʱ��ý��֧�ֵ�ý������*/
+#define MEDIA_TYPE_MMS 0x40
+#define MEDIA_TYPE_RTSP_RDT 0x41
+#define MEDIA_TYPE_RTSP_RTP 0x42
+/*ý������:��Ƭ������Ƶ֧�ֵ�ý������*/
+#define MEDIA_TYPE_OSMF 0x50
+#define MEDIA_TYPE_HLS 0x51
+/*ý������:VOIP֧�ֵ�ý�����ͣ��༴��������*/
+#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
+
+/*ָ����Ϣ��ѡ������*/
+/*ָ����Ϣ��ѡ������-VOIPѡ������*/
+#define OPT_SIP_SEND_RATE_INFO 0x71 /*VOIP���������Ϣ*/
+
+/*==================================��Ϣͷ��==============================================*/
+typedef struct msg_head_s
+{
+ uint16_t magic;
+ uint16_t m_type;
+ uint32_t c_len; //��Ϣ�峤��(��������Ϣͷ��)
+}msg_head_t;
+
+/*==================================ָ����Ϣ��==============================================*/
+typedef struct msg_meta_s
+{
+ char pid[8]; //ID�������ݻ�ȡ�ڵ�����
+ uint64_t proglen; //���ļ������ֽڳ��ȣ�Ϊ0��ʾ����δ֪
+ uint32_t capip; // ��ȡ�ڵ��IP
+ uint8_t protocol; // ����������
+ uint8_t mediatype; // ���ܵ�ý������
+ uint8_t data_flag; // ���ݱ�־
+ uint8_t opt_num; // ѡ�����
+}msg_meta_t;
+
+/*�Ѿ��������ļ����涨���
+struct opt_unit_t
+{
+ uint32_t opt_len; //����opt_len��opt_type��opt_value
+ uint8_t opt_type;
+ char* opt_value;
+};
+*/
+
+/*==================================��������Ϣ��==============================================*/
+typedef struct av_data_s
+{
+ char pid[8]; // ���ļ���ID�������ݻ�ȡ�ڵ�����
+ uint16_t frag_seq; // ����Ƶ��Ƭ:Ƭ����� VOIP:������
+ int64_t offset:48; // �����������������ļ��е�ƫ��λ��
+ //char* avs; // ��ý��������
+}av_data_t;
+
+/*VOIP��ý�������ݸ�ʽ*/
+struct voip_header_t
+{
+ uint32_t time_stamp; // ����֡��ʱ���, ������
+ uint32_t sequence;
+ //char* data; //VOIP����������
+};
+
+/*RTSP/RTMP��ý�������ݸ�ʽ*/
+struct sdp_data_packet
+{
+ char sdp[8]; // ��Ϊ"RTSP_SDP"
+ uint32_t sdp_len; // Ϊsdp�����ݳ���
+ //char * data; // sdp��������
+};
+
+/*RTSP sdp�������ݸ�ʽ*/
+struct rtsp_data_packet
+{
+ uint32_t flag; // RTSP����ͷ��ͷ��־ 0x46464646 "FFFF"
+ uint8_t type; // �������ͣ�1 for RDT��2 for RTP
+ uint8_t channel; // ���ݵ�ͨ����
+ uint16_t len; // ���ݳ���
+ //char * data; // ��������
+};
+
+/*RTMP sdp�������ݸ�ʽ*/
+struct rtmp_data_packet
+{
+ uint32_t flag; // RTMP����ͷ��ͷ��־ 0x52544D50"RTMP"
+ uint32_t av_type:8; // ����Ƶ���ͣ�8 for Audio, 9 for Video
+ uint32_t cs_id:24; // Chunk Stream ID
+ uint32_t timestamp; // ʱ���
+ uint32_t len; // �����ݳ���(������ͷ���ֶγ��ȣ�20�ֽ�)
+ uint32_t stream_id; // ��ID
+ //char * data; // ��������
+};
+
+/*MMS��ý�������ݸ�ʽ*/
+struct mms_data_packet
+{
+ uint32_t frame_flag; // ��Ϊ0x46464646 "FFFF"
+ uint32_t data_len; // Ϊ���ݳ���
+ //char * data; // ��������H���������ݻ���D����������
+};
+
+/*==================================�����Ϣ��==================================================*/
+typedef struct msg_result_s
+{
+ char pid[8]; // �����ļ���ID�������ݻ�ȡ�ڵ�����
+ int servicetype; // ҵ������
+ uint32_t cfgid; // ���е�����ID��ֵΪ0��ʾ����δ֪����
+ int8_t level; // ��������Ŷȣ� [0, 100]
+ uint8_t pad[7]; // Ԥ����������0ֵ
+ //char* logindex; // �����ֳ������ļ��Ĵ洢·��URL����"/0"����
+}msg_result_t;
+
+#endif
diff --git a/src/tool/sendsurvey_k/Makefile b/src/tool/sendsurvey_k/Makefile
new file mode 100644
index 0000000..4ccb8b2
--- /dev/null
+++ b/src/tool/sendsurvey_k/Makefile
@@ -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
diff --git a/src/tool/sendsurvey_k/common.a b/src/tool/sendsurvey_k/common.a
new file mode 100644
index 0000000..3549d78
--- /dev/null
+++ b/src/tool/sendsurvey_k/common.a
Binary files differ
diff --git a/src/tool/sendsurvey_k/common/Makefile b/src/tool/sendsurvey_k/common/Makefile
new file mode 100644
index 0000000..dcb5fc0
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/Makefile
@@ -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
+
+
diff --git a/src/tool/sendsurvey_k/common/debug.h b/src/tool/sendsurvey_k/common/debug.h
new file mode 100644
index 0000000..f0b5d3b
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/debug.h
@@ -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_
diff --git a/src/tool/sendsurvey_k/common/error.c b/src/tool/sendsurvey_k/common/error.c
new file mode 100644
index 0000000..c0bd4f1
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/error.c
@@ -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;
+}
+
+
diff --git a/src/tool/sendsurvey_k/common/error.h b/src/tool/sendsurvey_k/common/error.h
new file mode 100644
index 0000000..cd7469a
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/error.h
@@ -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_
diff --git a/src/tool/sendsurvey_k/common/input.c b/src/tool/sendsurvey_k/common/input.c
new file mode 100644
index 0000000..e697371
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/input.c
@@ -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;
+}
diff --git a/src/tool/sendsurvey_k/common/input.h b/src/tool/sendsurvey_k/common/input.h
new file mode 100644
index 0000000..e3934df
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/input.h
@@ -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_ */
diff --git a/src/tool/sendsurvey_k/common/ioctl_op.c b/src/tool/sendsurvey_k/common/ioctl_op.c
new file mode 100644
index 0000000..8fc3917
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/ioctl_op.c
@@ -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;
+}
diff --git a/src/tool/sendsurvey_k/common/ioctl_op.h b/src/tool/sendsurvey_k/common/ioctl_op.h
new file mode 100644
index 0000000..568d21e
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/ioctl_op.h
@@ -0,0 +1,6 @@
+#ifndef _IOCTL_OP_H_
+#define _IOCTL_OP_H_
+
+unsigned int getipbyifname(const char *ifname);
+
+#endif /*_IOCTL_OP_H_*/
diff --git a/src/tool/sendsurvey_k/common/loadprof.c b/src/tool/sendsurvey_k/common/loadprof.c
new file mode 100644
index 0000000..7449215
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/loadprof.c
@@ -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;
+}
diff --git a/src/tool/sendsurvey_k/common/loadprof.h b/src/tool/sendsurvey_k/common/loadprof.h
new file mode 100644
index 0000000..bd6c332
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/loadprof.h
@@ -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 */
diff --git a/src/tool/sendsurvey_k/common/log.c b/src/tool/sendsurvey_k/common/log.c
new file mode 100644
index 0000000..8400187
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/log.c
@@ -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
+
diff --git a/src/tool/sendsurvey_k/common/log.h b/src/tool/sendsurvey_k/common/log.h
new file mode 100644
index 0000000..767f646
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/log.h
@@ -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_ */
diff --git a/src/tool/sendsurvey_k/common/output.c b/src/tool/sendsurvey_k/common/output.c
new file mode 100644
index 0000000..c992a91
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/output.c
@@ -0,0 +1,206 @@
+// output.c
+//
+//
+//
+// MODIFIED by
+// CREATED BY Guo Le, 08/24/2010
+// use sendnto instead of sendto, [email protected] 2012-05-30
+// add Unix-domain sokcet,[email protected] 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;
+}
diff --git a/src/tool/sendsurvey_k/common/output.h b/src/tool/sendsurvey_k/common/output.h
new file mode 100644
index 0000000..2da9fc2
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/output.h
@@ -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_ */
diff --git a/src/tool/sendsurvey_k/common/un_server b/src/tool/sendsurvey_k/common/un_server
new file mode 100644
index 0000000..4bc61e4
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/un_server
Binary files differ
diff --git a/src/tool/sendsurvey_k/common/un_server.c b/src/tool/sendsurvey_k/common/un_server.c
new file mode 100644
index 0000000..a815c84
--- /dev/null
+++ b/src/tool/sendsurvey_k/common/un_server.c
@@ -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);
+ }
+}
+
diff --git a/src/tool/sendsurvey_k/readme.txt b/src/tool/sendsurvey_k/readme.txt
new file mode 100644
index 0000000..b2b6895
--- /dev/null
+++ b/src/tool/sendsurvey_k/readme.txt
@@ -0,0 +1,8 @@
+ʹ�÷�����
+
+������ ��ƴװ���ս����socket PID service_type configID level logurl
+���磺
+./sendsurvey /home/mesasoft/frag_rssb/un_recv 11111111111111 37 212 100 192.168.1.1:/home/lishu/test.txt
+
+logurl���Բ�д
+./sendsurvey /home/mesasoft/frag_rssb/un_recv 11111111111111111 0 0 0
diff --git a/src/tool/sendsurvey_k/sendsurvey b/src/tool/sendsurvey_k/sendsurvey
new file mode 100644
index 0000000..4df3fc7
--- /dev/null
+++ b/src/tool/sendsurvey_k/sendsurvey
Binary files differ
diff --git a/src/tool/sendsurvey_k/sendsurvey.c b/src/tool/sendsurvey_k/sendsurvey.c
new file mode 100644
index 0000000..352a62c
--- /dev/null
+++ b/src/tool/sendsurvey_k/sendsurvey.c
@@ -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.
+*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;
+}
+