general class notes Flashcards

1
Q

What is the order of wrapping in TCP/IP (sam applicable for OSI too)?

A

you have your message wrapped by application layer stuff then you have transport layer (TCP/UDP usually) things like the port number and then IP address and then link layer stuff.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do IP addresses identify?

A

they identify a network interface on a machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you identify different programs on a machine?

A

Using port numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many bits is IPv4?

A

32 bits in the form 8bits.8bits.8bits.8bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many bits is IPv6?

A

128 bits in the form 16bitsHexa:16bitsHexa:16bitsHexa:16bitsHexa:16bitsHexa:16bitsHexa:16bitsHexa (8 sets of 16 bits colon seperated)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Between client and server, who does the connect call, and who the listen and accept calls?

A

client does the conect call (it reaches out and connects) and server does the listen and accept calls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

in go net.dial() corresponds to what call on the C API?

A

on the C API net.Dial() which is used by the client to connect to the server is called connect()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

https://imgur.com/a/Teh8qPw
what do different parts of the TCP protocol process do on both the client and server side?
client: socket, connect, send(), receive(), close()
server: socket, bind, listen, accept(), send(), receive(), close()

A

Client:
socket: used to create a socket on some port number and IP address. If the IP address and port are not specified, it’ll use what’s available. socket() returns a socket descriptor and establishes 2 buffers(send and receive buffers) associated with the socket that live in the OS and not the application.
connect(): equivalent to net.Dial() in GO

send(): pretty similar in client and server. On the client side all you need to do is after creating an active socket use that to send info.
receive(): works pretty similarly on client and server side. It takes what data comes onto the socket receive buffer and puts it into a buffer passed as an argument. It returns the number of bytes actually read. receive is a blocking call, it will wait until some data is available on the socket receive buffer. if the connection has been closed it will return a 0. return of -ve number means error.
close(): tears down connection and frees up data associated with the socket().

Server:
socket: creates a socket on the server side, need to pass an IP address and port number for the server to be initialized on. You can not give IP address, then it’ll take connections from an IP address (wildcard IP address).socket() returns a socket descriptor and establishes 2 buffers (send and receive buffers) associated with the socket that live in the OS and not the application. Socket() creates a queue for accept() to come and take new connections which have done 3 way handshake from.
bind(): assigns the socket() to a specific port. You have to assign the socket to a port on the server side. You can do this on the client side too, when you don’t specify anything the system chooses an unused IP address and port for you. bind will
listen(): when you call listen you’re telling the OS that you’re going to be accepting incoming connections to a particular socket. In GO the bind and listen call are sorta combined into one. So net.listen() and we were done. listen will take back_log as argument. It determines the number of TCP connections we accept and queue.
accept(): its a blocking operation that waits for OS to put a connection on the queue and then grabs it off that queue and gives it to the application. It creates a new socket for every connection so that data can be sent over it.
send(): pretty similar in client and server. On the server side, you can take the socket accept() returns and use that to send data.
receive(): works pretty similarly on client and server side. It takes what data comes onto the socket receive buffer and puts it into a buffer passed as an argument. It returns the number of bytes actually read. receive is a blocking call, it will wait until some data is available on the socket receive buffer. if the connection has been closed it will return a 0. return of -ve number means error.
close(): tears down connection and frees up data associated with the socket().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

htons function used for what and where?

A

htons() used one the server side to avoid confusion between big endianess and little endianess. It’ll convert your port number to big endian if your system is little endian and leave as is if its big endian.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does active and passive mode in sockets mean?

A

the terminology is old fashioned but it basically means that the server is by default configured in active mode and the client is by default configured in passive mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how are we able to connect different clients to the same socket no server?

A

We don’t really do that. What happens is that the socket we create on the listener side to which the server binds port and IP address and on which listener is running doesn’t ever send or receive data through that port. All it does is pass connections to accept(), What accept() returns is a new socket that’s specific to every new connection to the server for communication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

when does deadlock occur?

A

If both client and server try to send() data as soon as a connection is established, since send() is a blocking operation, neither program moves ahead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly