String returns a human-readable representation of the IP address. For IPAddrID family (unresolved addresses), it returns "ID#XXXXXXXXXX" format similar to chronyc's output with the -a flag.
()
| 77 | // For IPAddrID family (unresolved addresses), it returns "ID#XXXXXXXXXX" format |
| 78 | // similar to chronyc's output with the -a flag. |
| 79 | func (ip *IPAddr) String() string { |
| 80 | switch ip.Family { |
| 81 | case IPAddrInet4: |
| 82 | return net.IP(ip.IP[:4]).String() |
| 83 | case IPAddrInet6: |
| 84 | return net.IP(ip.IP[:]).String() |
| 85 | case IPAddrID: |
| 86 | // Format like chronyc: "ID#XXXXXXXXXX" (10 hex digits) |
| 87 | // The ID is stored in the first 4 bytes of the IP field as big-endian uint32 |
| 88 | id := uint32(ip.IP[0])<<24 | uint32(ip.IP[1])<<16 | uint32(ip.IP[2])<<8 | uint32(ip.IP[3]) |
| 89 | return fmt.Sprintf("ID#%010X", id) |
| 90 | default: |
| 91 | return "" |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | type timeSpec struct { |
| 96 | SecHigh uint32 |