示例#1
0
static l4_uint16_t parse_udp(udp_hdr *u)
{
	l4_uint16_t psrc = ntohs(u->src_port);
	l4_uint16_t pdst =  ntohs(u->dst_port);
#if 0
	printf("    [UDP] src %d(%s), dest %d(%s), len %x, cs %x\n",
		   psrc, udp_port_str(psrc), pdst, udp_port_str(pdst),
	       ntohs(u->length), ntohs(u->checksum));
#endif

	switch(pdst) {
		case udp_port_bootp_srv:
			if (PA_DHCP || PA_BOOTP)
				parse_dhcp_srv((dhcp*)((char*)u + sizeof(udp_hdr)));
			return udp_port_bootp_srv;
			break;
		case udp_port_bootp_clnt:
			if (PA_DHCP || PA_BOOTP)
				parse_dhcp_clnt((dhcp*)((char*)u + sizeof(udp_hdr)));
			return udp_port_bootp_clnt;
			break;
		case udp_port_dns_srv:
			if (PA_DNS)
				parse_dns_srv((dns_t *)((char*)u + sizeof(udp_hdr)));
			return udp_port_dns_srv;
			break;
		default:
			return udp_port_unkown;
	}
}
示例#2
0
static GList *
g_resolver_records_from_DnsQuery (const gchar  *rrname,
                                  WORD          dnstype,
                                  DNS_STATUS    status,
                                  DNS_RECORD   *results,
                                  GError      **error)
{
  DNS_RECORD *rec;
  gpointer record;
  GList *records;

  if (status != ERROR_SUCCESS)
    {
      if (status == DNS_ERROR_RCODE_NAME_ERROR)
        {
          g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND,
                       _("No DNS record of the requested type for “%s”"), rrname);
        }
      else if (status == DNS_ERROR_RCODE_SERVER_FAILURE)
        {
          g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_TEMPORARY_FAILURE,
                       _("Temporarily unable to resolve “%s”"), rrname);
        }
      else
        {
          g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_INTERNAL,
                       _("Error resolving “%s”"), rrname);
        }

      return NULL;
    }

  records = NULL;
  for (rec = results; rec; rec = rec->pNext)
    {
      if (rec->wType != dnstype)
        continue;
      switch (dnstype)
        {
        case DNS_TYPE_SRV:
          record = parse_dns_srv (rec);
          break;
        case DNS_TYPE_SOA:
          record = parse_dns_soa (rec);
          break;
        case DNS_TYPE_NS:
          record = parse_dns_ns (rec);
          break;
        case DNS_TYPE_MX:
          record = parse_dns_mx (rec);
          break;
        case DNS_TYPE_TEXT:
          record = parse_dns_txt (rec);
          break;
        default:
          g_warn_if_reached ();
          record = NULL;
          break;
        }
      if (record != NULL)
        records = g_list_prepend (records, g_variant_ref_sink (record));
    }

  if (records == NULL)
    {
      g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND,
                   _("No DNS record of the requested type for “%s”"), rrname);

      return NULL;
    }
  else
    return records;
}