socket.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-15 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
29 #ifndef SYS_SOCKET_H
30 #define SYS_SOCKET_H
31 
32 #ifdef CPU_NATIVE
33 /* Ignore Linux definitions in native */
34 #define _BITS_SOCKADDR_H 1
35 #define __SOCKADDR_COMMON(sa_prefix) \
36  sa_family_t sa_prefix##family
37 
38 #define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int))
39 #endif
40 
41 #include <stdlib.h>
42 #include <sys/types.h>
43 #include <sys/uio.h>
44 
45 #include "kernel_types.h"
46 #include "net/af.h"
47 #include "sys/bytes.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
56 #ifndef SOCKET_POOL_SIZE
57 #ifdef MODULE_SOCK_TCP
58 #define SOCKET_POOL_SIZE (6) /* define enough for accepted sockets */
59 #else
60 #define SOCKET_POOL_SIZE (4)
61 #endif
62 #endif
63 
68 #ifndef SOCKET_TCP_QUEUE_SIZE
69 #ifdef MODULE_SOCK_TCP
70 #define SOCKET_TCP_QUEUE_SIZE (2)
71 #else
72 #define SOCKET_TCP_QUEUE_SIZE (0)
73 #endif
74 #endif
75 
83 #define SOCKADDR_MAX_DATA_LEN (26)
84 
89 #define SOCK_DGRAM (1)
90 #define SOCK_RAW (2)
91 #define SOCK_SEQPACKET (3)
92 #define SOCK_STREAM (4)
95 #define SOL_SOCKET (-1)
102 #define SO_ACCEPTCONN (0)
103 #define SO_BROADCAST (1)
104 #define SO_DEBUG (2)
105 #define SO_DONTROUTE (3)
106 #define SO_ERROR (4)
107 #define SO_KEEPALIVE (5)
108 #define SO_LINGER (6)
109 #define SO_OOBINLINE (7)
110 #define SO_RCVBUF (8)
111 #define SO_RCVLOWAT (9)
112 #define SO_RCVTIMEO (10)
113 #define SO_REUSEADDR (11)
114 #define SO_SNDBUF (12)
115 #define SO_SNDLOWAT (13)
116 #define SO_SNDTIMEO (14)
117 #define SO_TYPE (15)
120 typedef unsigned short sa_family_t;
125 struct sockaddr {
127  char sa_data[SOCKADDR_MAX_DATA_LEN];
128 };
129 
137 };
138 
139 
185 int accept(int socket, struct sockaddr *__restrict address,
186  socklen_t *__restrict address_len);
187 
212 int bind(int socket, const struct sockaddr *address,
213  socklen_t address_len);
214 
242 int connect(int socket, const struct sockaddr *address, socklen_t address_len);
243 
267 int getpeername(int socket, struct sockaddr *__restrict address,
268  socklen_t *__restrict address_len);
269 
293 int getsockname(int socket, struct sockaddr *__restrict address,
294  socklen_t *__restrict address_len);
295 
317 int listen(int socket, int backlog);
318 
353 ssize_t recvfrom(int socket, void *__restrict buffer, size_t length, int flags,
354  struct sockaddr *__restrict address,
355  socklen_t *__restrict address_len);
356 
380 static inline ssize_t recv(int socket, void *buffer, size_t length, int flags)
381 {
382  return recvfrom(socket, buffer, length, flags, NULL, NULL);
383 }
384 
426 ssize_t sendto(int socket, const void *buffer, size_t length, int flags,
427  const struct sockaddr *address, socklen_t address_len);
428 
450 static inline ssize_t send(int socket, const void *buffer, size_t length,
451  int flags)
452 {
453  return sendto(socket, buffer, length, flags, NULL, 0);
454 }
455 
477 int socket(int domain, int type, int protocol);
478 
483 static inline int getsockopt(int socket, int level, int option_name, void *option_value,
484  socklen_t *option_len)
485 {
486  (void)socket;
487  (void)level;
488  (void)option_name;
489  (void)option_value;
490  (void)option_len;
491  return -1;
492 }
493 
494 int setsockopt(int socket, int level, int option_name, const void *option_value,
495  socklen_t option_len);
496 
499 #ifdef __cplusplus
500 }
501 #endif
502 
506 #endif /* SYS_SOCKET_H */
Types used by the kernel.
static int getsockopt(int socket, int level, int option_name, void *option_value, socklen_t *option_len)
Definition: socket.h:483
static ssize_t recv(int socket, void *buffer, size_t length, int flags)
Receive a message from a connected socket.
Definition: socket.h:380
int getpeername(int socket, struct sockaddr *__restrict address, socklen_t *__restrict address_len)
Get the name of the peer socket.
sa_family_t sa_family
Address family.
Definition: socket.h:126
uint8_t ss_data[SOCKADDR_MAX_DATA_LEN]
Socket address.
Definition: socket.h:136
sa_family_t ss_family
Address family.
Definition: socket.h:135
size_t socklen_t
socket address length
Definition: bytes.h:29
int accept(int socket, struct sockaddr *__restrict address, socklen_t *__restrict address_len)
Accept a new connection on a socket.
ssize_t sendto(int socket, const void *buffer, size_t length, int flags, const struct sockaddr *address, socklen_t address_len)
Send a message on a socket.
#define SOCKADDR_MAX_DATA_LEN
Maximum data length for a socket address.
Definition: socket.h:83
Used to define the socket address.
Definition: socket.h:125
unsigned short sa_family_t
address family type
Definition: socket.h:120
Implementation based socket address table.
Definition: socket.h:134
int getsockname(int socket, struct sockaddr *__restrict address, socklen_t *__restrict address_len)
Get the socket name.
int listen(int socket, int backlog)
Listen for socket connections and limit the queue of incoming connections.
static ssize_t send(int socket, const void *buffer, size_t length, int flags)
Send a message on a socket.
Definition: socket.h:450
int bind(int socket, const struct sockaddr *address, socklen_t address_len)
Bind a name to a socket.
System-internal byte operations.
Global UNIX address family definitions.
int connect(int socket, const struct sockaddr *address, socklen_t address_len)
Connect a socket.
libc header for scatter/gather I/O
int socket(int domain, int type, int protocol)
Create an endpoint for communication.
stdlib.h wrapper for MSP430
ssize_t recvfrom(int socket, void *__restrict buffer, size_t length, int flags, struct sockaddr *__restrict address, socklen_t *__restrict address_len)
Receive a message from a socket.