Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: IPConn can't handle ARP packets #7574

gopherbot opened this issue Mar 18, 2014 · 5 comments

net: IPConn can't handle ARP packets #7574

gopherbot opened this issue Mar 18, 2014 · 5 comments


Copy link

@gopherbot gopherbot commented Mar 18, 2014

by jikai507:

package main

import (
    . "fmt"

type ARP struct {
    NetType       uint16
    ProtoType     uint16
    MacAddrLen    uint8
    IPAddrLen     uint8
    OperationCode uint16
    SrcMacAddr    [6]byte
    SrcIPAddr     [4]byte
    DstMacAddr    [6]byte
    DstIPAddr     [4]byte

func ParseMacAddr(macaddr string) (mac [6]byte) {
    segments := strings.Split(macaddr, "-")
    for i := 0; i < 6; i++ {
        value, err := strconv.ParseUint(segments[i], 16, 64)
        if err != nil {
            panic("parse mac addr error")
        mac[i] = byte(value)
    return mac

func ParseIP(ipaddr string) (ip [4]byte) {
    segments := strings.Split(ipaddr, ".")
    for i := 0; i < 4; i++ {
        value, err := strconv.Atoi(segments[i])
        if err != nil {
            panic("parse ip addr error")
        ip[i] = byte(value)
    return ip

func main() {
    var (
        laddr net.IPAddr = net.IPAddr{IP: net.ParseIP("")}
        raddr net.IPAddr = net.IPAddr{IP: net.ParseIP("")}

        // problems happens in this row...
    ipconn, err := net.DialIP("ip:arp", &laddr, &raddr)
    if err != nil {
        Println("DialIP() error:", err.Error())
    defer ipconn.Close()

    var (
        arp ARP
    arp.NetType = 0x1      
    arp.ProtoType = 0x0800 
    arp.MacAddrLen = 6
    arp.IPAddrLen = 4
    arp.OperationCode = 0x1
    arp.SrcMacAddr = ParseMacAddr("00-23-5A-BD-DF-82")
    arp.SrcIPAddr = ParseIP("")
    arp.DstMacAddr = ParseMacAddr("00-00-00-00-00-00")
    arp.DstIPAddr = ParseIP("")

    var (
        buffer bytes.Buffer
    binary.Write(&buffer, binary.BigEndian, arp)
    if _, err := ipconn.Write(buffer.Bytes()); err == nil {
        Println("send success")


What does 'go version' print?
go version go1.2.1 windows/386

What happened?
The error message like this :
DialIP() error: dial ip:arp GetProtoByName: The requested name is valid,
but no data of the requested type was found.

What should have happened instead?
If it can run successfully, it should output "send success".

Please provide any additional information below.
Copy link

@mikioh mikioh commented Mar 18, 2014

Comment 1:

ARP is not part of IPv4 protocol family.

Status changed to Invalid.

Copy link

@mikioh mikioh commented Mar 19, 2014

Comment 2:

PS: FWIW, you can use net.ParseMAC which can parse several burn-in/hardware MAC/EUI-48
to EUI-64 address representations instead.
Copy link

@gopherbot gopherbot commented Mar 21, 2014

Comment 3 by jikai507:

how can i send a arp package.
I try the:
net.Dial("arp" , "")
but it also can not compiled success.
2014��3��19�� ����11:10�� <>���
Copy link

@mikioh mikioh commented Mar 22, 2014

Comment 4:

Use platform-specific services that Go stdlib and subrepo stuff never provide:
On Windows, some APIs such as SendArp exist,
On Unix-like systems, you can use BPF/LSF and/or NetMap/PF_RING,
On some systems that equip with kinda big interfaces such as Mellanox, Chelsio, etc, use
APIs provided by such vendors
Anyway more questions about you are asking for would be not related to the Go language
@gopherbot gopherbot added the invalid label Aug 2, 2014
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants