libsocket
libinetsocket.h
Go to the documentation of this file.
1 #ifndef LIBSOCKET_LIBINETSOCKET_H_C1A9FFEDF5E94B2FB010A0FAA0E92A2F
2 #define LIBSOCKET_LIBINETSOCKET_H_C1A9FFEDF5E94B2FB010A0FAA0E92A2F
3 
9 /*
10  The committers of the libsocket project, all rights reserved
11  (c) 2012, dermesser <lbo@spheniscida.de>
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15 
16  1. Redistributions of source code must retain the above
17  copyright notice, this list of conditions and the following disclaimer.
18  2. Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the following disclaimer in the
20  documentation and/or other materials provided with the distribution.
21 
22  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS “AS IS” AND
23  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
26  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /* Headers (e.g. for flags) */
35 #include <sys/socket.h>
36 #include <sys/types.h>
37 
38 /* Macro definitions */
39 
40 #define LIBSOCKET_TCP 1
41 #define LIBSOCKET_UDP 2
42 
43 #define LIBSOCKET_IPv4 3
44 #define LIBSOCKET_IPv6 4
45 
46 #define LIBSOCKET_BOTH \
47  5 /* let the resolver/library choose (TCP/UDP or IPv4/6) */
48 
49 #define LIBSOCKET_READ 1
50 #define LIBSOCKET_WRITE 2
51 
52 #define LIBSOCKET_NUMERIC 1
53 
54 #ifdef __cplusplus
55 #ifdef MIXED
56 extern "C" {
57 #endif
58 #endif
59 
60 extern int create_inet_stream_socket(const char* host, const char* service,
61  char proto_osi3, int flags);
62 extern int create_inet_dgram_socket(char proto_osi3, int flags);
63 extern ssize_t sendto_inet_dgram_socket(int sfd, const void* buf, size_t size,
64  const char* host, const char* service,
65  int sendto_flags);
66 extern ssize_t recvfrom_inet_dgram_socket(int sfd, void* buffer, size_t size,
67  char* src_host, size_t src_host_len,
68  char* src_service,
69  size_t src_service_len,
70  int recvfrom_flags, int numeric);
71 extern int connect_inet_dgram_socket(int sfd, const char* host,
72  const char* service);
73 extern int destroy_inet_socket(int sfd);
74 extern int shutdown_inet_stream_socket(int sfd, int method);
75 extern int create_inet_server_socket(const char* bind_addr,
76  const char* bind_port, char proto_osi4,
77  char proto_osi3, int flags);
78 extern int accept_inet_stream_socket(int sfd, char* src_host,
79  size_t src_host_len, char* src_service,
80  size_t src_service_len, int flags,
81  int accept_flags);
82 extern int get_address_family(const char* hostname);
83 
84 #ifdef __linux__
85 extern int create_multicast_socket(const char* group, const char* port,
86  const char* local);
87 #endif
88 
89 #ifdef __cplusplus
90 #ifdef MIXED
91 }
92 #endif
93 #endif
94 
95 #endif
int create_inet_server_socket(const char *bind_addr, const char *bind_port, char proto_osi4, char proto_osi3, int flags)
Create a TCP or UDP server socket.
int get_address_family(const char *hostname)
Look up which address families a host supports.
ssize_t sendto_inet_dgram_socket(int sfd, const void *buf, size_t size, const char *host, const char *service, int sendto_flags)
This function is the equivalent to sendto(2)
int destroy_inet_socket(int sfd)
Close a socket.
int create_multicast_socket(const char *group, const char *port, const char *local)
Create a datagram socket and join to the multicast group address.
int accept_inet_stream_socket(int sfd, char *src_host, size_t src_host_len, char *src_service, size_t src_service_len, int flags, int accept_flags)
Accept a connection attempt on a server socket.
int create_inet_stream_socket(const char *host, const char *service, char proto_osi3, int flags)
Create and connect a new TCP/IP socket.
int shutdown_inet_stream_socket(int sfd, int method)
Perform a shutdown(2) call on a socket.
int connect_inet_dgram_socket(int sfd, const char *host, const char *service)
Connect a UDP socket.
ssize_t recvfrom_inet_dgram_socket(int sfd, void *buffer, size_t size, char *src_host, size_t src_host_len, char *src_service, size_t src_service_len, int recvfrom_flags, int numeric)
Receive data from a UDP/IP socket.
int create_inet_dgram_socket(char proto_osi3, int flags)
Creates a new UDP/IP socket.