Mercurial > hg > nnchat
diff libnnchat.h @ 352:b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 23 Jun 2011 06:28:40 +0300 |
parents | 8e509d6546d3 |
children | c01e42fc9adb |
line wrap: on
line diff
--- a/libnnchat.h Thu Jun 23 04:39:10 2011 +0300 +++ b/libnnchat.h Thu Jun 23 06:28:40 2011 +0300 @@ -34,14 +34,49 @@ enum { NN_CONN_UNINIT = 0, + NN_CONN_PROXY_NEG, NN_CONN_OPEN, NN_CONN_CLOSED }; +enum { + NN_PROXY_NONE = 0, + NN_PROXY_SOCKS4, + NN_PROXY_SOCKS4A, + + NN_PROXY_LAST +}; + +enum { + SOCKS_CMD_CONNECT = 1, + SOCKS_CMD_BIND = 2 +}; + +struct nn_socks_t { + uint8_t version; + uint8_t command; + in_port_t port; + in_addr_t addr; +} __attribute__((__packed__));; + +struct nn_socks_res_t { + uint8_t nb; + uint8_t result; + in_port_t port; + in_addr_t addr; +} __attribute__((__packed__));; + typedef struct _nn_conn_t { + struct { + int type; + int port; + struct in_addr addr; + } proxy; + + char *host; int socket; int port; - struct in_addr address; + struct in_addr addr; fd_set sockfds; void (*errfunc)(struct _nn_conn_t *conn, const char *fmt, va_list ap); @@ -55,13 +90,18 @@ ssize_t got; } nn_conn_t; + const char *nn_get_errstr(int err); -BOOL nn_network_init(void); +BOOL nn_network_init(); void nn_network_close(void); -nn_conn_t * nn_conn_open(struct in_addr *addr, const int port); +nn_conn_t * nn_conn_open( + void (*errfunc)(struct _nn_conn_t *conn, const char *fmt, va_list ap), + void (*msgfunc)(struct _nn_conn_t *conn, const char *fmt, va_list ap), + int ptype, int pport, struct in_addr *paddr, + struct in_addr *addr, const int port, const char *host); void nn_conn_close(nn_conn_t *); -BOOL nn_conn_pull(nn_conn_t *); +int nn_conn_pull(nn_conn_t *); BOOL nn_conn_send_buf(nn_conn_t *, const char *buf, const size_t len); BOOL nn_conn_send_msg(nn_conn_t *, const char *user, const char *fmt, ...); BOOL nn_conn_check(nn_conn_t *);