Socket.new question

M

Markus Jais

hello

I can create a socket object like this:

Socket.new(Socket::pF_INET, Socket::SOCK_STREAM, 0)

but what exactly is the third parameter ??
according to the Pickaxe this parameter is called "protocol".

what can I specify as a third parameter instead of 0 and do I need this
sometimes ??

thanks in advance !

regards

Markus
 
S

Sam Roberts

Quoteing (e-mail address removed), on Fri, Jan 07, 2005 at 04:01:30AM +0900:
hello

I can create a socket object like this:

Socket.new(Socket::pF_INET, Socket::SOCK_STREAM, 0)

but what exactly is the third parameter ??
according to the Pickaxe this parameter is called "protocol".

what can I specify as a third parameter instead of 0 and do I need this
sometimes ??

From my systems socket manual page:

The protocol specifies a particular protocol to be used with the
socket. Normally only a single protocol exists to support a
particular socket type within a given protocol family. However, it
is possible that many protocols may exist, in which case a
particular protocol must be speci- fied in this manner. The
protocol number to use is particular to the communication domain in
which communication is to take place; see protocols(5).

from /etc/protocols:

# See also http://www.isi.edu/in-notes/iana/assignments/protocol-numbers
#
ip 0 IP # internet protocol, pseudo protocol
number
#hopopt 0 HOPOPT # hop-by-hop options for ipv6
icmp 1 ICMP # internet control message protocol
igmp 2 IGMP # internet group management protocol
ggp 3 GGP # gateway-gateway protocol
ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
st2 5 ST2 # ST2 datagram mode (RFC 1819)

So, 0 means to use IP... which is probably what you want to do!


Cheers,
Sam
 
G

Guillaume Marcais

hello

I can create a socket object like this:

Socket.new(Socket::pF_INET, Socket::SOCK_STREAM, 0)

but what exactly is the third parameter ??
according to the Pickaxe this parameter is called "protocol".

what can I specify as a third parameter instead of 0 and do I need this
sometimes ??
From 'man 7 ip' on my Linux box:

"An IP socket is created by calling the socket(2) function as
socket(PF_INET, socket_type, protocol). Valid socket types are
SOCK_STREAM to open a tcp(7) socket, SOCK_DGRAM to open a udp(7)
socket, or SOCK_RAW to open a raw(7) socket to access the IP protocol
directly. protocol is the IP protocol in the IP header to be received
or sent. The only valid values for protocol are 0 and IPPROTO_TCP for
TCP sockets and 0 and IPPROTO_UDP for UDP sockets. For SOCK_RAW you
may specify a valid IANA IP protocol defined in RFC1700 assigned num-
bers."

So basically, in most usual case (IP and TCP/UDP), specifying the third
parameter is redundant.

You can get the official list of the defined protocol from
http://www.iana.org/assignments/protocol-numbers or from /etc/protocols
on a UNIX machine (not sure where it is on a Windows box).

Hope it helps,
Guillaume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top