Subject: SOCK_DGRAM and friends (This message is being sent to all CPSC 360 students) A diligent student asks: > Dr. Westall, > I'm not sure what exactly is going on, but creating the socket is > working on note examples that it's not supposed to work for, and not > working on examples it is supposed to work on. I was working on > shadow7. > > example: not supposed to work > [16:42:52] ./hostinfo 2 2 6 5785 > domain = 2, socktype = 2, proto = 6, port = 5785 > s = 3 > done > > example: supposed to work > [16:43:08] ./hostinfo 2 1 6 5785 > domain = 2, socktype = 1, proto = 6, port = 5785 > s = -1 > socket failed: Protocol not supported The answer is: That would be because in the solaris the #defines say 94 #define SOCK_STREAM 2 /* stream socket */ 95 #define SOCK_DGRAM 1 /* datagram socket */ 96 #define SOCK_RAW 4 /* raw-protocol interface */ but in Linux the declaration is: ./bits/socket.h: SOCK_DGRAM = 2, SOCK_STREAM = 1, Thus its always best to use the "standard name". The relative strengths of the names is: IPPROTO_UDP = 17 --- super strong AF/PF_INET = 2 --- pretty strong SOCK_DGRAM/STREAM -- pretty weak