Menu Close

Go – IsInterfaceLocalMulticast() of net package in go

In this tutorial, we are going to learn about IsInterfaceLocalMulticast() function of net package in go with example.

IsInterfaceLocalMulticast() function is used to check whether ip is an interface-local multicast address or not in net package.

function prototype:

func (ip IP) IsInterfaceLocalMulticast() bool

Example:

package main

import (
	"fmt"
	"net"
)

func main() {
    ipv4_ip := net.ParseIP("255.255.255.0")
    is_multicast_address := ipv4_ip.IsInterfaceLocalMulticast()
    
    if is_multicast_address == true {
        fmt.Println("255.255.255.0 is an interface-local multicast address.")
    } else {
        fmt.Println("255.255.255.0 is not an interface-local multicast address.")
    }
    
    ipv6_ip := net.ParseIP("ff01::1")
    is_multicast_address = ipv6_ip.IsInterfaceLocalMulticast()
    
    if is_multicast_address == true {
        fmt.Println("ff01::1 is an interface-local multicast address.")
    } else {
        fmt.Println("ff01::1 is not an interface-local multicast address.")
    }
    
    ipv6_ip = net.ParseIP("2000::")
    is_multicast_address = ipv6_ip.IsInterfaceLocalMulticast()
    
    if is_multicast_address == true {
        fmt.Println("2000:: is an interface-local multicast address.")
    } else {
        fmt.Println("2000:: is not an interface-local multicast address.")
    }
}

Output:

255.255.255.0 is not an interface-local multicast address.
ff01::1 is an interface-local multicast address.
2000:: is not an interface-local multicast address.

What is multicast address of interface-local ?

The interface-local scope expands a single interface only. A multicast address of interface-local scope is used only for loopback delivery of multicasts within a node. It means It’s form interprocess communication within a computer. interface-local multicast addresses may be joined on any interface.

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References: https://golang.org/pkg/

Posted in golang, net, packages

Leave a Reply

Your email address will not be published. Required fields are marked *