# Patch - for resolv.rb to support mDNS "cache flush" bit

**URL:** <https://rubytalk.org/t/patch-for-resolv-rb-to-support-mdns-cache-flush-bit/16299>\
**Category:** ruby-talk\
**Created:** [6 February 2005 22:45 UTC](https://rubytalk.org/t/patch-for-resolv-rb-to-support-mdns-cache-flush-bit/16299 "2005-02-06T22:45:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Roberts1](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@Sam\_Roberts1](https://rubytalk.org/u/Sam_Roberts1)\
**Post date:** [6 February 2005 22:45 UTC](https://rubytalk.org/t/patch-for-resolv-rb-to-support-mdns-cache-flush-bit/16299/1 "2005-02-06T22:45:58Z")

</div>

mDNS uses the high-bit of the CLASS of a resource record to store a  
"cache flush" bit.

This is DNS-incompatible, of course, but note only 2 bits of the 16  
CLASS bits are used so far, and classes other than "1" (internet) are  
rarely seen. It is unlikely that DNS will be needing the next thousands  
of values anytime soon.

Functional requirements for mDNS are:

1 - have the cache flush bit not be considered when choosing a Class to  
&nbsp;&nbsp;&nbsp;&nbsp;decode the rdata

2 - be able to retrieve the saved cache flush bit later

A way of doing this with a small set of changes to resolv.rb is:

Index: resolv.rb

> **···**
>
> ===================================================================  
> RCS file: /src/ruby/lib/resolv.rb,v  
> retrieving revision 1.17.2.9  
> diff -u -r1.17.2.9 resolv.rb  
> --- resolv.rb 5 Feb 2005 18:31:20 -0000 1.17.2.9  
> +++ resolv.rb 6 Feb 2005 22:32:59 -0000  
> @@ -1322,8 +1322,10 @@  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def get\_rr  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name = self.get\_name  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type, klass, ttl = self.get\_unpack('nnN')  
> - typeclass = Resource.get\_class(type, klass)  
> - return name, ttl, self.get\_length16 {typeclass.decode\_rdata(self)}  
> + typeclass = Resource.get\_class(type, klass % 0x8000)  
> + data = self.get\_length16 {typeclass.decode\_rdata(self)}  
> + data.instance\_variable\_set(:@cacheflush, true) if (klass \>\> 15) == 1  
> + return name, ttl, data  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> Another way would be to add
> 
> &nbsp;&nbsp;&nbsp;class Resource  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr\_accessor :cacheflush  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...
> 
> and use the attribute rather than #instance\_variable\_set. This is less  
> "weird", but instance\_variable\_set is more backwards compatible (i.e.,  
> if the bit isn't set (DNS' case) then no extra attributes exist in the  
> resource data class).
> 
> Thoughts please?
> 
> Thank you,  
> Sam
> 
> Example packet:
> 
> require 'resolv.rb'  
> require 'pp'
> 
> class Resolv  
> &nbsp;&nbsp;class DNS  
> &nbsp;&nbsp;&nbsp;&nbsp;class Name
> 
> &nbsp;&nbsp;&nbsp;&nbsp;# NOTE - could #inspect be added to Name? An array of labels every  
> &nbsp;&nbsp;&nbsp;&nbsp;# time I do a 'pp' is making output much harder to read than  
> &nbsp;&nbsp;&nbsp;&nbsp;# necessary.  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def inspect  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to\_s + (absolute? ? '.' : '')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;end  
> end
> 
> data1 = "\000\000\204\000\000\000\000\002\000\000\000\001\010ensemble\005\_http\004\_tcp\005local\000\000!\200\001\000\000\000\<\000\021\000\000\000\000\000P\010ensemble\300 \300\f\000\020\200\001\000\000\000\<\000\001\000\3007\000\001\200\001\000\000\000\<\000\004\300\250{\232"
> 
> msg = Resolv::DNS::Message.decode(data1)
> 
> pp msg
