返回函数值实例化参数
.c文件;
VOD_REQUEST VODrequest(void)
{
unsigned char* message_request="12,1234,192.168.9.98,55051";
int data_len=4;
int i;
printf("++++++++++++++++++++++>>>>>>>>>>>>>>>>>>vodrequest\n");
////////////////////////////////////////////////////////////string///////////////////////////////////////////////////////
char str[] = "12,1234,192.168.9.98,55056";//3232237922
char *p;
char *buff;
buff=str;
p = strsep(&buff, ",");
int index = 0;
VOD_REQUEST vr;
while(p)
{
printf("%s---%d\n", p,index);
if(index==0){
vr.vod_message_id=p;
}else if(index==1){
vr.train_num=p;
}else if(index==2){
vr.ip_addr=p;
}else if(index=3){
vr.port=atoi(p);
}
p = strsep(&buff, ",");
index++;
}
// time(&VOD_REQUEST.start);
printf("start:%s\n",vr.ip_addr);
vr.start=get_data_time();
// return vr;
#if 1
unsigned char temp[17];
unsigned short crc;
temp[0] = 0x30;
temp[1] =0x02;
temp[2] = 0x03;
temp[3] = 0x04;
temp[4] = 0x01;
temp[5] = 0x00;
temp[6] = 0xF6;
struct sockaddr_in dout;
socklen_t addr_len;
int socket_fd;
int rc;
//创建套接字
socket_fd = socket(PF_INET, SOCK_DGRAM, 0);
// 绑定
memset(&dout, 0, sizeof(dout));
dout.sin_family = AF_INET;
dout.sin_addr.s_addr = inet_addr(vr.ip_addr);
dout.sin_port = htons(vr.port);
rc= tcp_sent_vod_request(socket_fd, temp, 7, dout);
printf("socket_fd==>>%d\n",socket_fd);
printf ("rc:%d\n",rc);
return vr;
#endif
}
.h文件;
#ifndef VOD_REQUEST_HANDLE_H_
#define VOD_REQUEST_HANDLE_H_
#include "Thread_decode_apdu_handler.h"
//int VODrequest_sent(unsigned char* message_request,int data_len);
定义函数:
VOD_REQUEST VODrequest(void);
定义结构体:
typedef struct _vod_request_data{
char *start;
unsigned char *vod_message_id;
unsigned char* train_num;
const char * ip_addr;
unsigned int port;
unsigned char* data;
unsigned int data_len;
} VOD_REQUEST;
#endif /* VOD_REQUEST_HANDLE_H_ */
用法:返回函数值实例化参数;
VOD_REQUEST v = VODrequest();
unsigned char *vod_message_id=v.vod_message_id;
unsigned char *train_num=v.train_num;
char* start=v.start;
const char *ip_addr=v.ip_addr;
unsigned int port=v.port;
unsigned char*data=v.data;
unsigned int data_len=v.data_len;
printf("ipaddr:%s\n",ip_addr);
printf("port:%d\n",port);