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>
25 #define SOCK_LST 0 /* Listening */
26 #define SOCK_SYN 1 /* Connecting */
27 #define SOCK_EST 2 /* Established */
28 #define SOCK_STL 3 /* Stale, dead */
29 #define SOCK_TOS_MINDELAY 4
30 #define SOCK_TOS_MAXTP 3
31 #define SOCK_TOS_MAXREL 2
32 #define SOCK_TOS_MINCOST 1
36 struct dgrambuf *next;
37 struct sockaddr *addr;
45 struct socket *next, *prev;
48 int isrealsocket; /* Bleh... */
56 struct sockaddr *remote;
63 struct dgrambuf *f, *l;
76 struct dgrambuf *f, *l;
85 void (*conncb)(struct socket *sk, int err, void *data);
86 void (*errcb)(struct socket *sk, int err, void *data);
87 void (*readcb)(struct socket *sk, void *data);
88 void (*writecb)(struct socket *sk, void *data);
89 void (*acceptcb)(struct socket *sk, struct socket *newsk, void *data);
93 void putsock(struct socket *sk);
94 void getsock(struct socket *sk);
95 struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
96 struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
97 struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data);
98 struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
99 int pollsocks(int timeout);
100 void sockqueue(struct socket *sk, void *data, size_t size);
101 size_t sockqueuesize(struct socket *sk);
102 int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data);
103 struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen);
104 struct socket *netdupsock(struct socket *sk);
105 void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen);
106 int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
107 int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
108 int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf);
109 void closesock(struct socket *sk);
110 void *sockgetinbuf(struct socket *sk, size_t *size);
111 struct socket *wrapsock(int fd);
112 size_t sockgetdatalen(struct socket *sk);
113 int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf);
114 int socksettos(struct socket *sk, int tos);
115 int addreq(struct sockaddr *x, struct sockaddr *y);
116 char *formataddress(struct sockaddr *arg, socklen_t arglen);
117 void sockpushdata(struct socket *sk, void *buf, size_t size);