Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Jun 29, 2024
1 parent 7f68d63 commit f955bad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
4 changes: 2 additions & 2 deletions internal/tui/form_arp.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (t *tui) arpForm(sendFn func(*packemon.EthernetFrame) error, ethernetHeader
if count < 3 {
return true
} else if count == 3 {
ip, err := strIPToBytes(textToCheck)
ip, err := packemon.StrIPToBytes(textToCheck)
if err != nil {
return false
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (t *tui) arpForm(sendFn func(*packemon.EthernetFrame) error, ethernetHeader
if count < 3 {
return true
} else if count == 3 {
ip, err := strIPToBytes(textToCheck)
ip, err := packemon.StrIPToBytes(textToCheck)
if err != nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion networkinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewNetworkInterface(nwInterface string) (*NetworkInterface, error) {
return nil, errors.New("network interface may not have IP address configured")
}

ipAddr, err := strIPToBytes(strings.Split(ipAddrs[0].String(), "/")[0])
ipAddr, err := StrIPToBytes(strings.Split(ipAddrs[0].String(), "/")[0])
if err != nil {
return nil, err
}
Expand Down
19 changes: 1 addition & 18 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func WriteUint32(buf *bytes.Buffer, target uint32) {
buf.Write(b)
}

// stringのIPv4アドレスをbytesに変換
func StrIPToBytes(s string) ([]byte, error) {
b := make([]byte, 4)
src := strings.Split(s, ".")
Expand Down Expand Up @@ -78,24 +79,6 @@ func StrIntToUint16(s string) (uint16, error) {
return uint16(n), nil
}

// stringのIPv4アドレスをbytesに変換
func strIPToBytes(s string) ([]byte, error) {
b := make([]byte, 4)
src := strings.Split(s, ".")

for i := range src {
if len(src[i]) == 0 {
continue
}
ip, err := strconv.ParseUint(src[i], 10, 8)
if err != nil {
return nil, err
}
b[i] = byte(ip)
}
return b, nil
}

// copy of https://github.com/sat0ken/go-curo/blob/main/utils.go#L18
func calculateChecksum(packet []byte) []byte {
// まず16ビット毎に足す
Expand Down

0 comments on commit f955bad

Please sign in to comment.