pnovotnak
pnovotnak

Reputation: 4581

Getting Flags From a Network Interface

Looking at the net/interface.go code it seems like the only way to get interface flags is as strings. Is this true?

if strings.Contains(i.Flags.String(), "broadcast") {

Feels gross.

Upvotes: 5

Views: 1629

Answers (1)

user142162
user142162

Reputation:

net.Interface.Flags is a bitmask. To see if an interface has a certain flag, use the bitwise AND operator (&). For example:

if i.Flags&net.FlagBroadcast != 0 {
    // interface has broadcast
}

Upvotes: 6

Related Questions