1
import socket # the public network interface HOST = socket.gethostbyname(socket.gethostname()) # create a raw socket and bind it to the public interface s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) s.bind((HOST, 0)) # Include IP headers s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # receive all packages s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) //Error Occurs on this line # receive a package print(s.recvfrom(65565)) # disabled promiscuous mode s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) 

When I try to run this code I get:

Traceback (most recent call last): File "D:/Users/Gen/PycharmProjects/hex2float/socketerror.py", line 14, in <module> s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) OSError: [WinError 10045] The attempted operation is not supported for the type of object referenced 

This code was taken from Python document so I am confused why it does not work. Can anyone explain why?

1 Answer 1

3

perhaps you need to delete socket.AF_INET from u sentence s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)

as I use SOCK_DGRAM without AF_INET to build server successfully.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.