Download - LS4 Socket Types
-
7/31/2019 LS4 Socket Types
1/11
1
SocketsClient-server paradigm
-
7/31/2019 LS4 Socket Types
2/11
2
Client-server paradigm
Typical network app has two pieces: clientandserver
applicationtransportnetworkdata linkphysical
applicationtransport
networkdata linkphysical
Client:
initiates contact with server (speaks
first)
typically requests service from server, for Web, client is implemented in
browser; for e-mail, in mail reader
Server:
provides requested service to client, via
replies e.g., Web server sends requested Web
page, mail server delivers e-mail
request
reply
-
7/31/2019 LS4 Socket Types
3/11
-
7/31/2019 LS4 Socket Types
4/11
-
7/31/2019 LS4 Socket Types
5/11
5
socket()
bind()
listen()
accept()
read()
write()
procees request
get a blocked client
Server Process
TCP UDP
socket()
connect()
write()
read()
Client Process
socket()
bind()
sendto()
recvfrom()
Client Process
1
2
3
socket()
bind()
recvfrom()
sendto()
Server Process
get a blocked client
process request
UNIX
version
-
7/31/2019 LS4 Socket Types
6/11
6
socket()
bind()
listen()
accept()
recv()
send()
process request
get a blocked client
Server Process
TCP UDP
socket()
connect()
send()
recv()
Client Process
socket()
bind()
sendto()
recvfrom()
Client Process
1
2
3
socket()
bind()
recvfrom()
sendto()
Server Process
get a blocked client
process request
Winsock
or Unix
version
-
7/31/2019 LS4 Socket Types
7/117
IP (Raw) Socket
To use RAW sockets in Unix it is mandatory that one haveroot authority. To create a RAW socket write:s=socket(AF_INET,SOCK_RAW,[protocol])
Then you can send or receive over it. Raw sockets are usedto generate / receive packets of a type that the kerneldoesn't explicitly support.
-
7/31/2019 LS4 Socket Types
8/11
8
IP Raw Socket example
A familiar example is PING. Ping works by sending out an ICMPecho packet.
It formats an ICMP echo packet and sends it out over aSOCK_RAW, waiting for a response.
-
7/31/2019 LS4 Socket Types
9/11
9
Names and addresses
struct hostent *gethostbyname(char *hostname);
Converts textual name to a hostent structure
This structure contains all IPv4/IPv6 addresses of a host
/* Returns in Network Order */
unsigned long inet_addr(char *ipaddrstring);
Converts dotted decimal address to a 32 bit address
Similar functionality provided by inet_pton()
Deprecated. Better to use inet_aton()
-
7/31/2019 LS4 Socket Types
10/11
10
Byte ordering routines
How to interpret bits on the wire
Different computers store bytes in different order in memory
Network byte order (nbo) is big endian
Example: internal representation of 224
-
7/31/2019 LS4 Socket Types
11/11
11
Kindly visit us at
linuxsocketprogrammingshare.blogspot.com
And at our facebook group
https://www.facebook.com/groups/codingtheworld/
Thank you
https://www.facebook.com/groups/codingtheworld/https://www.facebook.com/groups/codingtheworld/