2001-09-09 22:24:39 -04:00
|
|
|
/* sock.h
|
|
|
|
* - General Socket Function Headers
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999 the icecast team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SOCK_H
|
|
|
|
#define __SOCK_H
|
|
|
|
|
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
|
|
|
|
|
2002-02-06 20:04:09 -05:00
|
|
|
typedef int sock_t;
|
|
|
|
|
2002-11-22 08:02:51 -05:00
|
|
|
/* The following values are based on unix avoiding errno value clashes */
|
|
|
|
#define SOCK_SUCCESS 0
|
2001-09-09 22:24:39 -04:00
|
|
|
#define SOCK_ERROR -1
|
2002-11-22 08:02:51 -05:00
|
|
|
#define SOCK_TIMEOUT -2
|
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
#define SOCK_BLOCK 0
|
|
|
|
#define SOCK_NONBLOCK 1
|
|
|
|
|
|
|
|
/* sock connect macro */
|
|
|
|
#define sock_connect(h, p) sock_connect_wto(h, p, 0)
|
|
|
|
|
2003-07-06 21:32:42 -04:00
|
|
|
#ifdef _mangle
|
|
|
|
# define sock_initialize _mangle(sock_initialize)
|
|
|
|
# define sock_shutdown _mangle(sock_shutdown)
|
|
|
|
# define sock_get_localip _mangle(sock_get_localip)
|
|
|
|
# define sock_error _mangle(sock_error)
|
|
|
|
# define sock_recoverable _mangle(sock_recoverable)
|
|
|
|
# define sock_stalled _mangle(sock_stalled)
|
|
|
|
# define sock_valid_socket _mangle(sock_valid_socket)
|
|
|
|
# define sock_set_blocking _mangle(sock_set_blocking)
|
|
|
|
# define sock_set_nolinger _mangle(sock_set_nolinger)
|
|
|
|
# define sock_set_nodelay _mangle(sock_set_nodelay)
|
|
|
|
# define sock_set_keepalive _mangle(sock_set_keepalive)
|
|
|
|
# define sock_close _mangle(sock_close)
|
|
|
|
# define sock_connect_wto _mangle(sock_connect_wto)
|
|
|
|
# define sock_connect_non_blocking _mangle(sock_connect_non_blocking)
|
|
|
|
# define sock_connected _mangle(sock_connected)
|
|
|
|
# define sock_write_bytes _mangle(sock_write_bytes)
|
|
|
|
# define sock_write _mangle(sock_write)
|
|
|
|
# define sock_write_fmt _mangle(sock_write_fmt)
|
|
|
|
# define sock_write_string _mangle(sock_write_string)
|
|
|
|
# define sock_writev _mangle(sock_writev)
|
|
|
|
# define sock_read_bytes _mangle(sock_read_bytes)
|
|
|
|
# define sock_read_line _mangle(sock_read_line)
|
|
|
|
# define sock_get_server_socket _mangle(sock_get_server_socket)
|
|
|
|
# define sock_listen _mangle(sock_listen)
|
|
|
|
# define sock_accept _mangle(sock_accept)
|
|
|
|
#endif
|
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
/* Misc socket functions */
|
|
|
|
void sock_initialize(void);
|
|
|
|
void sock_shutdown(void);
|
|
|
|
char *sock_get_localip(char *buff, int len);
|
|
|
|
int sock_error(void);
|
|
|
|
int sock_recoverable(int error);
|
2003-07-06 21:32:42 -04:00
|
|
|
int sock_stalled(int error);
|
2001-09-09 22:24:39 -04:00
|
|
|
int sock_valid_socket(sock_t sock);
|
|
|
|
int sock_set_blocking(sock_t sock, const int block);
|
2002-03-22 16:44:29 -05:00
|
|
|
int sock_set_nolinger(sock_t sock);
|
|
|
|
int sock_set_keepalive(sock_t sock);
|
2003-01-18 02:08:00 -05:00
|
|
|
int sock_set_nodelay(sock_t sock);
|
2001-09-09 22:24:39 -04:00
|
|
|
int sock_close(sock_t sock);
|
|
|
|
|
|
|
|
/* Connection related socket functions */
|
|
|
|
sock_t sock_connect_wto(const char *hostname, const int port, const int timeout);
|
2003-07-06 21:32:42 -04:00
|
|
|
int sock_connect_non_blocking(const char *host, const unsigned port);
|
2004-07-26 12:03:52 -04:00
|
|
|
int sock_connected(int sock, int timeout);
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* Socket write functions */
|
2002-11-22 08:02:51 -05:00
|
|
|
int sock_write_bytes(sock_t sock, const void *buff, const size_t len);
|
2001-09-09 22:24:39 -04:00
|
|
|
int sock_write(sock_t sock, const char *fmt, ...);
|
2003-06-05 20:05:19 -04:00
|
|
|
int sock_write_fmt(sock_t sock, const char *fmt, va_list ap);
|
2001-09-09 22:24:39 -04:00
|
|
|
int sock_write_string(sock_t sock, const char *buff);
|
2002-11-22 08:02:51 -05:00
|
|
|
ssize_t sock_writev (int sock, const struct iovec *iov, const size_t count);
|
|
|
|
|
2001-09-09 22:24:39 -04:00
|
|
|
|
|
|
|
/* Socket read functions */
|
|
|
|
int sock_read_bytes(sock_t sock, char *buff, const int len);
|
|
|
|
int sock_read_line(sock_t sock, char *string, const int len);
|
|
|
|
|
|
|
|
/* server socket functions */
|
2007-08-08 23:19:24 -04:00
|
|
|
sock_t sock_get_server_socket(int port, const char *sinterface);
|
2001-09-09 22:24:39 -04:00
|
|
|
int sock_listen(sock_t serversock, int backlog);
|
2007-08-08 23:19:24 -04:00
|
|
|
int sock_accept(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 */
|