- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# sockets.c File Reference

`#include <ubixos/types.h>`
`#include "net/debug.h"`
`#include "net/api.h"`
`#include "net/sockets.h"`

Go to the source code of this file.

## Data Structures
struct | lwip_socket
## Defines
#define | NUM_SOCKETS 10
## Functions
static int | alloc_socket (struct netconn *newconn)
static struct lwip_socket * | get_socket (int s)
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 *data, int size, unsigned int flags)
int | lwip_sendto (int s, void *data, 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 *data, int size)
## Variables
static struct lwip_socket | sockets [NUM_SOCKETS]

## Define Documentation

#define NUM_SOCKETS 10

Definition at line 43 of file sockets.c.

Referenced by alloc_socket(), and get_socket().

## Function Documentation

static int alloc_socket | ( | struct netconn * | newconn | ) | `[static]`

Definition at line 74 of file sockets.c.

References lwip_socket::conn, lwip_socket::lastdata, lwip_socket::lastoffset, NULL, NUM_SOCKETS, and sockets.

Referenced by lwip_accept(), and lwip_socket().

static struct lwip_socket* get_socket | ( | int | s | ) | `[static]`

Definition at line 55 of file sockets.c.

References lwip_socket::conn, NULL, NUM_SOCKETS, and sockets.

Referenced by lwip_accept(), lwip_bind(), lwip_close(), lwip_connect(), lwip_listen(), lwip_recvfrom(), lwip_send(), lwip_sendto(), and lwip_write().

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 * | data,
|  | 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 * | data,
|  | 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 * | data,
|  | 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.

## Variable Documentation

struct lwip_socket sockets[NUM_SOCKETS]`[static]`

Definition at line 51 of file sockets.c.

Referenced by alloc_socket(), and get_socket().