Python Socket.error Error 10022
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and socket.error errno 22 invalid argument python policies of this site About Us Learn more about Stack Overflow the
Socket Error Errno 10022 An Invalid Argument Was Supplied
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags python socket.accept errno 22 Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only
Socket Error Invalid Argument
takes a minute: Sign up socket.error errno=10022 when using socket.send(packet, (ip, port)) up vote 0 down vote favorite I learned to send packet using socket by Python, but there is an error (socket.error errno=10022) when running the code below on the Windows machine, and everything works fine on the Linux. How can I fix it? try: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP) python winerror 10022 except socket.error , msg: print 'Socket could not be created. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] sys.exit() s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) source_ip = self.source dest_ip = self.destination packet = ''; ip_header = self.construct_ip_header() tcp_header = self.construct_tcp_header() packet = ip_header + tcp_header s.sendto(packet, (dest_ip , 0 )) python sockets share|improve this question asked Sep 15 '15 at 15:30 lixiaoyu 230416 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote Error 10022 from Winsock means "Invalid argument" possibly because you're trying to mix SOCK_RAW with IPPROTO_TCP which are incompatible. The third argument is probably being ignored on linux, but windows is complaining about it. Something is also very wrong with your code sample - you've tried to open a raw socket, but are manually writing tcp and ip headers, but not handling the TCP state machine yourself? This seems highly overcomplicated unless you have some very specialist requirements. If you're just trying to open a TCP socket between this code and a server I'd suggest to go back the examples at https://docs.python.org/2/library/socket.htm
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting
Python Setsockopt
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
Oserror: [winerror 10022] An Invalid Argument Was Supplied
Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: python udp socket Sign up socket.recvfrom(1024) throws socket.error invalid argument supplied up vote 0 down vote favorite I have started to learn UDP sockets but for some reason this code is throwing an error. why does this code: s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) x=s.recvfrom(1024) throw an error http://stackoverflow.com/questions/32590031/socket-error-errno-10022-when-using-socket-sendpacket-ip-port of invalid argument supplied? python sockets share|improve this question asked Mar 4 at 20:42 J leong 337 1 Works for me, can you show the full error output and traceback? –cdarke Mar 4 at 20:54 Are you running on windows? Since you haven't bound a port, I'm not sure what should happen... on my linux machine I don't get an error but the call doesn't return either. On windows there may be an underlying permissions error. –tdelaney Mar 4 http://stackoverflow.com/questions/35805664/socket-recvfrom1024-throws-socket-error-invalid-argument-supplied at 21:04 @tdelaney yea im using windows. How would i bind it to a port? –J leong Mar 4 at 21:08 Here is the error: Traceback (most recent call last): File "C:\python practice\udpclient.py", line 4, in
here for a quick overview of the site Help Center Detailed answers to any questions you might have http://stackoverflow.com/questions/29580485/python-tcp-sniffer-under-windows Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads https://www.daniweb.com/programming/software-development/threads/370655/python-socket-problem with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, invalid argument just like you, helping each other. Join them; it only takes a minute: Sign up Python TCP Sniffer under Windows up vote 0 down vote favorite So I am attempting to retro fit an amazing network packet sniffer already established but for linux. The basic jist is the code below works for socket.IPPROTO_UDP but not socket.IPPROTO_TCP. an invalid argument import socket #create an INET, STREAMing socket 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_TCP) 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) # receive a packet packet = s.recvfrom(65565) print packet The error I get when running the above is : "line 12, in s.bind((HOST, 0)) File "", line 1, in bind socket.error: [Errno 10022] An invalid argument was supplied. If I fuss around with the above and strip it to bare min: import socket s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP) # receive a packet packet = s.recvfrom(65565) print packet I get similar error but a tad diff line 7, in packet = s.recvfrom(65565) socket.error: [Errno 10022] An invalid argument was supplied The sniffer I am trying to retro fit, using same formatting etc is here: http://www.binarytides.com/python-packet-sniffer-code-linux/ -- crd to dev -- if anyone has further advise i'd appreciate it. python sockets networking packet sniffer
trying to open multiple port on a compute. I am trying to make the code multi threaded.So here is my code: import socket import thread from threading import * s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def handler(clientsock,addr): while 1: data = clientsock.recv(BUFSIZ) if not data: break def openport(port): HOST = socket.gethostname() BUFSIZ = 1024 s.bind((HOST,port)) s.listen(5) print 'Listening on port ',port for n in range(1, 10): thread.start_new_thread(openport, (n,)) while 1: print 'Waiting for connection:' clientsock, addr = s.accept() print 'Connected with: ', addr thread.start_new_thread(handler, (clientsock, addr)) And i am getting following error; C:\Python27>python m.py Waiting for connection: Traceback (most recent call last): File "m.py", line 21, in