Ejemplo n.º 1
0
// RAWTCPListen creates a listener to capture traffic from RAW_SOCKET
func NewListener(addr string, port string) (rawListener *Listener) {
	rawListener = &Listener{}

	rawListener.c_packets = make(chan *TCPPacket, 100)
	rawListener.c_messages = make(chan *TCPMessage, 100)
	rawListener.c_del_message = make(chan *TCPMessage, 100)
	rawListener.messages = make(map[string]*TCPMessage)

	rawListener.addr = addr
	rawListener.port, _ = strconv.Atoi(port)
	rawListener.host = common.GetHostIp()

	go rawListener.listen()
	go rawListener.readRAWSocket()

	return
}
Ejemplo n.º 2
0
func getInterfaceName() string {
	ip := common.GetHostIp()
	devices, err := pcap.FindAllDevs()
	if err != nil {
		log.Fatal(err)
	}

	for _, dev := range devices {
		addrs := dev.Addresses
		for _, addr := range addrs {
			if addr.IP.String() == ip {
				return dev.Name
			}
		}
	}

	return ""
}