Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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?

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.

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?

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.

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!

![]() |
![]() |
![]() |

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