The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
socket.h File Reference

sockets: Unix domain stream sockets, with file descriptor passing, and IPv4 sockets (TCP; UDP, and ICMP for ping). More...

#include <sys/types.h>
#include <sys/uio.h>

Go to the source code of this file.

Data Structures

struct  sockaddr
struct  sockaddr_storage
struct  msghdr
struct  cmsghdr

Macros

#define AF_UNSPEC   0
#define AF_UNIX   1
#define AF_LOCAL   AF_UNIX
#define AF_INET   2
#define AF_INET6   10
#define PF_UNSPEC   AF_UNSPEC
#define PF_UNIX   AF_UNIX
#define PF_LOCAL   AF_UNIX
#define PF_INET   AF_INET
#define PF_INET6   AF_INET6
#define SOCK_STREAM   1
#define SOCK_DGRAM   2
#define SOCK_NONBLOCK   0x00000800
#define SOCK_CLOEXEC   0x00080000
#define SOL_SOCKET   1
#define SCM_RIGHTS   1
#define SO_REUSEADDR   2
#define SO_TYPE   3
#define SO_ERROR   4
#define SO_BROADCAST   6
#define SO_SNDBUF   7
#define SO_RCVBUF   8
#define SO_KEEPALIVE   9
#define SHUT_RD   0
#define SHUT_WR   1
#define SHUT_RDWR   2
#define MSG_PEEK   0x0002
#define MSG_CTRUNC   0x0008
#define MSG_TRUNC   0x0020
#define MSG_DONTWAIT   0x0040
#define MSG_NOSIGNAL   0x4000
#define MSG_CMSG_CLOEXEC   0x40000000
#define CMSG_ALIGN(len)
#define CMSG_SPACE(len)
#define CMSG_LEN(len)
#define CMSG_DATA(cmsg)
#define CMSG_FIRSTHDR(msg)
#define CMSG_NXTHDR(msg, cmsg)

Typedefs

typedef unsigned int socklen_t
typedef unsigned short sa_family_t

Functions

struct cmsghdr * __cmsg_nxthdr (struct msghdr *msg, struct cmsghdr *cmsg)
 the control message after cmsg, or NULL.
int socket (int domain, int type, int protocol)
int socketpair (int domain, int type, int protocol, int sv[2])
int bind (int fd, const struct sockaddr *addr, socklen_t addrlen)
int listen (int fd, int backlog)
int accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
int accept4 (int fd, struct sockaddr *addr, socklen_t *addrlen, int flags)
int connect (int fd, const struct sockaddr *addr, socklen_t addrlen)
ssize_t sendmsg (int fd, const struct msghdr *msg, int flags)
ssize_t recvmsg (int fd, struct msghdr *msg, int flags)
ssize_t send (int fd, const void *buf, size_t len, int flags)
ssize_t recv (int fd, void *buf, size_t len, int flags)
ssize_t sendto (int fd, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
ssize_t recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
int getsockname (int fd, struct sockaddr *addr, socklen_t *addrlen)
int getpeername (int fd, struct sockaddr *addr, socklen_t *addrlen)
int setsockopt (int fd, int level, int name, const void *value, socklen_t length)
int getsockopt (int fd, int level, int name, void *value, socklen_t *length)
int shutdown (int fd, int how)

Detailed Description

sockets: Unix domain stream sockets, with file descriptor passing, and IPv4 sockets (TCP; UDP, and ICMP for ping).

AF_UNIX with SOCK_STREAM, and AF_INET with SOCK_STREAM or SOCK_DGRAM (<netinet/in.h> has the addresses). the values and layouts are the same as Linux's, and must match src/kernel/ipc/unix_socket.h and src/kernel/net/inet_socket.h.

to pass open files, put their fds in an SCM_RIGHTS control message of sendmsg; the message must have at least one byte of data. the receiver gets new fds for the same open files from recvmsg.

Macro Definition Documentation

◆ AF_UNSPEC

#define AF_UNSPEC   0

◆ AF_UNIX

#define AF_UNIX   1

◆ AF_LOCAL

#define AF_LOCAL   AF_UNIX

◆ AF_INET

#define AF_INET   2

◆ AF_INET6

#define AF_INET6   10

◆ PF_UNSPEC

#define PF_UNSPEC   AF_UNSPEC

◆ PF_UNIX

#define PF_UNIX   AF_UNIX

◆ PF_LOCAL

#define PF_LOCAL   AF_UNIX

◆ PF_INET

#define PF_INET   AF_INET

◆ PF_INET6

#define PF_INET6   AF_INET6

◆ SOCK_STREAM

#define SOCK_STREAM   1

◆ SOCK_DGRAM

#define SOCK_DGRAM   2

◆ SOCK_NONBLOCK

#define SOCK_NONBLOCK   0x00000800

◆ SOCK_CLOEXEC

#define SOCK_CLOEXEC   0x00080000

◆ SOL_SOCKET

#define SOL_SOCKET   1

◆ SCM_RIGHTS

#define SCM_RIGHTS   1

◆ SO_REUSEADDR

#define SO_REUSEADDR   2

◆ SO_TYPE

#define SO_TYPE   3

◆ SO_ERROR

#define SO_ERROR   4

◆ SO_BROADCAST

#define SO_BROADCAST   6

◆ SO_SNDBUF

#define SO_SNDBUF   7

◆ SO_RCVBUF

#define SO_RCVBUF   8

◆ SO_KEEPALIVE

#define SO_KEEPALIVE   9

◆ SHUT_RD

#define SHUT_RD   0

◆ SHUT_WR

#define SHUT_WR   1

◆ SHUT_RDWR

#define SHUT_RDWR   2

◆ MSG_PEEK

#define MSG_PEEK   0x0002

◆ MSG_CTRUNC

#define MSG_CTRUNC   0x0008

◆ MSG_TRUNC

#define MSG_TRUNC   0x0020

◆ MSG_DONTWAIT

#define MSG_DONTWAIT   0x0040

◆ MSG_NOSIGNAL

#define MSG_NOSIGNAL   0x4000

◆ MSG_CMSG_CLOEXEC

#define MSG_CMSG_CLOEXEC   0x40000000

◆ CMSG_ALIGN

#define CMSG_ALIGN ( len)
Value:
(((len) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1))
__SIZE_TYPE__ size_t
Definition types.h:14

◆ CMSG_SPACE

#define CMSG_SPACE ( len)
Value:
(CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
#define CMSG_ALIGN(len)
Definition socket.h:96
Definition socket.h:90

◆ CMSG_LEN

#define CMSG_LEN ( len)
Value:
(CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))

◆ CMSG_DATA

#define CMSG_DATA ( cmsg)
Value:
((unsigned char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)))

