4

Yes, I did already try to find information on this.

The Python socket documentation has this list of what I believe are protocols:

SO_*
socket.SOMAXCONN
MSG_*
SOL_*
IPPROTO_*
IPPORT_*
INADDR_*
IP_*
IPV6_*
EAI_*
AI_*
NI_*
TCP_*

What exactly do they do? Let's say I used

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)

What does this do? I understand it's a raw socket, but does the IPPROTO_IP mean I have to construct everything? (i.e. the IP header down to the TCP to the data?)

The Python documentation says I can find information on the above in the Unix documentation on sockets, but I couldn't find the document. Anyone know where it is?

asked Jul 15, 2014 at 22:37
3
  • Yes, IPPROTO_IP means raw IP, and you probably don't want it. (Though you don't need to construct the IP header, only the TCP header.) As for the documentation, try linux.die.net/man/7/socket. Commented Jul 15, 2014 at 22:41
  • Thanks, much appreciated. So just to make sure, if I used (IPPROTO_IP) it means any protocol upward of IP must be constructed by me? So if I was using TCP i'd construct TCP heads, UDP, etc...? Commented Jul 15, 2014 at 22:46
  • Right. Plus, for TCP you'd have to implement your own handshaking, acknowledgements, retransmission, etc. Commented Jul 16, 2014 at 7:46

1 Answer 1

8

There are a lot of Linux manual pages describing socket:

In general, we use these arguments for socket:

  1. Address family: AF_INET for internet domain address family, AF_UNIX for UNIX domain address family.

  2. Socket type: SOCK_STREAM for TCP, SOCK_DGRAM for UDP. Of course you can use SOCK_RAW for directly access IP protocol.

  3. Protocol: when using TCP or UDP, leave it to 0 is just fine; when using RAW, you can specify protocol to 0, IPPROTO_TCP for TCP sockets, IPPROTO_UDP for UDP sockets.

And, SO_ means "socket option", SOL_ means "socket option level", which are used to set socket options through setsockopt (also mentioned in SOCKET).

In fact, you can find more pages at the bottom of these pages in the SEE ALSO section. Note that the page of 2 or 3 is a concrete system call or library function, pages of 7 is what you need.

answered Jul 15, 2014 at 23:33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.