00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __NETWORK_H
00018
#define __NETWORK_H
00019
00020
00021
00033
00034
00035
#include <fcntl.h>
00036
#include <sys/types.h>
00037
00038
00039
#ifndef WIN32
00040
# include <sys/socket.h>
00041
# include <netinet/in.h>
00042
# include <arpa/inet.h>
00043
# include <netdb.h>
00044
#endif
00045
00046
00047
00051 #define RW_BUFFER 2048
00052
00057 #define RW_SOCKBUFFER 65535
00058
00064 #define NET_IP_STRBUF
00065
00066
00067
00068 EXTERN_C_BEGIN
00069
00070
00071
00078 LIBGIFT_EXPORT
00079
void net_close (
int fd);
00080
00099 LIBGIFT_EXPORT
00100
int net_connect (
const char *ip, in_port_t port, BOOL blocking);
00101
00113 LIBGIFT_EXPORT
00114
int net_accept (
int sock, BOOL blocking);
00115
00124 LIBGIFT_EXPORT
00125
int net_bind (in_port_t port, BOOL blocking);
00126
00134 LIBGIFT_EXPORT
00135
int net_set_blocking (
int fd, BOOL blocking);
00136
00150 LIBGIFT_EXPORT
00151
int net_sock_error (
int fd);
00152
00164 LIBGIFT_EXPORT
00165
int net_send (
int fd,
const char *data, size_t len);
00166
00170 LIBGIFT_EXPORT
00171 in_addr_t net_ip (
const char *ip_str);
00172
00181 LIBGIFT_EXPORT
00182
char *net_ip_str (in_addr_t ip);
00183
00184
#ifdef NET_IP_STRBUF
00185
00190 LIBGIFT_EXPORT
00191
char *net_ip_strbuf (in_addr_t ip,
char *buf, size_t size);
00192
#endif
00193
00200 LIBGIFT_EXPORT
00201 in_addr_t net_peer (
int fd);
00202
00206 LIBGIFT_EXPORT
00207
char *net_peer_ip (
int fd);
00208
00212 LIBGIFT_EXPORT
00213 in_addr_t net_local_ip (
int fd, in_port_t *port);
00214
00222 LIBGIFT_EXPORT
00223 in_addr_t net_mask (
int bitwidth);
00224
00236 LIBGIFT_EXPORT
00237 BOOL net_match_host (in_addr_t ip,
char *match);
00238
00239
00240
00241 LIBGIFT_EXPORT
00242 uint8_t net_get8 (
unsigned char *src);
00243 LIBGIFT_EXPORT
00244 uint16_t net_get16 (
unsigned char *src,
int tohost);
00245 LIBGIFT_EXPORT
00246 uint32_t net_get32 (
unsigned char *src,
int tohost);
00247
00248 LIBGIFT_EXPORT
00249
void net_put8 (
unsigned char *dst, uint8_t src);
00250 LIBGIFT_EXPORT
00251
void net_put16 (
unsigned char *dst, uint16_t src);
00252 LIBGIFT_EXPORT
00253
void net_put32 (
unsigned char *dst, uint32_t src);
00254
00255
00256
00257 LIBGIFT_EXPORT
00258
int net_sock_adj_buf (
int fd,
int buf_name,
float factor);
00259
00260
00261
00262 EXTERN_C_END
00263
00264
00265
00266
#endif