1
package main
import (
"fmt"
"syscall"
)
func main() { ` 
  fd, err:= syscall.Socket(syscall.AF_PACKET, syscall.SOCK_RAW, syscall.ETH_P_ALL) //opening raw socket
  if (err != nil) {
    fmt.Println("Error: " + err.Error())
    return;
  }
  fmt.Println("Obtained fd ", fd)
  defer syscall.Close(fd)


  sa:= &syscall.SockaddrInet4{
        Addr: [4]byte{10,75,24,6}, //defining my IP
        }
    e := syscall.Bind(fd, sa)  //binding my IP
    if e != nil {
        fmt.Println(e)   
         }   
   fmt.Println("Entering main loop")
    for {
        buf := make([]byte, 1024)
        numRead, err,_ := syscall.Recvfrom(fd,buf,0)   //reading the packets via raw sockets
        if err != nil {
            fmt.Println("error")
                }
        fmt.Printf("%X\n",buf[:numRead])
    }
}`

I'm trying to receive packets from all protocol using ETH_P_ALL in raw socket.But i'm not able to receive packets.This code is written in GoLang. Can you guys please help me to sort it out

Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
nivetha a
  • 11
  • 1

0 Answers0