# sockets.h File Reference

`#include <ubixos/types.h>`

Go to the source code of this file.

## Data Structures

struct | in_addr
struct | sockaddr
struct | sockaddr_in

## Defines

#define | AF_INET 2
#define | INADDR_ANY 0
#define | INADDR_BROADCAST 0xffffffff
#define | IPPROTO_TCP 6
#define | IPPROTO_UDP 17
#define | PF_INET AF_INET
#define | SOCK_DGRAM 2
#define | SOCK_STREAM 1

## Functions

int | lwip_accept (int s, struct sockaddr *addr, int *addrlen)
int | lwip_bind (int s, struct sockaddr *name, int namelen)
int | lwip_close (int s)
int | lwip_connect (int s, struct sockaddr *name, int namelen)
int | lwip_listen (int s, int backlog)
int | lwip_read (int s, void *mem, int len)
int | lwip_recv (int s, void *mem, int len, unsigned int flags)
int | lwip_recvfrom (int s, void *mem, int len, unsigned int flags, struct sockaddr *from, int *fromlen)
int | lwip_send (int s, void *dataptr, int size, unsigned int flags)
int | lwip_sendto (int s, void *dataptr, int size, unsigned int flags, struct sockaddr *to, int tolen)
int | lwip_socket (int domain, int type, int protocol)
int | lwip_write (int s, void *dataptr, int size)

## Define Documentation

#define AF_INET 2

Definition at line 64 of file sockets.h.

#define INADDR_ANY 0

Definition at line 70 of file sockets.h.

#define INADDR_BROADCAST 0xffffffff

Definition at line 71 of file sockets.h.

#define IPPROTO_TCP 6

Definition at line 67 of file sockets.h.

#define IPPROTO_UDP 17

Definition at line 68 of file sockets.h.

#define PF_INET AF_INET

Definition at line 65 of file sockets.h.

#define SOCK_DGRAM 2

Definition at line 62 of file sockets.h.

Referenced by lwip_socket().

#define SOCK_STREAM 1

Definition at line 61 of file sockets.h.

Referenced by lwip_socket().

## Function Documentation

int lwip_accept | ( | int | s,
|  | struct sockaddr * | addr,
|  | int * | addrlen |
| ) |  |  |

Definition at line 91 of file sockets.c.

References ip_addr::addr, alloc_socket(), lwip_socket::conn, get_socket(), netconn_accept(), netconn_delete(), netconn_peer(), and NULL.

int lwip_bind | ( | int | s,
|  | struct sockaddr * | name,
|  | int | namelen |
| ) |  |  |

Definition at line 121 of file sockets.c.

References ip_addr::addr, lwip_socket::conn, ERR_OK, get_socket(), name, netconn_bind(), ntohs, and NULL.

int lwip_close | ( | int | s | ) |

Definition at line 147 of file sockets.c.

References lwip_socket::conn, DEBUGF, get_socket(), lwip_socket::lastdata, lwip_socket::lastoffset, netbuf_delete(), netconn_delete(), NULL, and SOCKETS_DEBUG.

int lwip_connect | ( | int | s,
|  | struct sockaddr * | name,
|  | int | namelen |
| ) |  |  |

Definition at line 169 of file sockets.c.

References ip_addr::addr, lwip_socket::conn, ERR_OK, get_socket(), name, netconn_connect(), ntohs, and NULL.

int lwip_listen | ( | int | s,
|  | int | backlog |
| ) |  |  |

Definition at line 195 of file sockets.c.

References lwip_socket::conn, ERR_OK, get_socket(), netconn_listen(), and NULL.

int lwip_read | ( | int | s,
|  | void * | mem,
|  | int | len |
| ) |  |  |

Definition at line 293 of file sockets.c.

References lwip_recv().

int lwip_recv | ( | int | s,
|  | void * | mem,
|  | int | len,
|  | unsigned int | flags |
| ) |  |  |

Definition at line 299 of file sockets.c.

References lwip_recvfrom(), and NULL.

Referenced by lwip_read().

int lwip_recvfrom | ( | int | s,
|  | void * | mem,
|  | int | len,
|  | unsigned int | flags,
|  | struct sockaddr * | from,
|  | int * | fromlen |
| ) |  |  |

Definition at line 216 of file sockets.c.

References ip_addr::addr, lwip_socket::conn, get_socket(), htons, lwip_socket::lastdata, lwip_socket::lastoffset, netbuf_copy_partial(), netbuf_delete(), netbuf_fromaddr(), netbuf_fromport(), netbuf_len(), netconn_recv(), NETCONN_TCP, netconn_type(), and NULL.

Referenced by lwip_recv().

int lwip_send | ( | int | s,
|  | void * | dataptr,
|  | int | size,
|  | unsigned int | flags |
| ) |  |  |

Definition at line 305 of file sockets.c.

References lwip_socket::conn, DEBUGF, netbuf::err, ERR_ARG, ERR_OK, get_socket(), netbuf_delete(), netbuf_new(), netbuf_ref(), NETCONN_COPY, netconn_send(), NETCONN_TCP, netconn_type(), NETCONN_UDP, netconn_write(), NULL, and SOCKETS_DEBUG.

Referenced by lwip_sendto(), and lwip_write().

int lwip_sendto | ( | int | s,
|  | void * | dataptr,
|  | int | size,
|  | unsigned int | flags,
|  | struct sockaddr * | to,
|  | int | tolen |
| ) |  |  |

Definition at line 354 of file sockets.c.

References ip_addr::addr, lwip_socket::conn, get_socket(), lwip_send(), netconn_connect(), netconn_peer(), and NULL.

int lwip_socket | ( | int | domain,
|  | int | type,
|  | int | protocol |
| ) |  |  |

Definition at line 383 of file sockets.c.

References alloc_socket(), DEBUGF, netconn_delete(), netconn_new(), NETCONN_TCP, NETCONN_UDP, NULL, SOCK_DGRAM, SOCK_STREAM, and SOCKETS_DEBUG.

int lwip_write | ( | int | s,
|  | void * | dataptr,
|  | int | size |
| ) |  |  |

Definition at line 417 of file sockets.c.

References lwip_socket::conn, DEBUGF, ERR_ARG, ERR_OK, get_socket(), lwip_send(), NETCONN_COPY, NETCONN_TCP, netconn_type(), NETCONN_UDP, netconn_write(), NULL, and SOCKETS_DEBUG.