net: implement a SO_PROTOCOL getsockoption

Similar to SO_TYPE returning the socket type, SO_PROTOCOL allows to
retrieve the protocol used with a given socket.

I am not quite sure why we have that-many copies of socket.h, and why
the values are not the same on all arches either, but for where hex
numbers dominate, I use 0x1029 for SO_PROTOCOL as that seems to be
the next free unused number across a bunch of operating systems, or
so Google results make me want to believe. SO_PROTOCOL for others
just uses the next free Linux number, 38.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jan Engelhardt 2009-08-04 07:28:28 +00:00 committed by David S. Miller
parent c1c00ab862
commit 49c794e946
20 changed files with 40 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#define SO_RCVTIMEO 0x1012 #define SO_RCVTIMEO 0x1012
#define SO_SNDTIMEO 0x1013 #define SO_SNDTIMEO 0x1013
#define SO_ACCEPTCONN 0x1014 #define SO_ACCEPTCONN 0x1014
#define SO_PROTOCOL 0x1028
/* linux-specific, might as well be the same as on i386 */ /* linux-specific, might as well be the same as on i386 */
#define SO_NO_CHECK 11 #define SO_NO_CHECK 11

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* __ASM_AVR32_SOCKET_H */ #endif /* __ASM_AVR32_SOCKET_H */

View File

@ -59,6 +59,8 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -57,5 +57,7 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -66,4 +66,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_IA64_SOCKET_H */ #endif /* _ASM_IA64_SOCKET_H */

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_M32R_SOCKET_H */ #endif /* _ASM_M32R_SOCKET_H */

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -66,4 +66,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_MICROBLAZE_SOCKET_H */ #endif /* _ASM_MICROBLAZE_SOCKET_H */

View File

@ -42,6 +42,7 @@ To add: #define SO_REUSEPORT 0x0200 /* Allow local address and port reuse. */
#define SO_SNDTIMEO 0x1005 /* send timeout */ #define SO_SNDTIMEO 0x1005 /* send timeout */
#define SO_RCVTIMEO 0x1006 /* receive timeout */ #define SO_RCVTIMEO 0x1006 /* receive timeout */
#define SO_ACCEPTCONN 0x1009 #define SO_ACCEPTCONN 0x1009
#define SO_PROTOCOL 0x1028 /* protocol type */
/* linux-specific, might as well be the same as on i386 */ /* linux-specific, might as well be the same as on i386 */
#define SO_NO_CHECK 11 #define SO_NO_CHECK 11

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -24,6 +24,7 @@
#define SO_RCVTIMEO 0x1006 #define SO_RCVTIMEO 0x1006
#define SO_ERROR 0x1007 #define SO_ERROR 0x1007
#define SO_TYPE 0x1008 #define SO_TYPE 0x1008
#define SO_PROTOCOL 0x1028
#define SO_PEERNAME 0x2000 #define SO_PEERNAME 0x2000
#define SO_NO_CHECK 0x400b #define SO_NO_CHECK 0x400b

View File

@ -64,4 +64,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_POWERPC_SOCKET_H */ #endif /* _ASM_POWERPC_SOCKET_H */

View File

@ -65,4 +65,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_SOCKET_H */ #endif /* _ASM_SOCKET_H */

View File

@ -29,6 +29,8 @@
#define SO_RCVBUFFORCE 0x100b #define SO_RCVBUFFORCE 0x100b
#define SO_ERROR 0x1007 #define SO_ERROR 0x1007
#define SO_TYPE 0x1008 #define SO_TYPE 0x1008
#define SO_PROTOCOL 0x1028
/* Linux specific, keep the same. */ /* Linux specific, keep the same. */
#define SO_NO_CHECK 0x000b #define SO_NO_CHECK 0x000b

View File

@ -57,4 +57,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _ASM_X86_SOCKET_H */ #endif /* _ASM_X86_SOCKET_H */

View File

@ -68,4 +68,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* _XTENSA_SOCKET_H */ #endif /* _XTENSA_SOCKET_H */

View File

@ -60,4 +60,6 @@
#define SO_TIMESTAMPING 37 #define SO_TIMESTAMPING 37
#define SCM_TIMESTAMPING SO_TIMESTAMPING #define SCM_TIMESTAMPING SO_TIMESTAMPING
#define SO_PROTOCOL 38
#endif /* __ASM_GENERIC_SOCKET_H */ #endif /* __ASM_GENERIC_SOCKET_H */

View File

@ -482,6 +482,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
sk->sk_reuse = valbool; sk->sk_reuse = valbool;
break; break;
case SO_TYPE: case SO_TYPE:
case SO_PROTOCOL:
case SO_ERROR: case SO_ERROR:
ret = -ENOPROTOOPT; ret = -ENOPROTOOPT;
break; break;
@ -764,6 +765,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
v.val = sk->sk_type; v.val = sk->sk_type;
break; break;
case SO_PROTOCOL:
v.val = sk->sk_protocol;
break;
case SO_ERROR: case SO_ERROR:
v.val = -sock_error(sk); v.val = -sock_error(sk);
if (v.val == 0) if (v.val == 0)