@@ -537,9 +537,13 @@ func (ip IP) WithZone(zone string) IP {
537
537
// IsLinkLocalUnicast reports whether ip is a link-local unicast address.
538
538
// If ip is the zero value, it will return false.
539
539
func (ip IP ) IsLinkLocalUnicast () bool {
540
+ // Dynamic Configuration of IPv4 Link-Local Addresses
541
+ // https://datatracker.ietf.org/doc/html/rfc3927#section-2.1
540
542
if ip .Is4 () {
541
543
return ip .v4 (0 ) == 169 && ip .v4 (1 ) == 254
542
544
}
545
+ // IP Version 6 Addressing Architecture (2.5.6 Link-Local IPv6 Unicast Addresses)
546
+ // https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.6
543
547
if ip .Is6 () {
544
548
return ip .v6u16 (0 ) == 0xfe80
545
549
}
@@ -549,9 +553,13 @@ func (ip IP) IsLinkLocalUnicast() bool {
549
553
// IsLoopback reports whether ip is a loopback address. If ip is the zero value,
550
554
// it will return false.
551
555
func (ip IP ) IsLoopback () bool {
556
+ // Requirements for Internet Hosts -- Communication Layers (3.2.1.3 Addressing)
557
+ // https://datatracker.ietf.org/doc/html/rfc1122#section-3.2.1.3
552
558
if ip .Is4 () {
553
559
return ip .v4 (0 ) == 127
554
560
}
561
+ // IP Version 6 Addressing Architecture (2.5.3 The Loopback Address)
562
+ // https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.3
555
563
if ip .Is6 () {
556
564
return ip .addr .hi == 0 && ip .addr .lo == 1
557
565
}
@@ -561,6 +569,8 @@ func (ip IP) IsLoopback() bool {
561
569
// IsMulticast reports whether ip is a multicast address. If ip is the zero
562
570
// value, it will return false.
563
571
func (ip IP ) IsMulticast () bool {
572
+ // Host Extensions for IP Multicasting (4. HOST GROUP ADDRESSES)
573
+ // https://datatracker.ietf.org/doc/html/rfc1112#section-4
564
574
if ip .Is4 () {
565
575
return ip .v4 (0 )& 0xf0 == 0xe0
566
576
}
@@ -574,6 +584,8 @@ func (ip IP) IsMulticast() bool {
574
584
// multicast address. If ip is the zero value or an IPv4 address, it will return
575
585
// false.
576
586
func (ip IP ) IsInterfaceLocalMulticast () bool {
587
+ // IPv6 Addressing Architecture (2.7.1. Pre-Defined Multicast Addresses)
588
+ // https://datatracker.ietf.org/doc/html/rfc4291#section-2.7.1
577
589
if ip .Is6 () {
578
590
return ip .v6u16 (0 )& 0xff0f == 0xff01
579
591
}
@@ -583,9 +595,13 @@ func (ip IP) IsInterfaceLocalMulticast() bool {
583
595
// IsLinkLocalMulticast reports whether ip is a link-local multicast address.
584
596
// If ip is the zero value, it will return false.
585
597
func (ip IP ) IsLinkLocalMulticast () bool {
598
+ // IPv4 Multicast Guidelines (4. Local Network Control Block (224.0.0/24))
599
+ // https://datatracker.ietf.org/doc/html/rfc5771#section-4
586
600
if ip .Is4 () {
587
601
return ip .v4 (0 ) == 224 && ip .v4 (1 ) == 0 && ip .v4 (2 ) == 0
588
602
}
603
+ // IPv6 Addressing Architecture (2.7.1. Pre-Defined Multicast Addresses)
604
+ // https://datatracker.ietf.org/doc/html/rfc4291#section-2.7.1
589
605
if ip .Is6 () {
590
606
return ip .v6u16 (0 )& 0xff0f == 0xff02
591
607
}
0 commit comments