cosinekitty / zeroconfig

Dotnet Core C# library for MDNS zeroconfig browsing, resolving, and publishing. Self-contained -- no external dependencies.
MIT License
8 stars 1 forks source link

Support NSEC records #1

Open cosinekitty opened 3 years ago

cosinekitty commented 3 years ago

I have seen an NSEC record for AirPlay speakers. (Denial of existence?) Add support for interpreting and dumping these, instead of printing "not-used":

2021-03-01T01:30:55.9988909Z : packet from 192.168.1.8

       0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f
      -- -- -- -- -- -- -- --   -- -- -- -- -- -- -- --
0000  00 00 84 00 00 00 00 07   00 00 00 04 13 43 43 42  .............CCB
0010  30 44 41 36 34 33 44 39   39 40 20 50 61 74 69 6f  0DA643D99@ Patio
0020  05 5f 72 61 6f 70 04 5f   74 63 70 05 6c 6f 63 61  ._raop._tcp.loca
0030  6c 00 00 10 80 01 00 00   11 94 00 85 09 74 78 74  l............txt
0040  76 65 72 73 3d 31 08 73   72 3d 34 34 31 30 30 05  vers=1.sr=44100.
0050  73 73 3d 31 36 04 63 68   3d 32 06 74 70 3d 55 44  ss=16.ch=2.tp=UD
0060  50 08 70 77 3d 66 61 6c   73 65 08 73 76 3d 66 61  P.pw=false.sv=fa
0070  6c 73 65 06 65 74 3d 30   2c 31 04 65 6b 3d 31 06  lse.et=0,1.ek=1.
0080  63 6e 3d 30 2c 31 08 6d   64 3d 30 2c 31 2c 32 07  cn=0,1.md=0,1,2.
0090  64 61 3d 74 72 75 65 0c   63 74 2d 72 63 76 72 3d  da=true.ct-rcvr=
00a0  74 72 75 65 0a 61 6d 3d   44 45 4e 4f 4e 2c 31 08  true.am=DENON,1.
00b0  76 6e 3d 36 35 35 33 37   08 76 73 3d 31 30 33 2e  vn=65537.vs=103.
00c0  32 09 5f 73 65 72 76 69   63 65 73 07 5f 64 6e 73  2._services._dns
00d0  2d 73 64 04 5f 75 64 70   c0 2b 00 0c 00 01 00 00  -sd._udp.+......
00e0  11 94 00 02 c0 20 c0 20   00 0c 00 01 00 00 11 94  ..... . ........
00f0  00 02 c0 0c 13 43 43 42   30 44 41 36 34 33 44 39  .....CCB0DA643D9
0100  41 40 20 5a 6f 6e 65 32   c0 20 00 10 80 01 00 00  A@ Zone2. ......
0110  11 94 00 85 09 74 78 74   76 65 72 73 3d 31 08 73  .....txtvers=1.s
0120  72 3d 34 34 31 30 30 05   73 73 3d 31 36 04 63 68  r=44100.ss=16.ch
0130  3d 32 06 74 70 3d 55 44   50 08 70 77 3d 66 61 6c  =2.tp=UDP.pw=fal
0140  73 65 08 73 76 3d 66 61   6c 73 65 06 65 74 3d 30  se.sv=false.et=0
0150  2c 31 04 65 6b 3d 31 06   63 6e 3d 30 2c 31 08 6d  ,1.ek=1.cn=0,1.m
0160  64 3d 30 2c 31 2c 32 07   64 61 3d 74 72 75 65 0c  d=0,1,2.da=true.
0170  63 74 2d 72 63 76 72 3d   74 72 75 65 0a 61 6d 3d  ct-rcvr=true.am=
0180  44 45 4e 4f 4e 2c 31 08   76 6e 3d 36 35 35 33 37  DENON,1.vn=65537
0190  08 76 73 3d 31 30 33 2e   32 c0 20 00 0c 00 01 00  .vs=103.2. .....
01a0  00 11 94 00 02 c0 f4 c0   0c 00 21 80 01 00 00 00  ..........!.....
01b0  78 00 10 00 00 00 00 13   88 07 53 68 61 74 6e 65  x.........Shatne
01c0  72 c0 2b c0 f4 00 21 80   01 00 00 00 78 00 08 00  r.+...!.....x...
01d0  00 00 00 13 89 c1 b9 c1   b9 00 01 80 01 00 00 00  ................
01e0  78 00 04 c0 a8 01 08 c1   b9 00 2f 80 01 00 00 00  x........./.....
01f0  78 00 05 c1 b9 00 01 40   c0 0c 00 2f 80 01 00 00  x......@.../....
0200  11 94 00 09 c0 0c 00 05   00 00 80 00 40 c0 f4 00  ............@...
0210  2f 80 01 00 00 11 94 00   09 c0 f4 00 05 00 00 80  /...............
0220  00 40                                              .@

AnswerRR: name=[CCB0DA643D99@ Patio._raop._tcp.local.] type=TXT class=32769 TTL=4500
TXT "txtvers=1"
TXT "sr=44100"
TXT "ss=16"
TXT "ch=2"
TXT "tp=UDP"
TXT "pw=false"
TXT "sv=false"
TXT "et=0,1"
TXT "ek=1"
TXT "cn=0,1"
TXT "md=0,1,2"
TXT "da=true"
TXT "ct-rcvr=true"
TXT "am=DENON,1"
TXT "vn=65537"
TXT "vs=103.2"

