[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Socket.new question

Markus Jais

1/6/2005 7:02:00 PM

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

2 Answers

Sam Roberts

1/6/2005 7:12:00 PM

0

Quoteing markusjais@yahoo.de, 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/protoc...
#
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




Guillaume Marcais

1/6/2005 7:17:00 PM

0

On Fri, 2005-01-07 at 04:01 +0900, Markus Jais wrote:
> 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/protoc... or from /etc/protocols
on a UNIX machine (not sure where it is on a Windows box).

Hope it helps,
Guillaume.

> thanks in advance !
>
> regards
>
> Markus
>
>