close raw sockets on error
This commit is contained in:
parent
6dff0847b3
commit
d9ff4d40cc
|
@ -53,6 +53,7 @@ proc setupEthernetCapturingSocket*(iface: NetworkInterface): AsyncFD =
|
|||
if bindAddr(result.SocketHandle,
|
||||
cast[ptr SockAddr](addr sa),
|
||||
sizeof(Sockaddr_ll).SockLen) != 0:
|
||||
closeSocket(result)
|
||||
raise newException(RawSocketError, "cannot bind to interface")
|
||||
|
||||
# Enable promiscuous mode, see netdevice(7) man page
|
||||
|
@ -62,6 +63,7 @@ proc setupEthernetCapturingSocket*(iface: NetworkInterface): AsyncFD =
|
|||
PACKET_ADD_MEMBERSHIP.cint,
|
||||
addr req,
|
||||
sizeof(req).SockLen) != 0:
|
||||
closeSocket(result)
|
||||
raise newException(RawSocketError, "cannot enable promiscuous mode")
|
||||
|
||||
proc setupTcpInjectingSocket*(): AsyncFD =
|
||||
|
@ -74,4 +76,5 @@ proc setupTcpInjectingSocket*(): AsyncFD =
|
|||
var sockOpt: cint = 1
|
||||
if setsockopt(result.SocketHandle, IPPROTO_IP, IP_HDRINCL, addr sockOpt,
|
||||
sizeof(sockOpt).SockLen) != 0:
|
||||
closeSocket(result)
|
||||
raise newException(RawSocketError, "cannot set IP_HDRINCL option")
|
||||
|
|
Loading…
Reference in New Issue