示例#1
0
int payload_splice(u_char **str, struct listhdr *l, struct payload *p, FILE *log){
	int size = 0, i = 0, start = 0;
	*str = NULL;
	while(l->pld_list != p){//先找到帧的起始标志
		start=flag_find(l->pld_list->mpld, l->pld_list->plen, 0);
		if(start!=-1 && start!=l->pld_list->plen-1){
			if(l->pld_list->mpld[start+1]==PPP_FLAG)
				start++;
			size = size + l->pld_list->plen - start;
			*str = (u_char *)realloc(*str, size*sizeof(u_char));
			for(;i<size;i++)
				(*str)[i] = l->pld_list->mpld[start+i];
			fprintf(log, "%d\t", l->pld_list->pnum);
			payload_pop(l);
			break;
		}
		fprintf(log, "%d\t", l->pld_list->pnum);
		payload_pop(l);
	}
	while(l->pld_list != p){
		size = size + l->pld_list->plen;
		*str = (u_char *)realloc(*str, size*sizeof(u_char));
		for(;i<size;i++)
			(*str)[i] = l->pld_list->mpld[l->pld_list->plen+i-size];

		//释放队列中相应单元
		fprintf(log, "%d\t", l->pld_list->pnum);
		payload_pop(l);
	}
	return size;
}
示例#2
0
int cli_parse(const int argc, const char **argv)
{
  options_init();

  flag_t *flag;
  const char *arg;
  int i;
  for (arg = argv[i=1]; i < argc; arg = argv[++i]) {
    flag = NULL;

    if (flag_is_long_flag(arg)) {
      flag = flag_find_by_name(arg+2);
    }
    else if (flag_is_short_flag(arg)) {
      flag = flag_find(arg[1]);
    }
    else if (flag_is_filename(arg)) {
      flag = flag_find_by_name("in");
      options_set_with_arg(flag, arg);
      continue;
    }

    if (!flag) {
      log_error("unknown flag \'%s\'", arg);
      return 0;
    }
    else if (flag->args > 0) {
      if (i+1 < argc)
        options_set_with_arg(flag, argv[++i]);
      else {
        log_error("flag \'%s\' needs an argument", arg);
        return 0;
      }
    }
    else {
      options_set(flag);
    }
  }

  if (options->out_filename == NULL && options->in_filename == NULL) {
    log_error("at least one filename (input or output) has to be declared");
    return 0;
  }

  log_info("parsed arguments from command line");
  return 1;
}
示例#3
0
int ppp_complt(u_char *frame, int frame_size, struct framehdr *fh, 
		struct  msidhash *mh, struct radiushash *rh, FILE *output){
	//返回获得的IP数据包个数
	int ipnum = 0, start = 0, end = 0;
	_Int16 *protocol = 0, *size = 0;
	u_char t[2];
	while(start < frame_size){
		if((end = flag_find(frame, frame_size, start+1)) == -1)
			break;
		start+=1;
		if(start != end){
			frame_escape((frame+start),end-start);
			protocol = (_Int16 *)(frame+start+2);
			switch(*protocol){
				//				case IPV4:
				//					//是IP协议说明是数据帧,进行解封装处理
				//					start+=4;
				//					t[0] = frame[start+2]; t[1] = frame[start+3];
				//					size = (_Int16 *)t;
				//					*size = short_displace(*size);
				//					fwrite(size, 1, sizeof(_Int16), output);
				//					fwrite((frame+start), 1, *size, output);
				//					ipnum++;
				//					break;
				case IPCP:
					start+=4;
					IPCP_handler((frame+start), fh, mh, rh);
					break;
				default:
					break;
			}
			start = end;
		}
	}
	return ipnum;
}