Computing.Net > Forums > Programming > Python + Windows + sockets

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Python + Windows + sockets

Reply to Message Icon

Name: Birdman
Date: December 25, 2004 at 20:53:51 Pacific
OS: Windows XP Pro
CPU/Ram: 80x86
Comment:

A program I wrote in python uses the symbol AF_PACKET. It runs just find under Linux, importing * from socket. But under Windows, AF_PACKET is said to be undefined.

Any ideas why this symbol might not be implemented under Windows, and what I should define it as?



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: December 25, 2004 at 23:35:06 Pacific
Reply:

If it worked under Linux it's probably because bits/socket.h is full of compatibility synonyms and stuff for network protocols and address formats that Windows doesn't use or support and AF_PACKET got treated as AF_INET when you used it but it's not the right one to use. When Python is built on Linux it gets all this stuff from that header and so doesn't give you an error but it's not portable.

Since you obviously have access to Linux you should have access to the documentation - all this socket stuff is well documented in both the python html and glibc docs. You'll notice that there's only 3 or 4 standard AF_*s mentioned (even in glibc) - for the local UNIX sockets and the two internet protocols - and you probably want AF_INET. In fact I don't think there is even an AF_UNIX or AF_LOCAL equivalent on Windows so that leaves you with just AF_INET or AF_INET6 to choose from.



0

Response Number 2
Name: Birdman
Date: December 26, 2004 at 09:57:58 Pacific
Reply:

Thanks for the help. Both AF_INET and AF_INET6 are recognized, and I'm guessing that AF_INET will be the right one. But now I'm running into another problem: I'm getting errors telling me that my protocol (0x0806) isn't supported. 0x0806 is ARP, so I don't see why it wouldn't be supported.

Any ideas on this?


0

Response Number 3
Name: Wolfbone
Date: December 26, 2004 at 11:46:45 Pacific
Reply:

Assuming you've followed the Python documentation and examples and you're correctly calling socket() with 2 parameters and not 3:

s = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)

(and doing everything else right) then it's likely a Windows or Python_on_Windows problem and I have no idea about anything Windowsy.


0

Response Number 4
Name: Birdman
Date: December 26, 2004 at 22:09:56 Pacific
Reply:

OK, well thanks for the help. I was doing as you said, using two parameters, not including the protocol. I did more googling, and it seems that the socket module for Windows just doesn't support the same raw access that Linux does. Windows DOES support using socket.socket(socket.AF_INET,socket.SOCK_RAW,socket.PROTO_RAW)
(I may have garbled the last argument, I forget exactly what it is), but that doesn't do exactly what I want. It's not critical that the code be portable to windows, so I'll just leave it as it is.

Thanks again for the help!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Python + Windows + sockets

Windows Sockets www.computing.net/answers/programming/windows-sockets/9411.html

windows socket programming www.computing.net/answers/programming/windows-socket-programming/4211.html

Windows socket programming www.computing.net/answers/programming/windows-socket-programming/5311.html