Home | History | Annotate | Download | only in net

Lines Matching refs:off

309 // All the packers and unpackers take a (msg []byte, off int)
328 // Pack a domain name s into msg[off:].
331 func packDomainName(s string, msg []byte, off int) (off1 int, ok bool) {
339 msg[off] = 0
340 off++
341 return off, true
349 if off+tot > len(msg) {
364 msg[off] = byte(i - begin)
365 off++
368 msg[off] = s[j]
369 off++
374 msg[off] = 0
375 off++
376 return off, true
392 func unpackDomainName(msg []byte, off int) (s string, off1 int, ok bool) {
397 if off >= len(msg) {
400 c := int(msg[off])
401 off++
409 if off+c > len(msg) {
412 s += string(msg[off:off+c]) + "."
413 off += c
420 if off >= len(msg) {
423 c1 := msg[off]
424 off++
426 off1 = off
431 off = (c^0xC0)<<8 | int(c1)
441 off1 = off
446 // packStruct packs a structure into msg at specified offset off, and
447 // returns off1 such that msg[off:off1] is the encoded data.
448 func packStruct(any dnsStruct, msg []byte, off int) (off1 int, ok bool) {
456 if off+2 > len(msg) {
459 msg[off] = byte(i >> 8)
460 msg[off+1] = byte(i)
461 off += 2
464 msg[off] = byte(i >> 24)
465 msg[off+1] = byte(i >> 16)
466 msg[off+2] = byte(i >> 8)
467 msg[off+3] = byte(i)
468 off += 4
471 if off+n > len(msg) {
474 copy(msg[off:off+n], fv)
475 off += n
483 off, ok = packDomainName(s, msg, off)
489 if len(s) > 255 || off+1+len(s) > len(msg) {
492 msg[off] = byte(len(s))
493 off++
494 off += copy(msg[off:], s)
502 return off, true
505 // unpackStruct decodes msg[off:] into the given structure, and
506 // returns off1 such that msg[off:off1] is the encoded data.
507 func unpackStruct(any dnsStruct, msg []byte, off int) (off1 int, ok bool) {
514 if off+2 > len(msg) {
517 *fv = uint16(msg[off])<<8 | uint16(msg[off+1])
518 off += 2
520 if off+4 > len(msg) {
523 *fv = uint32(msg[off])<<24 | uint32(msg[off+1])<<16 |
524 uint32(msg[off+2])<<8 | uint32(msg[off+3])
525 off += 4
528 if off+n > len(msg) {
531 copy(fv, msg[off:off+n])
532 off += n
540 s, off, ok = unpackDomainName(msg, off)
545 if off >= len(msg) || off+1+int(msg[off]) > len(msg) {
548 n := int(msg[off])
549 off++
552 b[i] = msg[off+i]
554 off += n
564 return off, true
629 func packRR(rr dnsRR, msg []byte, off int) (off2 int, ok bool) {
636 off1, ok = packStruct(rr.Header(), msg, off)
640 off2, ok = packStruct(rr, msg, off)
646 packStruct(rr.Header(), msg, off)
651 func unpackRR(msg []byte, off int) (rr dnsRR, off1 int, ok bool) {
654 off0 := off
655 if off, ok = unpackStruct(&h, msg, off); !ok {
658 end := off + int(h.Rdlength)
667 off, ok = unpackStruct(rr, msg, off0)
668 if off != end {
671 return rr, off, ok
747 off := 0
748 off, ok = packStruct(&dh, msg, off)
753 off, ok = packStruct(&question[i], msg, off)
759 off, ok = packRR(answer[i], msg, off)
765 off, ok = packRR(ns[i], msg, off)
771 off, ok = packRR(extra[i], msg, off)
776 return msg[0:off], true
782 off := 0
784 if off, ok = unpackStruct(&dh, msg, off); !ok {
805 off, ok = unpackStruct(&dns.question[i], msg, off)
811 rec, off, ok = unpackRR(msg, off)
818 rec, off, ok = unpackRR(msg, off)
825 rec, off, ok = unpackRR(msg, off)
831 // if off != len(msg) {
832 // println("extra bytes in dns packet", off, "<", len(msg));