2001-09-09 22:24:39 -04:00
|
|
|
/* sock.h
|
|
|
|
* - General Socket Function Headers
|
|
|
|
*
|
2018-10-12 06:28:09 -04:00
|
|
|
* Copyright (C) 2014 Michael Smith <msmith@icecast.org>,
|
|
|
|
* Brendan Cully <brendan@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>,
|
|
|
|
* Jack Moffitt <jack@icecast.org>,
|
|
|
|
* Ed "oddsock" Zaleski <oddsock@xiph.org>,
|
|
|
|
* Copyright (C) 2012-2018 Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
|
2001-09-09 22:24:39 -04:00
|
|
|
*
|
2014-12-05 04:31:08 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2001-09-09 22:24:39 -04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-12-05 04:31:08 -05:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2001-09-09 22:24:39 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-12 06:16:06 -04:00
|
|
|
#ifndef _LIBIGLOO__SOCK_H_
|
|
|
|
#define _LIBIGLOO__SOCK_H_
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2003-03-07 09:57:36 -05:00
|
|
|
#include <stdarg.h>
|
2002-11-22 08:13:04 -05:00
|
|
|
|
2003-10-19 23:08:46 -04:00
|
|
|
#ifdef HAVE_WINSOCK2_H
|
2001-10-20 01:57:28 -04:00
|
|
|
#include <winsock2.h>
|
2003-10-19 23:08:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2002-11-30 21:11:07 -05:00
|
|
|
#include <unistd.h>
|
2003-10-19 23:08:46 -04:00
|
|
|
#elif _WIN32
|
2006-02-23 23:37:22 -05:00
|
|
|
#include <compat.h>
|
2002-11-30 21:11:07 -05:00
|
|
|
#endif
|
2001-09-09 22:24:39 -04:00
|
|
|
|
2002-11-22 08:02:51 -05:00
|
|
|
#ifdef HAVE_SYS_UIO_H
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#else
|
|
|
|
#ifndef _SYS_UIO_H
|
|
|
|
struct iovec
|
|
|
|
{
|
|
|
|
void *iov_base;
|
|
|
|
size_t iov_len;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2003-03-17 11:47:20 -05:00
|
|
|
#if !defined(HAVE_INET_ATON) && defined(HAVE_INET_PTON)
|
2003-02-06 08:10:48 -05:00
|
|
|
#define inet_aton(a,b) inet_pton(AF_INET, (a), (b))
|
|
|
|
#endif
|
|
|
|
|
2003-02-13 06:29:07 -05:00
|
|
|
#ifdef INET6_ADDRSTRLEN
|
|
|
|
#define MAX_ADDR_LEN INET6_ADDRSTRLEN
|
|
|
|
#else
|
|
|
|
#define MAX_ADDR_LEN 46
|
|
|
|
#endif
|
|
|
|
|
2018-10-12 07:27:17 -04:00
|
|
|
#ifndef igloo_sock_t
|
|
|
|
#define igloo_sock_t int
|
2007-10-24 17:42:01 -04:00
|
|
|
#endif
|
2002-02-06 20:04:09 -05:00
|
|
|
|
2002-11-22 08:02:51 -05:00
|
|
|
/* The following values are based on unix avoiding errno value clashes */
|
2018-10-12 07:27:17 -04:00
|
|
|
#define igloo_SOCK_SUCCESS 0
|
|
|
|
#define igloo_SOCK_ERROR (igloo_sock_t)-1
|
|
|
|
#define igloo_SOCK_TIMEOUT -2
|
2002-11-22 08:02:51 -05:00
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
/* sock connect macro */
|
2018-10-12 07:27:17 -04:00
|
|
|
#define igloo_sock_connect(h, p) igloo_sock_connect_wto(h, p, 0)
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* Misc socket functions */
|
2018-10-12 06:55:24 -04:00
|
|
|
void igloo_sock_initialize(void);
|
|
|
|
void igloo_sock_shutdown(void);
|
|
|
|
char *igloo_sock_get_localip(char *buff, int len);
|
|
|
|
int igloo_sock_error(void);
|
|
|
|
int igloo_sock_recoverable(int error);
|
|
|
|
int igloo_sock_stalled(int error);
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_sock_valid_socket(igloo_sock_t sock);
|
|
|
|
int igloo_sock_active (igloo_sock_t sock);
|
|
|
|
int igloo_sock_set_blocking(igloo_sock_t sock, int block);
|
|
|
|
int igloo_sock_set_nolinger(igloo_sock_t sock);
|
|
|
|
int igloo_sock_set_keepalive(igloo_sock_t sock);
|
|
|
|
int igloo_sock_set_nodelay(igloo_sock_t sock);
|
|
|
|
void igloo_sock_set_send_buffer (igloo_sock_t sock, int win_size);
|
2018-10-12 06:55:24 -04:00
|
|
|
void igloo_sock_set_error(int val);
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_sock_close(igloo_sock_t sock);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* Connection related socket functions */
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_sock_t igloo_sock_connect_wto(const char *hostname, int port, int timeout);
|
|
|
|
igloo_sock_t igloo_sock_connect_wto_bind(const char *hostname, int port, const char *bnd, int timeout);
|
|
|
|
igloo_sock_t igloo_sock_connect_non_blocking(const char *host, unsigned port);
|
|
|
|
int igloo_sock_connected(igloo_sock_t sock, int timeout);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* Socket write functions */
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_sock_write_bytes(igloo_sock_t sock, const void *buff, size_t len);
|
|
|
|
int igloo_sock_write(igloo_sock_t sock, const char *fmt, ...);
|
|
|
|
int igloo_sock_write_fmt(igloo_sock_t sock, const char *fmt, va_list ap);
|
|
|
|
int igloo_sock_write_string(igloo_sock_t sock, const char *buff);
|
|
|
|
ssize_t igloo_sock_writev (igloo_sock_t sock, const struct iovec *iov, size_t count);
|
2002-11-22 08:02:51 -05:00
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* Socket read functions */
|
2018-10-12 07:27:17 -04:00
|
|
|
int igloo_sock_read_bytes(igloo_sock_t sock, char *buff, size_t len);
|
|
|
|
int igloo_sock_read_line(igloo_sock_t sock, char *string, const int len);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* server socket functions */
|
2018-10-12 07:27:17 -04:00
|
|
|
igloo_sock_t igloo_sock_get_server_socket(int port, const char *sinterface);
|
|
|
|
int igloo_sock_listen(igloo_sock_t serversock, int backlog);
|
|
|
|
igloo_sock_t igloo_sock_accept(igloo_sock_t serversock, char *ip, size_t len);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
int inet_aton(const char *s, struct in_addr *a);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __SOCK_H */
|