📄 sflsock.h
字号:
int s_port;
char *s_proto;
};
#endif
/*---------------------------------------------------------------------------
* Required definitions
*
* These are symbols used by calling programs: if the compiler does not
* define them, we do it.
*/
#if (!defined (EWOULDBLOCK)) /* BSD tends to use EWOULDBLOCK */
# if (defined (__WINDOWS__))
# define EWOULDBLOCK WSAEWOULDBLOCK
# else
# define EWOULDBLOCK -1
# endif
#endif
#if (!defined (EINPROGRESS)) /* Return code for asynch I/O */
# if (defined (__WINDOWS__))
# define EINPROGRESS WSAEINPROGRESS
# else
# define EINPROGRESS EWOULDBLOCK
# endif
#endif
#if (!defined (EAGAIN)) /* Return code for asynch I/O */
# define EAGAIN EWOULDBLOCK
#endif
#if (!defined (EPIPE)) /* Return code for closed socket */
# define EPIPE -1
#endif
#if (!defined (ECONNRESET)) /* Return code for closed socket */
# if (defined (__WINDOWS__))
# define ECONNRESET WSAECONNRESET
# else
# define ECONNRESET EPIPE
# endif
#endif
#if (defined (__UTYPE_HPUX))
# define FD_SETTYPE (int *) /* Some systems use the older */
#else /* select() format */
# define FD_SETTYPE /* Most use fd_set's */
#endif
#if (!defined (MAXHOSTNAMELEN)) /* Some guys don't define this */
# define MAXHOSTNAMELEN 256 /* constant */
#endif
#if (!defined (INADDR_NONE)) /* Some guys don't define this */
# define INADDR_NONE -1 /* constant */
#endif
/*---------------------------------------------------------------------------
* Error values returned by connect_error(). These reflect the last problem
* detected by one of the passive/connect connection functions.
*/
#define IP_NOERROR 0 /* No errors */
#define IP_NOSOCKETS 1 /* Sockets not supported */
#define IP_BADHOST 2 /* Host not known */
#define IP_BADSERVICE 3 /* Service or port not known */
#define IP_BADPROTOCOL 4 /* Invalid protocol specified */
#define IP_SOCKETERROR 5 /* Error creating socket */
#define IP_CONNECTERROR 6 /* Error making connection */
#define IP_BINDERROR 7 /* Error binding socket */
#define IP_LISTENERROR 8 /* Error preparing to listen */
/*---------------------------------------------------------------------------
* The ip_portbase is added to the port number when creating a service;
* you can set this variable before calling passive_TCP or passive_UDP.
*/
extern int
ip_portbase;
/*---------------------------------------------------------------------------
* The ip_nonblock flag determines whether sockets are blocking or not.
* Under Windows sockets are never blocking. Under UNIX they may be, or
* not. For portability to Windows, this flag is set to TRUE by default.
* The main consequence of this is that after a connect_xxx() call you may
* need to perform a select() on the socket for writing to determine when
* the connection has suceeded.
*/
extern Bool
ip_nonblock;
/*---------------------------------------------------------------------------
* The connect_errlist table provides messages for the connect_error()
* values.
*/
extern char
*connect_errlist [];
/*---------------------------------------------------------------------------
* The ip_passive address is used for passive socket connections. Initially
* this is set to INADDR_ANY. It is used for one passive socket creation
* and reset to INADDR_ANY thereafter.
*/
extern qbyte
ip_passive;
extern int
ip_sockets; /* Number of open sockets */
/*---------------------------------------------------------------------------
* Function prototypes
*/
#ifdef __cplusplus
extern "C" {
#endif
int sock_init (void);
int sock_term (void);
sock_t passive_TCP (const char *service, int queue);
sock_t passive_UDP (const char *service);
sock_t passive_socket (const char *service, const char *protocol,
int queue);
sock_t connect_TCP (const char *host, const char *service);
sock_t connect_UDP (const char *host, const char *service);
sock_t connect_TCP_fast (const struct sockaddr_in *sin);
sock_t connect_UDP_fast (const struct sockaddr_in *sin);
sock_t connect_socket (const char *host, const char *service, const char
*protocol, const struct sockaddr_in *sin,
int retry_max, int retry_delay);
int connect_to_peer (sock_t handle,
const struct sockaddr_in *sin);
int connect_error (void);
sock_t accept_socket (sock_t master);
sock_t create_socket (const char *protocol);
int address_end_point (const char *host, const char *service, const
char *protocol, struct sockaddr_in *sin);
int get_sock_addr (sock_t handle, struct sockaddr_in *sin,
char *name, int namesize);
int get_peer_addr (sock_t handle, struct sockaddr_in *sin,
char *name, int namesize);
void build_sockaddr (struct sockaddr_in *sin, qbyte host, dbyte port);
char *socket_localaddr (sock_t handle);
char *socket_peeraddr (sock_t handle);
Bool socket_is_alive (sock_t handle);
int socket_error (sock_t handle);
int socket_nodelay (sock_t handle);
int read_TCP (sock_t handle, void *buffer, size_t length);
int write_TCP (sock_t handle, const void *buffer, size_t length);
int read_UDP (sock_t handle, void *buffer, size_t length,
const struct sockaddr_in *sin);
int write_UDP (sock_t handle, const void *buffer, size_t length,
const struct sockaddr_in *sin);
int close_socket (sock_t handle);
int sock_select (int nfds, fd_set *readfds, fd_set *writefds,
fd_set *errorfds, struct timeval *timeout);
char *get_hostname (void);
qbyte get_hostaddr (void);
qbyte *get_hostaddrs (void);
const char *sockmsg (void);
Bool socket_is_permitted (const char *address, const char *mask);
char *sock_ntoa (qbyte address);
char *get_host_file (void);
int get_name_server (struct sockaddr_in *ns_address, int ns_max);
#if (defined (__WINDOWS__))
int winsock_last_error (void);
#endif
#ifdef __cplusplus
}
#endif
/* Macros for compatibility with previous versions */
#define socket_hostaddr(handle) socket_peeraddr (handle)
#endif /* Include sflsock.h */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -