0
  • I'm busy trying to use socket.getaddrinfo() to resolve a domain name. When I pass in:

host = 'www.google.com', port = 80, family = socket.AF_INET, type = 0, proto = 0, flags = 0

I get a pair of socket infos like you'd expect, one with SocketKind.SOCK_DGRAM (for UDP) and and the other with SocketKind.SOCK_STREAM (TCP).

  • When I set proto to socket.IPPROTO_TCP I narrow it to only TCP as expected.

  • However, when I use proto = socket.SOCK_STREAM (which shouldn't work) I get back a SocketKind.SOCK_RAW.

  • Also, Python won't let me use proto = socket.IPPROTO_RAW - I get 'Bad hints'.

Any thoughts on what's going on here?

dputtick
  • 21
  • 2

1 Answers1

0

socket.SOCK_STREAM should be passed in the type field. Using it in the proto field probably has a very random effect, which is what you're seeing. Proto only takes the IPPROTO constants. For a raw socket, you should use type = socket.SOCK_RAW. I'm not sure getaddrinfo supports that though, it's mostly for TCP and UDP.

It's probably better to have some actual code in your questions. It's much easier to see what's going on then.

Per Johansson
  • 6,697
  • 27
  • 34