1

I was playing with raw sockets on my Windows 8 machine. I created a socket as follows:

s=socket(AF_INET,SOCK_RAW,IPPROTO_TCP)
s.bind((gethostname(),0)) s.ioctl(SIO_RCVALL,RCVALL_ON)

But on binding line python is throwing an exception as follows

OSError: [WinError 10022] An invalid argument was supplied

But with IPPROTO_UDP as the third argument, it's working fine.

I also have an AWS machine running Windows 10, on which it's working fine with same third argument (IPPROTO_TCP)

Why am I getting this error?

Josiah Yoder
  • 3,321
  • 4
  • 40
  • 58
  • [Same question for C++](https://stackoverflow.com/questions/72834234/how-to-send-tcp-packets-using-raw-sockets-in-winsock). Same answer. :-( – Josiah Yoder Oct 28 '22 at 16:50

1 Answers1

1

Found the reason from Microsoft documentation... https://learn.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2

TCP data cannot be sent over raw sockets.

Josiah Yoder
  • 3,321
  • 4
  • 40
  • 58