AnswerRR: name=[_services._dns-sd._udp.local.] type=PTR class=IN TTL=4500
_raop._tcp.local.

AnswerRR: name=[_raop._tcp.local.] type=PTR class=IN TTL=4500
CCB0DA643D99@ Patio._raop._tcp.local.

AnswerRR: name=[CCB0DA643D9A@ Zone2._raop._tcp.local.] type=TXT class=32769 TTL=4500
TXT "txtvers=1"
TXT "sr=44100"
TXT "ss=16"
TXT "ch=2"
TXT "tp=UDP"
TXT "pw=false"
TXT "sv=false"
TXT "et=0,1"
TXT "ek=1"
TXT "cn=0,1"
TXT "md=0,1,2"
TXT "da=true"
TXT "ct-rcvr=true"
TXT "am=DENON,1"
TXT "vn=65537"
TXT "vs=103.2"

AnswerRR: name=[_raop._tcp.local.] type=PTR class=IN TTL=4500
CCB0DA643D9A@ Zone2._raop._tcp.local.

AnswerRR: name=[CCB0DA643D99@ Patio._raop._tcp.local.] type=SRV class=32769 TTL=120
0 0 5000 Shatner.local.

AnswerRR: name=[CCB0DA643D9A@ Zone2._raop._tcp.local.] type=SRV class=32769 TTL=120
0 0 5001 Shatner.local.

AdditionalRR: name=[Shatner.local.] type=A class=32769 TTL=120
192.168.1.8

AdditionalRR: name=[Shatner.local.] type=NSEC class=32769 TTL=120
not-used

AdditionalRR: name=[CCB0DA643D99@ Patio._raop._tcp.local.] type=NSEC class=32769 TTL=4500
not-used

AdditionalRR: name=[CCB0DA643D9A@ Zone2._raop._tcp.local.] type=NSEC class=32769 TTL=4500
not-used
cosinekitty commented 3 years ago

The NSEC record format is defined in: https://www.rfc-editor.org/rfc/rfc4034.txt

cosinekitty commented 3 years ago

Example of NSEC with data hex-dumped:

=========================================================================
2021-03-01T18:32:55.0963460Z : packet from 192.168.1.8

       0  1  2  3  4  5  6  7    8  9  a  b  c  d  e  f
      -- -- -- -- -- -- -- --   -- -- -- -- -- -- -- --
0000  00 00 84 00 00 00 00 04   00 00 00 03 07 53 48 41  .............SHA
0010  54 4e 45 52 0d 5f 63 61   73 61 74 75 6e 65 73 5f  TNER._casatunes_
0020  77 73 04 5f 74 63 70 05   6c 6f 63 61 6c 00 00 10  ws._tcp.local...
0030  80 01 00 00 11 94 00 11   10 6d 61 63 3d 43 43 42  .........mac=CCB
0040  30 44 41 36 34 33 44 39   39 09 5f 73 65 72 76 69  0DA643D99._servi
0050  63 65 73 07 5f 64 6e 73   2d 73 64 04 5f 75 64 70  ces._dns-sd._udp
0060  c0 27 00 0c 00 01 00 00   11 94 00 02 c0 14 c0 14  .'..............
0070  00 0c 00 01 00 00 11 94   00 02 c0 0c c0 0c 00 21  ...............!
0080  80 01 00 00 00 78 00 10   00 00 00 00 22 1b 07 53  .....x......"..S
0090  68 61 74 6e 65 72 c0 27   c0 8e 00 01 80 01 00 00  hatner.'........
00a0  00 78 00 04 c0 a8 01 08   c0 8e 00 2f 80 01 00 00  .x........./....
00b0  00 78 00 05 c0 8e 00 01   40 c0 0c 00 2f 80 01 00  .x......@.../...
00c0  00 11 94 00 09 c0 0c 00   05 00 00 80 00 40        .............@

AnswerRR: name=[SHATNER._casatunes_ws._tcp.local.] type=TXT class=32769 TTL=4500
TXT "mac=CCB0DA643D99"

AnswerRR: name=[_services._dns-sd._udp.local.] type=PTR class=IN TTL=4500
_casatunes_ws._tcp.local.

AnswerRR: name=[_casatunes_ws._tcp.local.] type=PTR class=IN TTL=4500
SHATNER._casatunes_ws._tcp.local.

AnswerRR: name=[SHATNER._casatunes_ws._tcp.local.] type=SRV class=32769 TTL=120
0 0 8731 Shatner.local.

AdditionalRR: name=[Shatner.local.] type=A class=32769 TTL=120
192.168.1.8

AdditionalRR: name=[Shatner.local.] type=NSEC class=32769 TTL=120
RDATA = [c0 8e 00 01 40]

AdditionalRR: name=[SHATNER._casatunes_ws._tcp.local.] type=NSEC class=32769 TTL=4500
RDATA = [c0 0c 00 05 00 00 80 00 40]