Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket programming, what is FD and SD

I am programming an SSL socket and many times I have seen something (variable name, function...) with FD or SD in its name. For example, OpenSSL provides the function:

int fd = SSL_get_fd(...);

In many tutorials (here, here and here), this is used:

int sd = socket(...);

Can anyone explain, what does FD and SD stand for?

Thanks

like image 734
Martin Heralecký Avatar asked Jun 06 '15 11:06

Martin Heralecký


People also ask

What is FD and SD?

A file descriptor is a non-negative integer, represented in C programming language as the type int. wfd , rfd will stand for write-FD and read-FD. sd is not a standard moniker, but it will likely stand for 'socket file descriptor', ie. a FD that corresponds to a socket.

What is FD in socket?

In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.

What is Socklen_t Addrlen?

addrlen is a pointer to a socklen_t where the length of the struct sockaddr filled in will be returned. int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); The function connect connects a socket on this host to another host. The function returns 0 on success or −1 on failure.

What does Sockfd stand for?

int sockfd = socket(domain, type, protocol) sockfd: socket descriptor, an integer (like a file-handle) domain: integer, specifies communication domain. We use AF_ LOCAL as defined in the POSIX standard for communication between processes on the same host.


2 Answers

SSL_get_fd:

SSL_get_fd() returns the file descriptor

File Descriptor:

In Unix and related computers operating systems, a file descriptor (FD, less frequently fildes) is an abstract indicator used to access a file or other input/output resource, such as a pipe or network connection. File descriptors are part of the POSIX application programming interface. A file descriptor is a non-negative integer, represented in C programming language as the type int.

wfd, rfd will stand for write-FD and read-FD. sd is not a standard moniker, but it will likely stand for 'socket file descriptor', ie. a FD that corresponds to a socket. From the same SSL_get_fd page:

fd will typically be the socket file descriptor of a network connection

like image 157
Remus Rusanu Avatar answered Oct 19 '22 20:10

Remus Rusanu


"fd" is generally an abbreviation of File Descriptor. On POSIX systems like Linux, OSX and the BSD variants a file descriptor is used not only for files, but for sockets, device communication and other things as well

like image 41
Some programmer dude Avatar answered Oct 19 '22 21:10

Some programmer dude