What's a difference between
invoke  socket,2,1,0 
and
invoke  socket,2,1,6


???


it work fine in both cases :>
Posted on 2005-01-25 07:20:49 by etn
The following are defined in winsock2.h:
#define SOCK_STREAM 1 /* stream socket */
#define SOCK_DGRAM 2 /* datagram socket */
#define SOCK_RAW 3 /* raw-protocol interface */
#define SOCK_RDM 4 /* reliably-delivered message */
#define SOCK_SEQPACKET 5 /* sequenced packet stream */

msdn says:
In Windows Sockets 2, many new socket types will be introduced and no longer need to be specified, since an application can dynamically discover the attributes of each available transport protocol through the WSAEnumProtocols function. Socket type definitions appear in Winsock2.h, which will be periodically updated as new socket types, address families, and protocols are defined.


Why do 0 and 6 work if they are not defined?
Probably because your machine has these associated with a protocol already, verifiable using the WSAEnumProtocols function.
Posted on 2005-01-30 02:29:47 by Homer
EvilHomer2k,

I think you have mixed up the arguments. Check the synopsis for socket and you will see that the first argument is the address format (always PF_INET), the second argument is the type (in this case he's using SOCK_STREAM), and the third argument is the protocol (in his examples he uses 0, which means the caller does not wish to specify a protocol, and 6, which is the TCP protocol).

etn,

Of course it will work fine in both cases, this is because 0 will default to TCP (in most cases) when used with SOCK_STREAM and will default to UDP (in most cases) when used with SOCK_DGRAM.

To answer the title of your post, What's a difference IP or TCP socket creations? The IP protocol "wraps" the TCP protocol (see RFC's on Internet Protocol and Transmission Control Protocol). IP is used for directing the packet from one system to another while TCP makes sure this happens (adds reliability).
Posted on 2005-03-03 10:09:45 by Synfire
Yep, I did mix up the params there.
He should use the defined equates, that's what I was driving at.
That's why they have been defined - for clarity in source..
Posted on 2005-03-03 21:59:38 by Homer
Alert the presses! EvilHomer2k and I actually fully agree on something! :o

etn,
As homer just stated, it's always a good idea to use the defined equates, if not for others readability, but for your own. I have a friend, Lamezoid, who is really bad about doing this and I have tried to help him debug some code where the error ended up being a missed value (where he put 23 in his code meaning for it to be 23H). Also I suggest you not use 0 as your value, even though it defaults to IPPROTO_TCP in this case, it may not later on due to changes in the system. Always try to be direct with your arguments and try not to let the system choose for you.

Regards,
Bryant Keller
Posted on 2005-03-04 12:10:15 by Synfire
Bry, we agree, and this is news? :-D
Posted on 2005-03-05 00:43:33 by Homer
Hi Guys

as You see there is big difference between IP and TCP protocols

defined as :

#define IPPROTO_IP      0
#define IPPROTO_ICMP 1
#define IPPROTO_IGMP 2
#define IPPROTO_GGP 3
#define IPPROTO_TCP    6
#define IPPROTO_PUP    12
#define IPPROTO_UDP    17
#define IPPROTO_IDP    22
#define IPPROTO_ND      77
#define IPPROTO_RAW    255
#define IPPROTO_MAX    256 


I can't understand why it works fine.
I thought that tcp is capsulated in IP and when I use IP proto then I can create all data and tcp header by myself ...
It looks like I was wrong and it means nothin what proto you choose.

thx for effort but I can't catch it in my mind.

etn
Posted on 2005-04-22 08:47:32 by etn
You need to open a "raw socket" if you want to create IP headers yourself.
Posted on 2005-04-22 09:00:12 by f0dder
Hi F0dder!,

and what abut I need only make TCP header byself and IP automaticaly ?
isn't IP proto for it ?

thx 4 replay
best regards
Posted on 2005-04-23 03:51:54 by etn
have you read the raw sockets tutorials at http://www.bsrf.org.uk/

Thomas :P
Posted on 2005-05-02 03:13:15 by thomasantony
I can not find raw socket tutorial or any others tutorials in most friedly language (means english)
Posted on 2005-05-05 09:53:43 by etn