◆ CMSG_FIRSTHDR

#define CMSG_FIRSTHDR ( msg)
Value:
((msg)->msg_controllen >= sizeof(struct cmsghdr) ? (struct cmsghdr *)(msg)->msg_control \
: (struct cmsghdr *)0)

◆ CMSG_NXTHDR

#define CMSG_NXTHDR ( msg,
cmsg )
Value:
__cmsg_nxthdr((msg), (cmsg))
struct cmsghdr * __cmsg_nxthdr(struct msghdr *msg, struct cmsghdr *cmsg)
the control message after cmsg, or NULL.

Typedef Documentation

◆ socklen_t

typedef unsigned int socklen_t

◆ sa_family_t

typedef unsigned short sa_family_t

Function Documentation

◆ __cmsg_nxthdr()

struct cmsghdr * __cmsg_nxthdr ( struct msghdr * msg,
struct cmsghdr * cmsg )

the control message after cmsg, or NULL.

use CMSG_NXTHDR.

◆ socket()

int socket ( int domain,
int type,
int protocol )

◆ socketpair()

int socketpair ( int domain,
int type,
int protocol,
int sv[2] )

◆ bind()

int bind ( int fd,
const struct sockaddr * addr,
socklen_t addrlen )

◆ listen()

int listen ( int fd,
int backlog )

◆ accept()

int accept ( int fd,
struct sockaddr * addr,
socklen_t * addrlen )

◆ accept4()

int accept4 ( int fd,
struct sockaddr * addr,
socklen_t * addrlen,
int flags )

◆ connect()

int connect ( int fd,
const struct sockaddr * addr,
socklen_t addrlen )

◆ sendmsg()

ssize_t sendmsg ( int fd,
const struct msghdr * msg,
int flags )

◆ recvmsg()

ssize_t recvmsg ( int fd,
struct msghdr * msg,
int flags )

◆ send()

ssize_t send ( int fd,
const void * buf,
size_t len,
int flags )

◆ recv()

ssize_t recv ( int fd,
void * buf,
size_t len,
int flags )

◆ sendto()

ssize_t sendto ( int fd,
const void * buf,
size_t len,
int flags,
const struct sockaddr * to,
socklen_t tolen )

◆ recvfrom()

ssize_t recvfrom ( int fd,
void * buf,
size_t len,
int flags,
struct sockaddr * from,
socklen_t * fromlen )

◆ getsockname()

int getsockname ( int fd,
struct sockaddr * addr,
socklen_t * addrlen )

◆ getpeername()

int getpeername ( int fd,
struct sockaddr * addr,
socklen_t * addrlen )

◆ setsockopt()

int setsockopt ( int fd,
int level,
int name,
const void * value,
socklen_t length )

◆ getsockopt()

int getsockopt ( int fd,
int level,
int name,
void * value,
socklen_t * length )

◆ shutdown()

int shutdown ( int fd,
int how )