Shared Flashcard Set

Details

Network Programming
n/a
78
Computer Science
Undergraduate 4
02/12/2013

Additional Computer Science Flashcards

 


 

Cards

Term
Hosts are mapped to?
Definition
32 bit IP Addresses
Term
A set of IP address is Mapped to?
Definition
A set of identifiers called Internet domain names
Term
Each host has an IP address. How many ports does a host have? Name some reserved ports.
Definition
65536; 20,21 -ftp
23-telnet
80- http
RFC 1700 ~2000
Term
32-bit IP addresses are stored in an ip address struct. What order are ip address stored in memory in?
Definition
network byte order
Term
What is the structure of a ip address struct?
Definition
struct in_addr{
unsigned int s_addr;
};
Term
What is the convention of an IP address?
Definition
A IP address is represented by a string: decimal values for bytes, separated by a period. IP address: 0x8002C2F2 = 128.2.194.242
Term
What functions are used to convert between binary IP addresses and dotted decimal strings?
Definition
inet_aton- decimal dotted to IP address in network byte order

inet_ntoa: - IP address in network byte order to dotted decimal string

NB: n- network representation
a-application representation
Term
What are the five classes of IP address?
Definition
8 16 24 31
ClassA- 0 NetID HostID
ClassB- 1 0 NetID Host I.D
ClassC 1 1 0 NetID Host I.D
CalssD- 1 1 1 0- multicast address
ClassE 1 1 1 1- reserved for experiments
Term
What is the form of a Network I.D?
Definition
w.x.y.z/n where n is the number if bits in the NetID.
Term
How many bits are in the Net ID of Unrouted private IP addresses?
Definition
8 12 or 16
Term
What are some first level Domain names?
Definition
.net .edu .gov .com
Term
What are some second level Domain names?
Definition
mit cmu berkely amazon
Term
What are some third level Domain names?
Definition
cs ece www
Term
What is the worldwide distributed DNS database?
Definition
A mapping between IP addresses and domain names maintained by the Internet
Term
The struct hostent is the structure of an entry in the DNS database. What are the variables and what do they represent?
Definition
char *h_name - domain name
char **H_aliases - null terminated array of domain names
int h_addrtype - host type (AF_INET)
h_length - the length of an address in bytes
char **h_addr_list - null terminated array of in_addr
Term
What are the query keys of the following?

gethostbyname:
gethostbyaddr:
Definition
gethostbyname: DNS domain name
gethostbyaddr: an IP address
Term
Each Host has a locally defined domain name localhost that always maps back to?
Definition
The loopback address 127.0.0.1
Term
What types of mapping are possible in DNS host entries?
Definition
one-to-one
multiple to one IP
mutiple domain names to multiple IP addresses
none---some map to nothing
Term
Domain Information Groper (DIG) does what?
Definition
Provides a scriptable command line interface to DNS
Term
How do clients and servers communicate?
Definition
By sending streams of bytes over connections
Term
what is a socket?
Definition
The end point of a connection

An interface between application and network
Term
What is a port?
Definition
a 16- bit integer that identifies a process
Term
Define the two types of ports
Definition
Ephemeral port- assigned automatically on client when client makes a connection request

Well-know port: associated with some service provided by a service
Term
What is a sock pair?
Definition
A unique identifier of a connection by endpoint socket addresses.
cliaddr:cliport, servaddr:servport
Term
What are the two common types of sockets and their features?
Definition
Sock_stream (TCP): reliable delivery, in-order guarentee, connection oriented, bidirectional


Sock_dgram (UDP): unreliable delivery, no order guarentees, no notions of "connection" , can send or recieve
Term
How are addresses and ports stored?
Definition
As integers, u_short sin_port (16-bit)
in_addr sin_addr (32-bit)
Term
What is a Big edian Machine and what is a little-edian macine?
Definition
little-endian: lower bytes first
big-endian: higher bytes first
Term
What is Host byte Odering?
Definition
The byte ordering used by a host (big vs little)
Term
What is Network Byte-Ordering?
Definition
The byte ordering used by the network always big-edian
Term
When transmitting what protocol about ordering followed?
Definition
Any words sent through the network should be converted to Network Byte-Order prior to transmission (and back to Host Byte-Order once received)
Term
What do the following do on Big-edian machines?

