nativesockets.IPPROTO_IP is wrong here; use setsockopt instead of setSockOptInt
This commit is contained in:
parent
504445a118
commit
5cc152c039
|
@ -1,12 +1,10 @@
|
||||||
import asyncdispatch
|
import asyncdispatch
|
||||||
from nativesockets import
|
from nativesockets import
|
||||||
AF_INET,
|
AF_INET,
|
||||||
IPPROTO_IP,
|
|
||||||
IPPROTO_TCP,
|
IPPROTO_TCP,
|
||||||
SOCK_RAW,
|
SOCK_RAW,
|
||||||
bindAddr,
|
bindAddr,
|
||||||
htons,
|
htons
|
||||||
setSockOptInt
|
|
||||||
from posix import setsockopt, SockAddr, SockLen, SocketHandle
|
from posix import setsockopt, SockAddr, SockLen, SocketHandle
|
||||||
import network_interface
|
import network_interface
|
||||||
|
|
||||||
|
@ -34,6 +32,7 @@ var
|
||||||
AF_PACKET {.importc: "AF_PACKET", header: "<sys/socket.h>".}: cushort
|
AF_PACKET {.importc: "AF_PACKET", header: "<sys/socket.h>".}: cushort
|
||||||
SOL_PACKET {.importc: "SOL_PACKET", header: "<sys/socket.h>".}: cushort
|
SOL_PACKET {.importc: "SOL_PACKET", header: "<sys/socket.h>".}: cushort
|
||||||
ETH_P_ALL {.importc: "ETH_P_ALL", header: "<linux/if_ether.h>".}: cushort
|
ETH_P_ALL {.importc: "ETH_P_ALL", header: "<linux/if_ether.h>".}: cushort
|
||||||
|
IPPROTO_IP {.importc: "IPPROTO_IP", header: "<netinet/in.h>".}: cint
|
||||||
IP_HDRINCL {.importc: "IP_HDRINCL", header: "<netinet/in.h>".}: cint
|
IP_HDRINCL {.importc: "IP_HDRINCL", header: "<netinet/in.h>".}: cint
|
||||||
PACKET_ADD_MEMBERSHIP {.importc: "PACKET_ADD_MEMBERSHIP", header: "<linux/if_packet.h>".}: cushort
|
PACKET_ADD_MEMBERSHIP {.importc: "PACKET_ADD_MEMBERSHIP", header: "<linux/if_packet.h>".}: cushort
|
||||||
PACKET_MR_PROMISC {.importc: "PACKET_MR_PROMISC", header: "<linux/if_packet.h>".}: cushort
|
PACKET_MR_PROMISC {.importc: "PACKET_MR_PROMISC", header: "<linux/if_packet.h>".}: cushort
|
||||||
|
@ -70,6 +69,9 @@ proc setupTcpInjectingSocket*(): AsyncFD =
|
||||||
result = createAsyncNativeSocket(AF_INET.cint, SOCK_RAW.cint,
|
result = createAsyncNativeSocket(AF_INET.cint, SOCK_RAW.cint,
|
||||||
IPPROTO_TCP.cint)
|
IPPROTO_TCP.cint)
|
||||||
|
|
||||||
# Tell the kernel to not generate an IP header, as we generate it ourselves,
|
## Tell the kernel to not generate an IP header, as we generate it ourselves,
|
||||||
# see raw(7) man page.
|
## see raw(7) man page.
|
||||||
setSockOptInt(result.SocketHandle, IPPROTO_IP.int, IP_HDRINCL, 1)
|
var sockOpt: cint = 1
|
||||||
|
if setsockopt(result.SocketHandle, IPPROTO_IP, IP_HDRINCL, addr sockOpt,
|
||||||
|
sizeof(sockOpt).SockLen) != 0:
|
||||||
|
raise newException(RawSocketError, "cannot set IP_HDRINCL option")
|
||||||
|
|
Loading…
Reference in New Issue