Hi, We’re running QNX RTOS 6.1a. We’re developing an ipfilter.
It seems to crash io-net when when we receive any ip packets, but only when we call our display function in the ipf_init() function that is called by io-net. The display function basically just outputs our array of rules to an output file. It seems to output the data fine.
Below is some of our code:
//this is the structure for each rule
typedef struct rule_data{
unsigned char ip_1[4];
unsigned char netmask_1;
unsigned char type;
unsigned char port[2];
unsigned char ip_2[4];
unsigned char netmask_2;
unsigned char rulemask;
unsigned char rule_no[2];
char dev[20];
}BINDATA;
BINDATA *dst_info, *src_info;
int ipf_init(void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char *options)
{
ipf_dll_hdl = dll_hdl;
ipf_ion = ion;
of=fopen("/tr/output.dat",“aw”); //open debug file
store_bin();
display(dst_info,8); <<<<----- when this function call is included the filter crashes when receiving IP packets
if(!ipf_register_filter()) //register filter with io-net
return(-1); //couldn’t register
//register what type of sub
ipf_ion->reg_byte_pat(ipf_reg_hdl, 0, 0, NULL, _BYTE_PAT_ALL);
return (0); // success
}
THESE ARE THE ONLY TWO FUNCTIONS CALLING THE POINTERS
TO THE BINDATA STRUCTURE
//stores binfile info into arrays of BINDATA allocates arrays to number of rules in file
int store_bin(void)
{
FILE *bp; //bin file pointer
int src_fd,dst_fd,i;
long size_of_file;
bp=fopen(SRC_BINFILE,“r”);
fseek(bp,0L,SEEK_END); //considering that the src and dest bin files
size_of_file = ftell(bp); //are the same size I only need to open the one
fclose(bp); //file
no_rules=size_of_file/sizeof(struct rule_data);
dst_info=(BINDATA*)malloc(no_rules); //allocate memory for #of rules in file
src_info=(BINDATA*)malloc(no_rules);; //allocate memory for #of rules in file
src_fd = open(SRC_BINFILE, O_RDONLY );
dst_fd = open(DST_BINFILE, O_RDONLY);
//read rules into BINDATA arrays
for(i=0;i<=no_rules;i++)
{
read(src_fd,&src_info_,sizeof(struct rule_data)); //read from source binary file
read(dst_fd,&dst_info,sizeof(struct rule_data)); //read from dest. bin file
}
close(src_fd);
close(dst_fd);
return(1);
}
THE DISPLAY FUNCTION
//output contents of rule array to file
void display(BINDATA *rule_info,int no_rules)
{
int i,j;
for(i=0;i<no_rules;i++)
{
fprintf(of,"–\n");
for(j=0;j<4;j++)
fprintf(of,"%d",rule_info.ip_1[j]);
fprintf(of,"%d",rule_info.netmask_1);
fprintf(of,"%d",rule_info.type);
fprintf(of,"%d",rule_info.port[0]);
fprintf(of,"%d",rule_info.port[1]);
for(j=0;j<4;j++)
fprintf(of,"%d",rule_info.ip_2[j]);
fprintf(of,"%d",rule_info.netmask_1);
fprintf(of,"%d",rule_info.rulemask);
fprintf(of,"%d",rule_info[i].rule_no[0]);
fprintf(of,"%d",rule_info[i].rule_no[1]);
fprintf(of,"%s",rule_info[i].dev);
}
fflush(of);
}
If I don’t include the display function io-net stays up and running no problem with
packets flowing through the filter. If someone could help it would be greatly appreciated.
Thanks.
QNX SLC Project Group_