use IpAddress instead of string
This commit is contained in:
parent
44cc3955b5
commit
12ef92dfe9
|
@ -1,10 +1,11 @@
|
|||
from nativesockets import getAddrString
|
||||
from posix import SockAddr, Sockaddr_in, inet_ntoa, AF_INET
|
||||
from net import IpAddress, parseIpAddress, `$`
|
||||
from posix import SockAddr, AF_INET, AF_INET6
|
||||
|
||||
type
|
||||
NetworkInterface* = object
|
||||
ipAddress*: string
|
||||
netMask*: string
|
||||
ipAddress*: IpAddress
|
||||
netMask*: IpAddress
|
||||
name*: string
|
||||
index*: cint
|
||||
flags*: cuint
|
||||
|
@ -25,17 +26,18 @@ proc getifaddrs(ifap: ptr ptr Ifaddrs): int {.header: "<ifaddrs.h>", importc: "g
|
|||
proc freeifaddrs(ifap: ptr Ifaddrs): void {.header: "<ifaddrs.h>", importc: "freeifaddrs".}
|
||||
proc if_nametoindex(ifname: cstring): cuint {.header: "<net/if.h>", importc: "if_nametoindex".}
|
||||
|
||||
proc fromIpAddress*(address: string): NetworkInterface =
|
||||
proc fromIpAddress*(address: IpAddress): NetworkInterface =
|
||||
var interfaces: ptr Ifaddrs
|
||||
if getifaddrs(addr interfaces) != 0:
|
||||
raise newException(NetworkInterfaceError, "getifaddrs failed")
|
||||
var it = interfaces
|
||||
while it != nil:
|
||||
if it.ifa_addr != nil and
|
||||
it.ifa_addr.sa_family.cint == AF_INET and
|
||||
it.ifa_addr.getAddrString() == address:
|
||||
(it.ifa_addr.sa_family.cint == AF_INET or
|
||||
it.ifa_addr.sa_family.cint == AF_INET6) and
|
||||
$address == it.ifa_addr.getAddrString():
|
||||
result.ipAddress = address
|
||||
result.netMask = it.ifa_netmask.getAddrString()
|
||||
result.netMask = parseIpAddress(it.ifa_addr.getAddrString())
|
||||
result.name = $it.ifa_name
|
||||
result.index = if_nametoindex(result.name).cint
|
||||
result.flags = it.ifa_flags
|
||||
|
|
|
@ -167,7 +167,7 @@ proc doAccept(puncher: TcpSyniPuncher, future: Future[AsyncSocket]) {.async.} =
|
|||
proc connect*(puncher: TcpSyniPuncher,
|
||||
progressCb: PunchProgressCb): Future[AsyncSocket] =
|
||||
result = newFuture[AsyncSocket]("tcp_syni.connect")
|
||||
let iface = fromIpAddress($puncher.srcIp)
|
||||
let iface = fromIpAddress(puncher.srcIp)
|
||||
let rawFd = setupEthernetCapturingSocket(iface)
|
||||
asyncCheck puncher.captureSeqNumbers(rawFd, progressCb)
|
||||
for dstPort in puncher.dstPorts:
|
||||
|
|
Loading…
Reference in New Issue