2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sys/socket.h>
24 #define SOCK_LST 0 /* Listening */
25 #define SOCK_SYN 1 /* Connecting */
26 #define SOCK_EST 2 /* Established */
27 #define SOCK_STL 3 /* Stale, dead */
28 #define SOCK_TOS_MINDELAY 4
29 #define SOCK_TOS_MAXTP 3
30 #define SOCK_TOS_MAXREL 2
31 #define SOCK_TOS_MINCOST 1
35 struct dgrambuf *next;
36 struct sockaddr *addr;
44 struct socket *next, *prev;
47 int isrealsocket; /* Bleh... */
55 struct sockaddr *remote;
61 struct dgrambuf *f, *l;
74 struct dgrambuf *f, *l;
83 void (*conncb)(struct socket *sk, int err, void *data);
84 void (*errcb)(struct socket *sk, int err, void *data);
85 void (*readcb)(struct socket *sk, void *data);
86 void (*writecb)(struct socket *sk, void *data);
87 void (*acceptcb)(struct socket *sk, struct socket *newsk, void *data);
91 void putsock(struct socket *sk);
92 void getsock(struct socket *sk);
93 struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
94 struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
95 struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
96 int pollsocks(int timeout);
97 void sockqueue(struct socket *sk, void *data, size_t size);
98 size_t sockqueuesize(struct socket *sk);
99 int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data);
100 struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen);
101 struct socket *netdupsock(struct socket *sk);
102 void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen);
103 int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
104 int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
105 void closesock(struct socket *sk);
106 void *sockgetinbuf(struct socket *sk, size_t *size);
107 struct socket *wrapsock(int fd);
108 size_t sockgetdatalen(struct socket *sk);
109 int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf);
110 int socksettos(struct socket *sk, int tos);
111 int addreq(struct sockaddr *x, struct sockaddr *y);
112 char *formataddress(struct sockaddr *arg, socklen_t arglen);
113 void sockpushdata(struct socket *sk, void *buf, size_t size);