socket |
Prototype: |
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
|
General Description: |
Creates a bidirectional channel that typically connects with the network. You may use this channel with network-specific system calls or general file I/O. |
Return Value: |
If successful, the call returns a valid socket descriptor. Otherwise the result is less than zero. Check errno for more information about error. |
Parameters |
domain |
Selects the network protocol for socket (see Appendix A). |
type |
Selects the network layer (see Appendix A). |
protocol |
Usually zero (see Appendix A). |
Possible Errors |
EPROTONOSUPPORT |
The protocol type or the specified protocol is not supported within this domain. |
ENFILE |
Not enough kernel memory to allocate a new socket structure. |
EMFILE |
Process file table overflow. |
EACCES |
Permission to create a socket of the specified type and/or protocol is denied. |
ENOBUFS |
|
ENOMEM |
Insufficient memory is available. The socket cannot be created until sufficient resources are freed. |
EINVAL |
Unknown protocol, or protocol family not available. |
Examples |
int sd;
sd = socket(PF_INET, SOCK_STREAM, 0);
|
int sd;
sd = socket(PF_INET, SOCK_RAW, htons(IPPROTO_ICMP));
|