diff --git a/internal/tui/form_arp.go b/internal/tui/form_arp.go index 5cdd40c..c4dccf1 100644 --- a/internal/tui/form_arp.go +++ b/internal/tui/form_arp.go @@ -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 } @@ -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 } diff --git a/networkinterface.go b/networkinterface.go index da09d2f..d1b827e 100644 --- a/networkinterface.go +++ b/networkinterface.go @@ -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 } diff --git a/util.go b/util.go index f3432d9..82c4883 100644 --- a/util.go +++ b/util.go @@ -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, ".") @@ -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ビット毎に足す