Ejemplo n.º 1
0
static int
run_read_entry_v0(struct rldb_file_cnts *cs, int n)
{
  struct runlog_state *rls = cs->rl_state;
  char buf[RUN_RECORD_SIZE + 16];
  char tip[RUN_RECORD_SIZE + 16];
  int  k, r;
  ej_ip4_t ip;

  memset(buf, 0, sizeof(buf));
  if (run_read_record_v0(cs, buf, RUN_RECORD_SIZE) < 0) return -1;
  r = sscanf(buf, " %lld %d %u %hd %d %d %d %hhu %hd %d %s %n",
             &rls->runs[n].time, &rls->runs[n].run_id,
             &rls->runs[n].size, &rls->runs[n].locale_id,
             &rls->runs[n].user_id, &rls->runs[n].lang_id,
             &rls->runs[n].prob_id, &rls->runs[n].status,
             &rls->runs[n].test, &rls->runs[n].score, tip, &k);
  if (r != 11) ERR_R("[%d]: sscanf returned %d", n, r);
  if (buf[k] != 0) ERR_R("[%d]: excess data", n);
  if (strlen(tip) > RUN_MAX_IP_LEN) ERR_R("[%d]: ip is to long", n);
  if (xml_parse_ip(NULL, 0, 0, 0, tip, &ip) < 0) ERR_R("[%d]: cannot parse IP");
  rls->runs[n].a.ip = ip;
  return 0;
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*
 * NAME: xml_parse_packet
 * DESC: Parse the content of a PDML packet
 *---------------------------------------------------------------------------*/
void xml_parse_packet(config *conf) {

  xmlChar *name;

  /* we keep a copy of cur */
  xmlNodePtr cur = conf->cur;

  /* enter in packet */
  cur = cur->xmlChildrenNode;

  /* init the protocol counter */
  conf->proto_counter = 1;
  debug(3, "protocol counter: %d\n", conf->proto_counter);

  while (cur != NULL) {
    if (!(xmlStrcmp(cur->name, (const xmlChar *) "proto"))) {

      /* catch the name of the proto */
      name = xmlGetProp(cur, "name");

      /* geninfo type */
      if (!strncmp(name, "geninfo", strlen(name))) {
	debug(3, "retreiving geninfo informations.\n", name);
      }

      /* frame type */
      else if (!strncmp(name, "frame", strlen(name))) {
	debug(3, "retreiving frame informations.\n", name);
      }

      /* eth type */
      else if (!strncmp(name, "eth", strlen(name))) {
	debug(3, "retreiving eth informations.\n", name);
      }

      /* ip type */
      else if (!strncmp(name, "ip", strlen(name))) {
	debug(3, "retreiving ip informations.\n", name);
	xml_parse_ip(conf, cur);

      }

      /* tcp type */
      else if (!strncmp(name, "tcp", strlen(name))) {
	debug(3, "retreiving tcp informations.\n", name);

	/* the communication seems to be in tcp */
	if (!conf->transport_type)  conf->transport_type = 1;

	/* udp and tcp in the same sniff ? huh not good! */
	else if (conf->transport_type != 1) {
	  error_("UDP *AND* TCP?! Check your Ethereal logs!\n");
	  exit(-1);
	}


	/* save the port (for identification, ip is not enough (think localhost)) */
	xmlChar *value;
	unsigned short src_port;
	unsigned short dst_port;

	value = xml_parse_field(cur, 1, "tcp.srcport", "show");
	src_port = (unsigned short) atoi(value);
	xmlFree(value);

	value = xml_parse_field(cur, 1, "tcp.dstport", "show");
	dst_port = (unsigned short) atoi(value);
	xmlFree(value);

	/* save the pkt source port */
	conf->port_pkt = src_port;

	/* save the port */
	if ((conf->port_client == 0) && (conf->port_server == 0)) {
	  if (conf->ip_client == conf->ip_pkt) {
	    conf->port_client = src_port;
	    conf->port_server = dst_port;
	  }
	  if (conf->ip_server == conf->ip_pkt) {
	    conf->port_client = dst_port;
	    conf->port_server = src_port;
	  }
	}
      }

      /* udp type */
      else if (!strncmp(name, "udp", strlen(name))) {
	debug(3, "retreiving udp informations.\n", name);

	/* the communication seems to be in udp */
	if (!conf->transport_type) conf->transport_type = 2;

	/* udp and tcp in the same sniff ? huh not good! */
	else if (conf->transport_type != 2) {
	  error_("UDP *AND* TCP?! Check your Ethereal logs!\n");
	  exit(-1);
	}

	/* save the port (for identification, ip is not enough (think localhost)) */
	xmlChar *value;
	unsigned short src_port;
	unsigned short dst_port;

	value = xml_parse_field(cur, 1, "udp.srcport", "show");
	src_port = (unsigned short) atoi(value);
	xmlFree(value);

	value = xml_parse_field(cur, 1, "udp.dstport", "show");
	dst_port = (unsigned short) atoi(value);
	xmlFree(value);

	/* save the pkt source port */
	conf->port_pkt = src_port;

	/* save the port */
	if ((conf->port_client == 0) && (conf->port_server == 0)) {
	  if (conf->ip_client == conf->ip_pkt) {
	    conf->port_client = src_port;
	    conf->port_server = dst_port;
	  }
	  if (conf->ip_server == conf->ip_pkt) {
	    conf->port_client = dst_port;
	    conf->port_server = src_port;
	  }
	}
      }

      /* other packet */
      /* TODO XXXFIXMEXXX parse icmp, etc.. like tcp */
      else if (conf->check_proto) {
	debug(3, "proto type: %s\n", name);

	/* parse the content of the packet */
	verbose_("[*] packet type: %s\n", name);
	xml_parse_proto(conf, cur);
      }

      conf->proto_counter++;

      /* free the field name */
      xmlFree(name);
    }
    else if (!(xmlStrcmp(cur->name, (const xmlChar *) "field"))) {
      if (!conf->check_proto) xml_parse_raw_data(conf, cur);
    }
    cur = cur->next;
  }
}