1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
names.go 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
package dns
// This file contains the name mapping data used to convert various DNS IDs to
// their string values.
import (
"encoding/hex"
"fmt"
"strconv"
"strings"
mkdns "github.com/miekg/dns"
)
// dnsOpCodeToString converts a Opcode value to a string. If the type's
// string representation is unknown then the numeric value will be returned as
// a string.
func dnsOpCodeToString(opCode int) string {
s, exists := mkdns.OpcodeToString[opCode]
if !exists {
return strconv.Itoa(int(opCode))
}
return s
}
// dnsResponseCodeToString converts a Rcode value to a string. If
// the type's string representation is unknown then "Unknown <rcode value>"
// will be returned.
func dnsResponseCodeToString(rcode int) string {
s, exists := mkdns.RcodeToString[rcode]
if !exists {
return fmt.Sprintf("Unknown %d", int(rcode))
}
return s
}
// dnsTypeToString converts a RR type value to a string. If the type's
// string representation is unknown then the numeric value will be returned
// as a string.
func dnsTypeToString(t uint16) string {
s, exists := mkdns.TypeToString[uint16(t)]
if !exists {
return strconv.Itoa(int(t))
}
return s
}
// dnsClassToString converts a RR class value to a string. If the class'es
// string representation is unknown then the numeric value will be returned
// as a string.
func dnsClassToString(c uint16) string {
s, exists := mkdns.ClassToString[uint16(c)]
if !exists {
return strconv.Itoa(int(c))
}
return s
}
// dnsAlgorithmToString converts an algorithm value to a string. If the algorithm's
// string representation is unknown then the numeric value will be returned
// as a string.
func dnsAlgorithmToString(a uint8) string {
s, exists := mkdns.AlgorithmToString[uint8(a)]
if !exists {
return strconv.Itoa(int(a))
}
return s
}
// dnsHashToString converts a hash value to a string. If the hash's
// string representation is unknown then the numeric value will be returned
// as a string.
func dnsHashToString(h uint8) string {
s, exists := mkdns.HashToString[uint8(h)]
if !exists {
return strconv.Itoa(int(h))
}
return s
}
// dnsTypeBitsMapToString converts a map of type bits to a string. If the type's
// string representation is unknown then the numeric value will be returned
// as a string.
func dnsTypeBitsMapToString(t []uint16) string {
var s string
for i := 0; i < len(t); i++ {
s += dnsTypeToString(t[i]) + " "
}
return strings.TrimSuffix(s, " ")
}
// saltToString converts a NSECX salt to uppercase and
// returns "-" when it is empty
// func copied from miekg/dns because unexported
func dnsSaltToString(s string) string {
if len(s) == 0 {
return "-"
}
return strings.ToUpper(s)
}
// hexStringToString converts an hexadeciaml string to string. Bytes
// below 32 or above 126 are represented as an escaped base10 integer (\DDD).
// Back slashes and quotes are escaped. Tabs, carriage returns, and line feeds
// will be converted to \t, \r and \n respectively.
// Example:
func hexStringToString(hexString string) (string, error) {
bytes, err := hex.DecodeString(hexString)
if err != nil {
return hexString, err
}
var s []byte
for _, value := range bytes {
switch value {
default:
if value < 32 || value >= 127 {
// Unprintable characters are written as \\DDD (e.g. \\012).
s = append(s, []byte(fmt.Sprintf("\\%03d", int(value)))...)
} else {
s = append(s, value)
}
case '"', '\\':
s = append(s, '\\', value)
case '\t':
s = append(s, '\\', 't')
case '\r':
s = append(s, '\\', 'r')
case '\n':
s = append(s, '\\', 'n')
}
}
return string(s), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.4.2

搜索帮助

A270a887 8829481 3d7a4017 8829481