u_long ntohl(u_long x);
u_short ntohs(u_short x);
u_long htonl(u_long x);
u_short htons(u_short x);
Definition
Nothing
Term
What do the following do on litte-edian machines?

u_long ntohl(u_long x);
u_short ntohs(u_short x);
u_long htonl(u_long x);
u_short htons(u_short x);
Definition
reverse byte order
Term
name the function to create a socket and the define the variables.
Definition
int s= socket(domain, type, protocol)

domain- integer, communication domain
type- communication type sock_stream vs sock_dgram

protocol - specifies protocol (usually set to 0)
Term
What are some example client programs?
Definition
web browsers, ftp, telnet, ssh
Term
How does a client find a server?
Definition
The IP address identifies the host
the well-know port in the server socket identifies the service and identifies the server process to perform that service
Term
What are servers?
Definition
Long-running processes(deamons)
Term
When are servers created and how long do they run?
Definition
Servers are created at boot-time and run continuous until the machine is turned off
Term
Classify and define the port number for a webserver.
Definition
Port 80
Resources: files/compute cycle
Sevice: retrives files and runs CGI programs on behalf of the client
Term
Classify and define the port number for a FTP Server
Definition
Resources: files
Service: Stores and retrieves files
Term
Classify and define the port number for a telnet server
Definition
resources: terminal
Services: Proxies a terminal on the server machine
Term
Classify and define the port number for a mail server
Definition
resource: email
service: stores mail messages in a spool file
Term
What is socket to a kernel?
Definition
Endpoint of communication
Term
What is a socket to an application?
Definition
a file descriptor that lets the application read/write from/to the network
Term
What is the main distinction between a regular file I/O and socket I/o
Definition
how the application opens the socket descriptors
Term
The struct sockaddr
Definition
The generic:
struct sockaddr {
u_short sa_family;
char sa_data[14];
};

