Skip to contentSkip to conversation

ipv6.7: SOCK_DGRAM can accept different protocols?

BUG? Alejandro Colomar 2 participants 2 messages Sep 16, 2021 – Sep 17, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

Reading a stackoverflow question <https://stackoverflow.com/questions/51996808/do-we-need-to-specify-protocol-when-type-is-sock-dgram-or-sock-stream-in-soc> it noted that, while ip(7) notes that protocol can be left as 0 for both SOCK_STREAM and SOCK_DGRAM, ipv6(7) is misleading and seems to suggest that protocol may be significant for SOCK_DGRAM (at least in the SYNOPSIS).

I guess that's not true, and it can be left as 0, but since I don't know, I'll ask.

Thanks,

Alex

--

IP(7) Linux Programmer's Manual IP(7)

NAME
ip - Linux IPv4 protocol implementation

SYNOPSIS

       #include <sys/socket.h>
       #include <netinet/in.h>
       #include <netinet/ip.h> /* superset of previous */

       tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
       udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
       raw_socket = socket(AF_INET, SOCK_RAW, protocol);

--

IPV6(7) Linux Programmer's Manual IPV6(7)

NAME
ipv6 - Linux IPv6 protocol implementation

SYNOPSIS

       #include <sys/socket.h>
       #include <netinet/in.h>

       tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
       raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
       udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#1 lore raw
Quoted 8 lines · Alejandro Colomar

Hi,

Reading a stackoverflow question
<https://stackoverflow.com/questions/51996808/do-we-need-to-specify-protocol-when-type-is-sock-dgram-or-sock-stream-in-soc>
it noted that, while ip(7) notes that protocol can be left as 0 for both SOCK_STREAM and SOCK_DGRAM, ipv6(7) is misleading and seems to suggest that protocol may be significant for SOCK_DGRAM (at least in the SYNOPSIS).

It can be left as 0, but, I think, IPPROTO_UDPLITE (at least) can be specified in both cases, if the caller wishes so (as well as IPPROTO_MPTCP/IPPROTO_SCTP for SOCK_STREAM, and some other, more obscure protocols, like DCCP or L2TP).

Quoted 45 lines

I guess that's not true, and it can be left as 0, but since I don't know, I'll ask.

Thanks,

Alex

--

IP(7) Linux Programmer's Manual IP(7)

NAME
ip - Linux IPv4 protocol implementation

SYNOPSIS

        #include <sys/socket.h>
        #include <netinet/in.h>
        #include <netinet/ip.h> /* superset of previous */

        tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
        udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
        raw_socket = socket(AF_INET, SOCK_RAW, protocol);

--

IPV6(7) Linux Programmer's Manual IPV6(7)

NAME
ipv6 - Linux IPv6 protocol implementation

SYNOPSIS

        #include <sys/socket.h>
        #include <netinet/in.h>

        tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
        raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
        udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);

--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

Signature · 3 lines
Eugene Syromyatnikov
mailto:[email protected]
xmpp:esyr@jabber.{ru|org}