Home | History | Annotate | Download | only in net

Lines Matching refs:off

376 // All the packers and unpackers take a (msg []byte, off int)
400 // Pack a domain name s into msg[off:].
403 func packDomainName(s string, msg []byte, off int) (off1 int, ok bool) {
414 if off+tot > len(msg) {
425 msg[off] = byte(i - begin)
426 off++
428 msg[off] = s[j]
429 off++
434 msg[off] = 0
435 off++
436 return off, true
452 func unpackDomainName(msg []byte, off int) (s string, off1 int, ok bool) {
457 if off >= len(msg) {
460 c := int(msg[off])
461 off++
469 if off+c > len(msg) {
472 s += string(msg[off:off+c]) + "."
473 off += c
480 if off >= len(msg) {
483 c1 := msg[off]
484 off++
486 off1 = off
491 off = (c^0xC0)<<8 | int(c1)
498 off1 = off
503 // packStruct packs a structure into msg at specified offset off, and
504 // returns off1 such that msg[off:off1] is the encoded data.
505 func packStruct(any dnsStruct, msg []byte, off int) (off1 int, ok bool) {
513 if off+2 > len(msg) {
516 msg[off] = byte(i >> 8)
517 msg[off+1] = byte(i)
518 off += 2
521 msg[off] = byte(i >> 24)
522 msg[off+1] = byte(i >> 16)
523 msg[off+2] = byte(i >> 8)
524 msg[off+3] = byte(i)
525 off += 4
528 if off+n > len(msg) {
531 copy(msg[off:off+n], fv)
532 off += n
540 off, ok = packDomainName(s, msg, off)
546 if len(s) > 255 || off+1+len(s) > len(msg) {
549 msg[off] = byte(len(s))
550 off++
551 off += copy(msg[off:], s)
559 return off, true
562 // unpackStruct decodes msg[off:] into the given structure, and
563 // returns off1 such that msg[off:off1] is the encoded data.
564 func unpackStruct(any dnsStruct, msg []byte, off int) (off1 int, ok bool) {
571 if off+2 > len(msg) {
574 *fv = uint16(msg[off])<<8 | uint16(msg[off+1])
575 off += 2
577 if off+4 > len(msg) {
580 *fv = uint32(msg[off])<<24 | uint32(msg[off+1])<<16 |
581 uint32(msg[off+2])<<8 | uint32(msg[off+3])
582 off += 4
585 if off+n > len(msg) {
588 copy(fv, msg[off:off+n])
589 off += n
597 s, off, ok = unpackDomainName(msg, off)
602 if off >= len(msg) || off+1+int(msg[off]) > len(msg) {
605 n := int(msg[off])
606 off++
609 b[i] = msg[off+i]
611 off += n
621 return off, true
686 func packRR(rr dnsRR, msg []byte, off int) (off2 int, ok bool) {
693 off1, ok = packStruct(rr.Header(), msg, off)
694 off2, ok = packStruct(rr, msg, off)
700 packStruct(rr.Header(), msg, off)
705 func unpackRR(msg []byte, off int) (rr dnsRR, off1 int, ok bool) {
708 off0 := off
709 if off, ok = unpackStruct(&h, msg, off); !ok {
712 end := off + int(h.Rdlength)
721 off, ok = unpackStruct(rr, msg, off0)
722 if off != end {
725 return rr, off, ok
801 off := 0
802 off, ok = packStruct(&dh, msg, off)
804 off, ok = packStruct(&question[i], msg, off)
807 off, ok = packRR(answer[i], msg, off)
810 off, ok = packRR(ns[i], msg, off)
813 off, ok = packRR(extra[i], msg, off)
818 return msg[0:off], true
824 off := 0
826 if off, ok = unpackStruct(&dh, msg, off); !ok {
847 off, ok = unpackStruct(&dns.question[i], msg, off)
850 rec, off, ok = unpackRR(msg, off)
857 rec, off, ok = unpackRR(msg, off)
864 rec, off, ok = unpackRR(msg, off)
870 // if off != len(msg) {
871 // println("extra bytes in dns packet", off, "<", len(msg));