Transcript M6 Lecture1

World-Wide Web
The Internet
Asia Pacific - Red
Europe/Middle East/Central Asia/Africa - Green
North America - Blue
Latin American and Caribbean - Yellow
RFC1918 IP Addresses - Cyan
Unknown - White
ISO/OSI Protocol Stack
Model
 1 Application layer: provides a
means for the user to access
information on the network through
an application. Functions typically
include identifying communication
partners, and determining
availability of required resources.
Some examples of application layer
implementations include Telnet, File
Transfer Protocol (FTP), and Simple
Mail Transfer Protocol (SMTP).
 2 Presentation layer: converts local host
computer data representations to/from a
standard network format for transmission
on the network.
Examples of Presentation layer coding and
conversion schemes include data
representation formats, conversion of
character formats, compression, and
encryption schemes.
 3. Session layer: establishes, manages,
and terminates communication sessions,
such as for RPC. Communication sessions
consist of service requests and service
responses that occur among applications
located on different network devices.
 4.Transport layer: Is responsible for
providing reliable service between the
hosts. Upper layer datagrams are broken
down into manageable datagrams and then
appropriate header information (such as
sequence number, port number, etc.) are
added to the datagram before passing it on
to the Network layer. Two transport
protocols are the TCP (Transmission
Control Protocol) and the UDP (User
Datagram Protocol).
 5. Network layer: Is responsible for the
routing of packets through the entire
network. Note that the physical address
(like MAC address) keeps changing from
hop to hop when a packet travels from
source to destination. As a result, an
address that doesn't change is required to
ensure continuity between hops. For the
Internet, IP address is the logical address.
 6. Data link layer: Provides delivery of
frames between devices. Is responsible for
flow regulation, error detection and
correction, framing of bits for transmission.
The network frame is made up of
checksum, destination MAC address,
source address, and the data. The largest
frame size is the maximum transmission
Unit (MTU). Consists of two sub layers:
 1.Logical Link Control (LLC): Defines how data is
transferred over the media and provides data
link service to the higher layers.
 2.Medium Access Control (MAC): Controls media
access by regulating the communicating nodes
using pre-defined set of rules. (i.e. Token
passing, Ethernet [CSMA/CD]).
 7. Physical layer: Handles the bit-level
communications across the physical
medium. The physical medium could be
made up of wired electrical signals, or
light, or radio (wireless) signals.
TCP/IP Internet
Architecture
Domain Name Service
HTTP -- port 80
 CLIENT
GET /pub/WWW/TheProject.html
HTTP/1.1 Host: www.w3.org
 SERVER -- replies w Content-Type….
MIME (Multipurpose Internet Mail Extensions)
application/vnd.ms-powerpoint
application/x.javascript
audio/tone
image/jpeg
image/vnd.wap.wbmp
message/news
model/vrml
text/tab-separated-values text/html
video/quicktime
Be a Browser
telnet uga.edu 80
Type everything below as shown:
GET /index.html HTTP/1.1
Host: www.uga.edu
Connection: close
CR/LF
CR/LF
TCP Packet
IP Addresses (32-bits)
IP Network Classes
Network Type Address Range
Normal Mask
Class A
001.x.x.x to 126.x.x.x
255.0.0.0
Class B
128.1.x.x to 191.254.x.x
255.255.0.0
Class C
192.0.1.x to 223.255.254.x 255.255.255.0
Class D
224.x.x.x to 239.255.255.255
Class E
240.x.x.x to 247.255.255.255
IP Packet
EtherNet Packet
Universal Resource Identifier
<scheme>://<net_location>/<path>;
<arguments>?<query>#<fragment>
http://www.google.com/search?hl=en&
ie=UTF-8&oe=UTF-8&q=usatoday+lincoln
Berkeley Socket API
 De facto standard for communications
programming.
 Socket - end point for communications. They are
file descriptors. Thus we can use system calls
like read and write to receive and send data.
 To communicate with a program on another
computer, we have to identify the computer and
specify the program. Specify the computer by
giving its IP address. Specify the program with its
port number, which is a positive integer that is
advertised by the program that is waiting for a
connection.
#include <unistd.h>
#include <netdb.h>
int gethostname(char name[], size_t namelen);
int sethostname(const char name[], int namelen);
struct hostent *gethostbyname(const char name[]);
char *inet_ntoa(struct in_addr in);
in_addr_t inet_addr(const char *cp);
h=gethostbyname("ibm.com");
memcpy(&a, h->h_addr_list[0], sizeof(struct in_addr));
printf("%s\n", inet_ntoa(a));
printf("0x%0lx\n", inet_addr("129.42.19.99"));
OUTPUT
129.42.16.103
0x63132a81
Socket TCP/IP API
#include <sys/types.h>
#include <sys/socket.h>
int socket(int protocolFamily, int rawDatagramStream, int protocol);
int bind(int socket, const struct sockaddr *address, socklen_t
address_len);
int listen(int socket, int maxQueueLength);
int accept(int socket, struct sockaddr *restrict address, socklen_t
*restrict address_len);
ssize_t recv(int socket, void *buffer, size_t length, int flags);
int connect(int socket, const struct sockaddr *address, socklen_t
address_len);
ssize_t send(int socket, const void *buffer, size_t length, int flags);
//select blocks on multiple ports until one completes an I/O
int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
fd_set *restrict errorfds, struct timeval *restrict timeout);
uint16_t htons(uint16_t hostshort); //cvt host to network byte order
uint32_t ntohl(uint32_t netlong); //network to host byte order
#include <stdio.h>
Get a web page
#include <string.h>
using the socket API
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(int argc, char *argv[]) {
int i; char str[1024];
char msg[] = "GET / HTTP/1.0\r\nHost:
www.uga.edu\r\nConnection: close\r\n\r\n";
int s;
struct sockaddr_in si;
struct hostent *h = gethostbyname(uga.edu");
s = socket(AF_INET, SOCK_STREAM,
IPPROTO_TCP);
memset(&si, 0, sizeof(si));
memcpy(&si.sin_addr,
h->h_addr_list[0], sizeof(struct in_addr));
si.sin_port = htons(80);
si.sin_family = AF_INET;
i = connect(s, (const struct sockaddr *)&si,
sizeof(si));
i = send(s,msg, sizeof(msg), 0);
i = recv(s, str, sizeof(str), 0);
if (i > 0) {
str[i] = 0;
printf("%s\n", str);
}
close(s);
}
Cookies
 Variables for a distributed computation
 Property Lists
 .tucows.com TRUE / FALSE 2145801589
NGUserID cf88422c-26266-958947479-5
 207.136.66.80 FALSE / FALSE 1116627479
Apache 192.9.25.22.18775958947478702