Lines Matching refs:packet

61  *  - it takes raw DNS query packet data as input, and returns raw DNS
62 * answer packet data as output
333 /* dump the content of a query of packet to the log */
355 /* reminder: the general format of a DNS packet is the following:
420 * OFFSET : 14 : offset to another part of the DNS packet
422 * The offset is relative to the start of the DNS packet and must point
457 _dnsPacket_init( DnsPacket* packet, const uint8_t* buff, int bufflen )
459 packet->base = buff;
460 packet->end = buff + bufflen;
461 packet->cursor = buff;
465 _dnsPacket_rewind( DnsPacket* packet )
467 packet->cursor = packet->base;
471 _dnsPacket_skip( DnsPacket* packet, int count )
473 const uint8_t* p = packet->cursor + count;
475 if (p > packet->end)
476 p = packet->end;
478 packet->cursor = p;
482 _dnsPacket_readInt16( DnsPacket* packet )
484 const uint8_t* p = packet->cursor;
486 if (p+2 > packet->end)
489 packet->cursor = p+2;
496 /* check bytes in a dns packet. returns 1 on success, 0 on failure.
500 _dnsPacket_checkBytes( DnsPacket* packet, int numBytes, const void* bytes )
502 const uint8_t* p = packet->cursor;
504 if (p + numBytes > packet->end)
510 packet->cursor = p + numBytes;
514 /* parse and skip a given QNAME stored in a query packet,
519 _dnsPacket_checkQName( DnsPacket* packet )
521 const uint8_t* p = packet->cursor;
522 const uint8_t* end = packet->end;
533 packet->cursor = p;
550 /* parse and skip a given QR stored in a packet.
554 _dnsPacket_checkQR( DnsPacket* packet )
556 if (!_dnsPacket_checkQName(packet))
560 if (!_dnsPacket_checkBytes(packet, 2, DNS_TYPE_A) &&
561 !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_PTR) &&
562 !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_MX) &&
563 !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_AAAA) &&
564 !_dnsPacket_checkBytes(packet, 2, DNS_TYPE_ALL))
570 if (!_dnsPacket_checkBytes(packet, 2, DNS_CLASS_IN)) {
578 /* check the header of a DNS Query packet, return 1 if it is one
582 _dnsPacket_checkQuery( DnsPacket* packet )
584 const uint8_t* p = packet->base;
587 if (p + DNS_HEADER_SIZE > packet->end) {
588 XLOG("query packet too small");
595 XLOG("query packet flags unsupported");
602 * - there is no point for a query packet sent to a server
624 XLOG("query packet contains non-query records");
629 XLOG("query packet doesn't contain query record");
634 packet->cursor = p + DNS_HEADER_SIZE;
637 if (!_dnsPacket_checkQR(packet))
647 _dnsPacket_bprintQName(DnsPacket* packet, char* bp, char* bend)
649 const uint8_t* p = packet->cursor;
650 const uint8_t* end = packet->end;
662 packet->cursor = p;
687 _dnsPacket_bprintQR(DnsPacket* packet, char* p, char* end)
702 p = _dnsPacket_bprintQName(packet, p, end);
708 if (_dnsPacket_checkBytes(packet, 2, qTypes[nn].typeBytes)) {
717 int typeCode = _dnsPacket_readInt16(packet);
724 _dnsPacket_skip(packet, 2);
728 /* this function assumes the packet has already been checked */
730 _dnsPacket_bprintQuery( DnsPacket* packet, char* p, char* end )
734 if (packet->base[2] & 0x1) {
738 _dnsPacket_skip(packet, 4);
739 qdCount = _dnsPacket_readInt16(packet);
740 _dnsPacket_skip(packet, 6);
743 p = _dnsPacket_bprintQR(packet, p, end);
761 _dnsPacket_hashBytes( DnsPacket* packet, int numBytes, unsigned hash )
763 const uint8_t* p = packet->cursor;
764 const uint8_t* end = packet->end;
769 packet->cursor = p;
775 _dnsPacket_hashQName( DnsPacket* packet, unsigned hash )
777 const uint8_t* p = packet->cursor;
778 const uint8_t* end = packet->end;
807 packet->cursor = p;
812 _dnsPacket_hashQR( DnsPacket* packet, unsigned hash )
814 hash = _dnsPacket_hashQName(packet, hash);
815 hash = _dnsPacket_hashBytes(packet, 4, hash); /* TYPE and CLASS */
820 _dnsPacket_hashRR( DnsPacket* packet, unsigned hash )
823 hash = _dnsPacket_hashQR(packet, hash);
824 hash = _dnsPacket_hashBytes(packet, 4, hash); /* TTL */
825 rdlength = _dnsPacket_readInt16(packet);
826 hash = _dnsPacket_hashBytes(packet, rdlength, hash); /* RDATA */
831 _dnsPacket_hashQuery( DnsPacket* packet )
835 _dnsPacket_rewind(packet);
838 _dnsPacket_skip(packet, 2);
847 hash = hash*FNV_MULT ^ (packet->base[2] & 1);
850 _dnsPacket_skip(packet, 1);
853 hash = _dnsPacket_hashBytes(packet, 1, hash);
856 count = _dnsPacket_readInt16(packet);
859 _dnsPacket_skip(packet, 4);
862 arcount = _dnsPacket_readInt16(packet);
866 hash = _dnsPacket_hashQR(packet, hash);
870 hash = _dnsPacket_hashRR(packet, hash);
1199 /* initialize an Entry as a search key, this also checks the input query packet