Socket Creation and Basic Configuration Flashcards

1
Q

constructor of socket library

A

socket(family, type, proto, fileno)

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

What does the family field specify?

A

address family, which format is used to identify the socket address

AF_INET: address family _ internet ==> for ipv4

socket address is (host, port)
host could be hostname or ipv4

hostname first result of DNS resolution is used

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

IPv6 Internet protocols

A

AF_INET6

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

designed for efficient communication between processes in the same
UNIX machine

A

AF_UNIX

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

low-level raw packet that communicates with device drivers, i.e., at
the Data Link layer (TCP/IP Layer 2)

A

AF_PACKET

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

for communication using several Bluetooth protocols.

A

AF_BLUETOOTH

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

Reliable Datagram Socket (RDS) protocol. (Connectionless reliable
low-latency protocol)

A

AF_RDS

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

Controller Area Network Automotive bus protocol (developed by
Volkswagen for Linux)

A

AF_CAN

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

What does the type argument define

A

the type of the stream, how the socket stream will be handled

type of the transport layer protocol

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

TCP Protocol: Provides connection based, reliable and
sequenced communication

A

SOCK_STREAM

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

UDP Protocol: Provides datagram based (connectionless),
unreliable and non-sequenced communication

A

SOCK_DGRAM

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

Allows for customized lower-level programming2

A

SOCK_RAW

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

Datagram based, reliable and non-sequenced communication

A

SOCK_RDM

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

Datagram based, reliable and sequenced communication

A

SOCK_SEQPACKET

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

socket(AF_INET,RAW_SOCKET,…)
vs.
socket(AF_PACKET,RAW_SOCKET,…)

A

allows you to program at the IP layer

allows you to program at the Data Link layer.

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

what does proto = 0 indicate

A

underlying Layer 3 protocol. For the vast majority of applications, it is set to 0 which
indicates using the IP protocol.

17
Q

when do we benefit from the fileno argument

A

This can be useful to close a
detached socket, and in some operations in the non-blocking mode.

18
Q

s = socket() which will create

A

Pv4 TCP socket.

19
Q

The address family, stream type and protocol are defined aaaaas?

A

attributes
s.family
s.proto
s.type

Once a socket is created, you cannot set/change the above three attributes, because they
are defined as read-only attributes.

20
Q

You can get a list of all object
attributes and methods using the command

A

dir(<socket_object>)</socket_object>

21
Q

does the __dict__ attribute exist? why?

A

no, none of the attributes are writable

22
Q

because every class in Python extends the basic object class, the basic attributes
are also applicable like:

A

__module__
__class__

23
Q

To verify socket creation, if s is a socket object type the command

24
Q

a socket is no
more than a file created by the OS, and a socket descriptor is treated just like any other
file descriptor

A

UNIX, Windows behaves a bit differently

25
A file descriptor assigned to a socket is always
a positive integer, other than 0 (reserved for stdin), 1 (reserved for stdout) and 2 (reserved for stderr).
26
When communicating over the network using sockets, the ?????? will create the transport, network, and data link packet headers for you
for non raw packets OS However, the programmer is responsible for preparing the application-layer payloads.
27
Closing a socket will deallocate all the resources given to the socket. The file descriptor will also be deallocated, and a value of ??????? is assigned. Once a socket is closed, then all socket operations become illegal.
-1
28
if you do not need the socket anymore, but you need the file descriptor associated with it, then the method????? should be used.
detach
29
If you need to copy the socket specifications, then the method can be used. This will create another socket with the same specifications but with a different file descriptor. These two sockets are distinct sockets, and their operations are independent of each other
dup() not copy, deepcopy or = DIFFERENT FILE DESCRIPTOR if you want same FD, you'll need to use the fileno argument