Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by rwniceing
at 2024-09-06 07:39:42
Point:500 Replies:6 POST_ID:829223USER_ID:12079
Topic:
Network Operations;Networking Protocols;Miscellaneous Networking
I tried one socket tutorial example as following code on my window 7 for getting webpage from remote sites or localhost that is successful. TCP is at transport layer and IP is at network layer. When doing the socket_create(), we need to know protocol number such as "0" for IP and "6" for TCP.
Question-1 Why I tried either socket_create(AF_INET, SOCK_STREAM, 0) or
socket_create(AF_INET, SOCK_STREAM, 6) on the code, both are worked and outpage webpage are
same ? If both work, IP and TCP protocol spec is no different , Right ?
Question-2. This php program code, we treat it at transport or network layer or both layer together ?
Question-3 Our computer network card is handling Data layer and network layer(IP) and Transport layer(TCP) all together , right ?
Those protocol is shown into each layer descibed at this link ,http://www.protocols.com/pbook/tcpip1.htm
Please advise
Rwniceing
Question-1 Why I tried either socket_create(AF_INET, SOCK_STREAM, 0) or
socket_create(AF_INET, SOCK_STREAM, 6) on the code, both are worked and outpage webpage are
same ? If both work, IP and TCP protocol spec is no different , Right ?
Question-2. This php program code, we treat it at transport or network layer or both layer together ?
Question-3 Our computer network card is handling Data layer and network layer(IP) and Transport layer(TCP) all together , right ?
Those protocol is shown into each layer descibed at this link ,http://www.protocols.com/pbook/tcpip1.htm
Please advise
Rwniceing
<?php//- http://php.net/manual/en/function.header.php//- http://en.wikipedia.org/wiki/Internet_Control_Message_Protocol//- http://www.protocols.com/pbook/tcpip1.htm$protocol = 'tcp';$get_prot = getprotobyname($protocol);echo $get_prot."----protocol";if(!($sock = socket_create(AF_INET, SOCK_STREAM, 6))){ $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Couldn't create socket: [$errorcode] $errormsg");} echo "Socket created"; if(!socket_connect($sock , '127.0.0.1' , 80)){ $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Could not connect: [$errorcode] $errormsg");} echo "Connection established";$message = "GET / HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";$message = "GET / HTTP/1.1";$message .= "Host:";$message .= "Connection: Close";//Send the message to the serverif( ! socket_send ( $sock , $message , strlen($message) , 0)){$errorcode = socket_last_error();$errormsg = socket_strerror($errorcode);die("Could not send data: [$errorcode] $errormsg");}echo "Message send successfully";//Now receive reply from serverif(socket_recv ( $sock , $buf , 6144 , MSG_WAITALL ) === FALSE){ $errorcode = socket_last_error(); $errormsg = socket_strerror($errorcode); die("Could not receive data: [$errorcode] $errormsg");}//print the received messageecho $buf;/* getprotobyname0 <---> ip1 <---> icmp2 <---> igmp3 <---> ggp4 <---> ipencap5 <---> st6 <---> tcp8 <---> egp9 <---> igp12 <---> pup17 <---> udp20 <---> hmp22 <---> xns-idp27 <---> rdp29 <---> iso-tp433 <---> dccp36 <---> xtp37 <---> ddp38 <---> idpr-cmtp41 <---> ipv643 <---> ipv6-route44 <---> ipv6-frag45 <---> idrp46 <---> rsvp47 <---> gre50 <---> esp51 <---> ah57 <---> skip58 <---> ipv6-icmp59 <---> ipv6-nonxt60 <---> ipv6-opts73 <---> rspf81 <---> vmtp88 <---> eigrp89 <---> ospf93 <---> ax.2594 <---> ipip97 <---> etherip98 <---> encap103 <---> pim108 <---> ipcomp112 <---> vrrp115 <---> l2tp124 <---> isis132 <---> sctp133 <---> fc135 <---> mobility-header136 <---> udplite137 <---> mpls-in-ip138 <---> manet139 <---> hip140 <---> shim6141 <---> wesp142 <---> rohc*/?> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:92:93:94:95:96:97:98:99:
Author: rwniceing replied at 2024-09-06 20:54:04
Dave, thanks for your reply,
Answer-1 is correct 0 and 6 both are working as same since window connection default is set to TCP . "0" means computer default protocol. '6" is set for TCP
Answer-2 not sure yet
Answer-3 not sure yet
Answer-1 is correct 0 and 6 both are working as same since window connection default is set to TCP . "0" means computer default protocol. '6" is set for TCP
Answer-2 not sure yet
Answer-3 not sure yet
Expert: Dave Baldwin replied at 2024-09-06 20:50:33
If you read the man page http://us3.php.net/manual/en/function.socket-create.php , you will not see any mention of OSI or TCP/IP model. You will only see the functions that are available.
This page http://us3.php.net/manual/en/sockets.constants.php shows the constants that can be used. It is not completely clear where they should be used.
This page http://us3.php.net/manual/en/sockets.constants.php shows the constants that can be used. It is not completely clear where they should be used.
Author: rwniceing replied at 2024-09-06 20:34:21
Answer-1: When select AF_INET, the socket will use IPv4 . When select AF_INET6, the socket will use IPv6 So IP on internet or network layer is already taken care for communication with AF_INET. So Choose what protocol using on the transport layer before IP internet/network layer, we need to use protocol
number to specifiy it. Select 0, it will choose computer default ,TCP. Select 6, it will choose TCP also . So both protocol num work the same if computer default is set to TCP.
Answer-2:More or less depended on which model you choose OSI or TCP/IP model
Answer-3: date decoding diagram is completed on the socket software, so network card may just act as the data layer for routing or send date to remote IP address ?
Please advise
number to specifiy it. Select 0, it will choose computer default ,TCP. Select 6, it will choose TCP also . So both protocol num work the same if computer default is set to TCP.
Answer-2:More or less depended on which model you choose OSI or TCP/IP model
Answer-3: date decoding diagram is completed on the socket software, so network card may just act as the data layer for routing or send date to remote IP address ?
Please advise
Expert: Dave Baldwin replied at 2024-09-06 11:39:15
Here http://en.wikipedia.org/wiki/Internet_protocol_suite is a different view and some history about TCP/IP and protocols. Note that the real implementations of TCP/IP have never exactly matched the theoretical versions. The code came along before the theory in this case. In real usage, you have to go by what functions are available.
Author: rwniceing replied at 2024-09-06 09:51:33
david,thanks for your reply, the code is working but why it is worked for either socket_create(AF_INET, SOCK_STREAM, 0) or socket_create(AF_INET, SOCK_STREAM, 6) ? Do you understand my questions that is more related to concept than permission or code . ?If not, I can write it with more detail
Expert: David Johnson, CD, MVP replied at 2024-09-06 09:37:30
Microsoft has put a lot of restrictions on raw sockets
TCP data cannot be sent over raw sockets.
UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
A call to the bind function with a raw socket for the IPPROTO_TCP protocol is not allowed.
Note The bind function with a raw socket is allowed for other protocols (IPPROTO_IP, IPPROTO_UDP, or IPPROTO_SCTP, for example).
http://msdn.microsoft.com/en-ca/library/windows/desktop/ms740548%28v=vs.85%29.aspx
TCP data cannot be sent over raw sockets.
UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
A call to the bind function with a raw socket for the IPPROTO_TCP protocol is not allowed.
Note The bind function with a raw socket is allowed for other protocols (IPPROTO_IP, IPPROTO_UDP, or IPPROTO_SCTP, for example).
http://msdn.microsoft.com/en-ca/library/windows/desktop/ms740548%28v=vs.85%29.aspx