struct sockaddr_in {
short sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
Term
What does sa_family do in the following?

struct sockaddr {
u_short sa_family;
char sa_data[14];
};
Definition
specifies which address family is being used
determines how the remaining 14 bytes are used
Term
Why is the generic sock address needed?
Definition
NO void* when C created, needed to connect, bind and sccept
Term
What does the internet-specific socket need to do to connect, bind or accept?
Definition
Must cast (sockaddr_in *) to (sockaddr *) for connect, bind, and accept
Term
What does the bind function do?
Definition
associates and (can exclusively) reserves a port for use by the socket
Term
What is the function for bind?
Definition
int status = bind(sockid, &addrport, size);
status: error status, = -1 if bind failed
sockid: integer, socket descriptor
addrport: struct sockaddr, the (IP) address and port of the machine (address usually set to INADDR_ANY – chooses a local address)
size: the size (in bytes) of the addrport structure
Term
When can you skip binding for sock_stream and sock_dgram?
Definition
Sock_dgram- if only sending
sock_stream- can always destination determined during conn. setup
don't need to know sending port
Term
True or false connection setup needed for sock_dgram
Definition
False
Term
Connection occurs between what types of participants?
Definition
passive: waits for an active participant to request connection
active: initiates connection request to passive side

after connection both become equal and can send and receive and terminate connection
Term
What are the steps in setting up a connection?
Definition
1. listen for request
2. request and establish (active)
3. accept (passive)
step 4. data transfer
Term
Where is the accepted connection?
Definition
new socket. The old socket listens for more participants
Term
What is the function to listen to a call?
Definition
int status = listen(sock, queuelen);
status: 0 if listening, -1 if error
sock: integer, socket descriptor
queuelen: integer, # of active participants that can “wait” for a connection
Term
What is the function to accept a connection?
Definition
int s = accept(sock, &name, &namelen);
s: integer, the new socket (used for data-transfer)
sock: integer, the orig. socket (being listened on)
name: struct sockaddr, address of the active participant
namelen: sizeof(name): value/result parameter
Term
What is the function to connect?
Definition
int status = connect(sock, &name, namelen);
status: 0 if successful connect, -1 otherwise
sock: integer, socket to be used in connection
name: struct sockaddr: address of passive participant
namelen: integer, sizeof(name)
Term
Which of the following are blocking and non-blocking? Listen, accept and connect, send, recv
Definition
listen-nonblocking accept and connect, count, recieve blokcing,
Term
What is the function to send?
Definition
int count = send(sock, &buf, len, flags);
count: # bytes transmitted (-1 if error)
buf: char[], buffer to be transmitted
len: integer, length of buffer (in bytes) to transmit
flags: integer, special options, usually just 0
Term
What is the function to recieve?
Definition
int count = recv(sock, &buf, len, flags);
count: # bytes received (-1 if error)
buf: void[], stores received bytes
len: # bytes received
flags: integer, special options, usually just 0
Term
What calls are used to send and recieve without a connnection? (sock_dgram)
Definition
int count = sendto(sock, &buf, len, flags, &addr, addrlen);
count, sock, buf, len, flags: same as send
addr: struct sockaddr, address of the destination
addrlen: sizeof(addr)
int count = recvfrom(sock, &buf, len, flags, &addr,
&addrlen);
count, sock, buf, len, flags: same as recv
name: struct sockaddr, address of the source
namelen: sizeof(name): value/result parameter
Term
How is a socket closed? and what does closing a socket do?
Definition
status = close(s);
s: the file descriptor (socket being closed)

frees up the port used by the socket
Term
What code is used to close a port after a rough exit?
Definition
#include void cleanExit(){exit(0);} in socket code: signal(SIGTERM, cleanExit); signal(SIGINT, cleanExit);
Term
What do the following do?

gets(Sentence);

n=write(clientSocket, Sentence, strlen(Sentence)+1);


n=read(clientSocket, modifiedSentence, sizeof(modifiedSentence));

close(clientSocket);
Definition
Get input stream

send line to server

read line from server

close connection
Term
What is a listening descriptor?
Definition
End point for client connection requests
Created once and exists for lifetime of the server
Term
What is a connected descriptor?
Definition
End point of the connection between client and server
A new descriptor is created each time the server accepts a connection request from a client
Exists only as long as it takes to service client
Term
Why are connected and listening descriptors different?
Definition
Allows for concurrent servers that can communicate over many client connections simultaneously
Term
Why is tenet useful?
Definition
is invaluable for testing servers that transmit ASCII strings over Internet connections

Our simple echo server
Web servers
Mail servers
Term
How is telnet used?
Definition
unix> telnet Creates a connection with a server running on and listening on port
Term
How do handle problems with blocking calls?
Definition
create multi-process or multi-threaded code
turn off the blocking feature (e.g., using the fcntl file-descriptor control function)
use the select function call.
Term
What does select function do in relation t sockets?
Definition
can be permanent blocking, time-limited blocking or non-blocking
input: a set of file-descriptors
output: info on the file-descriptors’ status
i.e., can identify sockets that are “ready for use”: calls involving that socket will return immediately
Term
What is the select function?
Definition
int status = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
status: # of ready objects, -1 if error
nfds: 1 + largest file descriptor to check
readfds: list of descriptors to check if read-ready
writefds: list of descriptors to check if write-ready
exceptfds: list of descriptors to check if an exception is registered
timeout: time after which select returns, even if nothing ready - can be 0 or infinity
Term
When using select we the structure fd_set is used. What is it?
Definition
it is just a bit-vector
if bit i is set in [readfds, writefds, exceptfds], select will check if file descriptor (i.e. socket) i is ready for [reading, writing, exception]
Term
What calls are needed before select?
Definition
FD_ZERO(&fdvar): clears the structure
FD_SET(i, &fdvar): to check file desc. i
Term
What calls are needed after select?
Definition
int FD_ISSET(i, &fdvar): boolean returns TRUE iff i is “ready”
Term
What do the following do?
bzero(char* c, int n):

gethostname(char *name, int len):

gethostbyaddr(char *addr, int len, int type):
Definition
0’s n bytes starting at c

gets the name of the current host

converts IP hostname to structure containing long integer
Term
TCp types of sockets are?
Definition
ServerSocket and Socket
Supporting users have an ad free experience!