google / google/gopacket

Dot11Type MainType() Function Does Not Return `Mgmt`

Open
#1,205 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

New to both Go and this library so, perhaps I've missed something. Here's a simple example of what I'm seeing:
```go
packet := gopacket.NewPacket(
data,
layers.LayerTypeRadioTap,
gopacket.DecodeOptions{Lazy: true, NoCopy: true},
)

// retrieve the dot11 layer
dot11Layer := packet.Layer(layers.LayerTypeDot11)
if dot11Layer == nil {
log.Fatalf("No 802.11 layer found in packet %d", i)
}
dot11, ok := dot11Layer.(*layers.Dot11)

fmt.Printf("MainType: %s\n", dot11.Type.MainType())
fmt.Printf("Type: %s\n", dot11.Type)

```
From this, I get the following output:
```
MainType: MgmtAssociationReq
Type: MgmtBeacon
```

According to the docs I would have expected the MainType value to be something like `Mgmt`. https://github.com/google/gopacket/blob/v1.1.19/layers/enums.go#L214

Inspecting the library code, I believe I see that `Mgmt` is actually never going to be returned? The `Dot11TypeMetadata` slice doesn't actuallly have an entry for `Dot11TypeMgmt`. This appears to be related to the fact that the following two values are the same?
```
...
Dot11TypeMgmt Dot11Type = 0x00
...
Dot11TypeMgmtAssociationReq Dot11Type = 0x00
...
```

So when the `MainType` function applies it's masking it can only mask to a single value? If all of that is true, it feels like there's a reason or maybe some history in why the `Mgmt` type isn't represented when calling `MainType`.

Does anyone have any insights on this? Have I missed something? Most importantly, if I want to determine the `MainType` value to be one of management, control, or data, should I code against the currently returned value of `MgmtAssociationReq`? Or should I perhaps look at the integer representations of these values instead?

Thanks for your insights.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.