diff options
| author | Shulhan <ms@kilabit.info> | 2026-01-26 16:33:55 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-01-26 22:17:53 +0700 |
| commit | d4ff81a5e454bdbe0346beb9d09f9055dd2f07ed (patch) | |
| tree | 2da169c1b3681c089f8d580817d0eb612f88f104 /lib/dns | |
| parent | b1a1b7f245a812db563766ab82083b15665d019b (diff) | |
| download | pakakeh.go-d4ff81a5e454bdbe0346beb9d09f9055dd2f07ed.tar.xz | |
lib/dns: add method to set TTL on Message
The SetTTL method set all RRs answer time to live.
Diffstat (limited to 'lib/dns')
| -rw-r--r-- | lib/dns/message.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/dns/message.go b/lib/dns/message.go index abef69cd..8a5e2f05 100644 --- a/lib/dns/message.go +++ b/lib/dns/message.go @@ -996,6 +996,22 @@ func (msg *Message) SetResponseCode(code ResponseCode) { } } +// SetTTL set all RRs answer and authority time-to-live (TTL) to `n`. +func (msg *Message) SetTTL(n uint32) { + for x := range len(msg.Answer) { + msg.Answer[x].TTL = n + binary.BigEndian.PutUint32( + msg.packet[msg.Answer[x].idxTTL:], + msg.Answer[x].TTL) + } + for x := range len(msg.Authority) { + msg.Authority[x].TTL = n + binary.BigEndian.PutUint32( + msg.packet[msg.Authority[x].idxTTL:], + msg.Authority[x].TTL) + } +} + // SubTTL subtract TTL in each resource records and in packet by n seconds. // If TTL is less than n, it will set to 0. func (msg *Message) SubTTL(n uint32) { |
