d3372da9 |
1 | /* |
2 | * Dolda Connect - Modular multiuser Direct Connect-style client |
3 | * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com) |
4 | * |
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. |
9 | * |
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. |
14 | * |
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 |
18 | */ |
19 | #ifndef _NET_H |
20 | #define _NET_H |
21 | |
22 | #include <sys/socket.h> |
23 | |
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 */ |
e6252feb |
28 | #define SOCK_TOS_MINDELAY 4 |
29 | #define SOCK_TOS_MAXTP 3 |
30 | #define SOCK_TOS_MAXREL 2 |
31 | #define SOCK_TOS_MINCOST 1 |
d3372da9 |
32 | |
33 | struct dgrambuf |
34 | { |
35 | struct dgrambuf *next; |
36 | struct sockaddr *addr; |
37 | socklen_t addrlen; |
38 | void *data; |
39 | size_t size; |
40 | }; |
41 | |
42 | struct socket |
43 | { |
44 | struct socket *next, *prev; |
45 | int refcount; |
46 | int fd; |
47 | int isrealsocket; /* Bleh... */ |
48 | int family; |
49 | int tos; |
50 | int type; |
51 | int state; |
52 | int ignread; |
53 | int events; |
54 | int close; |
55 | struct sockaddr *remote; |
56 | socklen_t remotelen; |
57 | union |
58 | { |
59 | struct |
60 | { |
61 | struct dgrambuf *f, *l; |
62 | } d; |
63 | struct |
64 | { |
65 | void *buf; |
66 | size_t bufsize; |
67 | size_t datasize; |
68 | } s; |
69 | } outbuf; |
70 | union |
71 | { |
72 | struct |
73 | { |
74 | struct dgrambuf *f, *l; |
75 | } d; |
76 | struct |
77 | { |
78 | void *buf; |
79 | size_t bufsize; |
80 | size_t datasize; |
81 | } s; |
82 | } inbuf; |
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); |
88 | void *data; |
89 | }; |
90 | |
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); |
99a28d47 |
111 | int addreq(struct sockaddr *x, struct sockaddr *y); |
d3372da9 |
112 | char *formataddress(struct sockaddr *arg, socklen_t arglen); |
336539c2 |
113 | void sockpushdata(struct socket *sk, void *buf, size_t size); |
d3372da9 |
114 | |
115 | #endif |