-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package tui | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/ddddddO/packemon" | ||
"github.com/rivo/tview" | ||
) | ||
|
||
type IPv6 struct { | ||
*packemon.IPv6 | ||
} | ||
|
||
func (*IPv6) rows() int { | ||
return 16 | ||
} | ||
|
||
func (*IPv6) columns() int { | ||
return 30 | ||
} | ||
|
||
func (i *IPv6) viewTable() *tview.Table { | ||
table := tview.NewTable().SetBorders(false) | ||
table.Box = tview.NewBox().SetBorder(true).SetTitle(" IPv6 Header ").SetTitleAlign(tview.AlignLeft).SetBorderPadding(1, 1, 1, 1) | ||
|
||
table.SetCell(0, 0, tview.NewTableCell(padding("Version"))) | ||
table.SetCell(0, 1, tview.NewTableCell(padding(fmt.Sprintf("%x", i.Version)))) | ||
|
||
table.SetCell(1, 0, tview.NewTableCell(padding("Traffic Class"))) | ||
table.SetCell(1, 1, tview.NewTableCell(padding(fmt.Sprintf("%x", i.TrafficClass)))) | ||
|
||
table.SetCell(2, 0, tview.NewTableCell(padding("Flow Label"))) | ||
table.SetCell(2, 1, tview.NewTableCell(padding("<under development!>"))) | ||
|
||
table.SetCell(3, 0, tview.NewTableCell(padding("Payload Length"))) | ||
table.SetCell(3, 1, tview.NewTableCell(padding("<under development!>"))) | ||
|
||
table.SetCell(4, 0, tview.NewTableCell(padding("Next Header"))) | ||
table.SetCell(4, 1, tview.NewTableCell(padding(fmt.Sprintf("%x", i.NextHeader)))) | ||
|
||
table.SetCell(5, 0, tview.NewTableCell(padding("Hop Limit"))) | ||
table.SetCell(5, 1, tview.NewTableCell(padding(fmt.Sprintf("%d", i.HopLimit)))) | ||
|
||
table.SetCell(6, 0, tview.NewTableCell(padding("Source Address"))) | ||
table.SetCell(6, 1, tview.NewTableCell(padding(i.StrSrcIPAddr()))) | ||
|
||
table.SetCell(7, 0, tview.NewTableCell(padding("Destination Address"))) | ||
table.SetCell(7, 1, tview.NewTableCell(padding(i.StrDstIPAddr()))) | ||
|
||
return table | ||
} | ||
|
||
func (i *IPv6) StrSrcIPAddr() string { | ||
return uintsToStrIPv6Addr(i.SrcAddr) | ||
} | ||
|
||
func (i *IPv6) StrDstIPAddr() string { | ||
return uintsToStrIPv6Addr(i.DstAddr) | ||
} | ||
|
||
func uintsToStrIPv6Addr(byteAddr []uint8) string { | ||
ipv6Addr := net.IP(byteAddr) | ||
return ipv6Addr.To16().String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package packemon | ||
|
||
// https://atmarkit.itmedia.co.jp/ait/articles/1201/05/news113.html | ||
type IPv6 struct { | ||
Version uint8 // 4bit | ||
TrafficClass uint8 | ||
FlowLabel uint32 // 20bit | ||
PayloadLength uint16 | ||
NextHeader uint8 | ||
HopLimit uint8 | ||
SrcAddr []uint8 | ||
DstAddr []uint8 | ||
|
||
Option []uint8 | ||
|
||
Data []byte | ||
} | ||
|
||
func ParsedIPv6(payload []byte) *IPv6 { | ||
return &IPv6{ | ||
Version: payload[0] >> 4, | ||
TrafficClass: payload[0]<<4 | payload[1]>>4, | ||
// FlowLabel: , | ||
// PayloadLength: , | ||
NextHeader: payload[6], | ||
HopLimit: payload[7], | ||
SrcAddr: payload[8:24], | ||
DstAddr: payload[24:40], | ||
} | ||
} | ||
|
||
const ( | ||
IPv6_NEXT_HEADER_UDP = 0x11 | ||
IPv6_NEXT_HEADER_ICMPv6 = 0x3a | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters