1 /* dircproxy 2 * Copyright (C) 2000-2003 Scott James Remnant <scott at netsplit dot com> 3 * 4 * Copyright (C) 2004-2008 Francois Harvey <contact at francoisharvey dot ca> 5 * 6 * Copyright (C) 2008-2009 Noel Shrum <noel dot w8tvi at gmail dot com> 7 * Francois Harvey <contact at francoisharvey dot ca> 8 * 9 * 10 * net.h 11 * -- 12 * @(#) $Id: net.h,v 1.9 2002/12/29 21:30:12 scott Exp $ 13 * 14 * This file is distributed according to the GNU General Public 15 * License. For full details, read the top of 'main.c' or the 16 * file called COPYING that was distributed with this code. 17 */ 18 19 #ifndef __DIRCPROXY_NET_H 20 #define __DIRCPROXY_NET_H 21 22 #if HAVE_CONFIG_H 23 #include "config.h" 24 #endif 25 26 #if HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 27 # define HAVE_IPV6 1 28 # define SOCKADDR struct sockaddr_storage 29 # define SOCKADDR_LEN(x) ((x)->ss_family == AF_INET ? \ 30 sizeof(struct sockaddr_in) : \ 31 sizeof(struct sockaddr_in6)) 32 #else 33 # define SOCKADDR struct sockaddr_in 34 # define SOCKADDR_LEN(x) sizeof(struct sockaddr_in) 35 #endif 36 /* these are in the same place in both _in and _in6 versions */ 37 #define SOCKADDR_FAMILY(x) ((struct sockaddr_in *)(x))->sin_family 38 #define SOCKADDR_PORT(x) ((struct sockaddr_in *)(x))->sin_port 39 40 /* Socket types */ 41 #define SOCK_NORMAL 0x00 42 #define SOCK_CONNECTING 0x01 43 #define SOCK_LISTENING 0x02 44 45 /* handy defines */ 46 #define ACTIVITY_FUNCTION(_FUNC) ((void (*)(void *, int)) (_FUNC)) 47 #define ERROR_FUNCTION(_FUNC) ((void (*)(void *, int, int)) (_FUNC)) 48 49 /* functions */ 50 extern int net_socket(int); 51 extern void net_create(int *); 52 extern void net_keepalive(int); 53 extern int net_close(int *); 54 extern int net_closeall(void); 55 extern int net_flush(void); 56 extern int net_hook(int, int, void *, 57 void(*)(void *, int), void(*)(void *, int, int)); 58 extern int net_throttle(int, long, long); 59 extern int net_send(int, const char *, ...); 60 extern int net_sendurgent(int, const char *, ...); 61 extern int net_queue(int, void *, int); 62 extern int net_gets(int, char **, const char *); 63 extern int net_read(int, void *, int); 64 extern int net_poll(void); 65 66 extern const char *net_ntop(SOCKADDR *, char *, int); 67 extern int net_pton(int af, const char *, void *); 68 extern int net_filladdr(SOCKADDR *, const char *, unsigned short); 69 70 #endif /* __DIRCPROXY_NET_H */ 71