예제 #1
0
파일: listener.go 프로젝트: xxoxx/httpcap
// 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
}
예제 #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 ""
}