I am doing some network programming stuff with python. I know that sockets can be created like below...
For TCP sockets
socket.socket(
family = socket.AF_INET,
type = socket.SOCK_STREAM,
proto = socket.IPPROTO_IP,
fileno = None)
socket.socket(
family = socket.AF_INET,
type = socket.SOCK_STREAM,
proto = socket.IPPROTO_TCP,
fileno = None)
For UDP sockets
socket.socket(
family = socket.AF_INET,
type = socket.SOCK_DGRAM,
proto = socket.IPPROTO_IP,
fileno = None)
socket.socket(
family = socket.AF_INET,
type = socket.SOCK_DGRAM,
proto = socket.IPPROTO_TCP,
fileno = None)
For raw sockets to capture all packets...
socket.socket(
family = socket.AF_PACKET,
type = socket.SOCK_RAW,
proto = socket.htons(0x0003),
fileno = None
)
Mostly I have been doing TCP, UDP and raw sockets.Apart from TCP and UDP there are many other protocols and Python socket library has support for these other protocols as well. But when I tried to do some works with some other protocols, things are not always correct. Sometimes while creating a socket, everything looks correct but gives error.I have many confusions on which combination of family, type and protocol will fit together correctly while creating a socket. I am consciously not giving any specific code sample here to better explain my problem, instead I am looking for the networking and protocol related logic and knowledge which is required to properly create a socket.
Please kindly share some views and comments on this topic.