Commit | Line | Data |
---|---|---|
d3372da9 | 1 | /* |
2 | * Dolda Connect - Modular multiuser Direct Connect-style client | |
302a2600 | 3 | * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com> |
d3372da9 | 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> | |
9e5f2b29 | 23 | #include <sys/un.h> |
d3372da9 | 24 | |
2b9a1911 FT |
25 | #define SOCK_SYN 0 /* Connecting */ |
26 | #define SOCK_EST 1 /* Established */ | |
27 | #define SOCK_STL 2 /* 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 | { | |
d3372da9 | 44 | int refcount; |
d3372da9 | 45 | int state; |
2b9a1911 | 46 | int dgram; |
02a705ad | 47 | int eos; |
81286a22 | 48 | size_t maxbuf; |
f96d0914 | 49 | struct socket *back, *pnext; |
d3372da9 | 50 | union |
51 | { | |
52 | struct | |
53 | { | |
54 | struct dgrambuf *f, *l; | |
55 | } d; | |
56 | struct | |
57 | { | |
58 | void *buf; | |
59 | size_t bufsize; | |
60 | size_t datasize; | |
61 | } s; | |
2b9a1911 | 62 | } buf; |
d3372da9 | 63 | void (*conncb)(struct socket *sk, int err, void *data); |
64 | void (*errcb)(struct socket *sk, int err, void *data); | |
65 | void (*readcb)(struct socket *sk, void *data); | |
66 | void (*writecb)(struct socket *sk, void *data); | |
2b9a1911 FT |
67 | struct ufd *ufd; |
68 | void *data; | |
b2e73d7b FT |
69 | char *dbgnm; |
70 | int dbglvl; | |
2b9a1911 FT |
71 | }; |
72 | ||
73 | struct lport { | |
74 | struct ufd *ufd; | |
75 | void (*acceptcb)(struct lport *lp, struct socket *newsk, void *data); | |
76 | void (*errcb)(struct lport *lp, int err, void *data); | |
d3372da9 | 77 | void *data; |
78 | }; | |
79 | ||
80 | void putsock(struct socket *sk); | |
81 | void getsock(struct socket *sk); | |
1ce5968e | 82 | struct socket *netsockpipe(void); |
02a705ad FT |
83 | struct lport *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct lport *, struct socket *, void *), void *data); |
84 | struct lport *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct lport *, struct socket *, void *), void *data); | |
85 | struct lport *netcstcplisten(int port, int local, void (*func)(struct lport *, struct socket *, void *), void *data); | |
cab0b442 | 86 | struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data); |
d3372da9 | 87 | int pollsocks(int timeout); |
02a705ad | 88 | void freedgbuf(struct dgrambuf *dg); |
d3372da9 | 89 | void sockqueue(struct socket *sk, void *data, size_t size); |
40c21c4f | 90 | void sockerror(struct socket *sk, int en); |
81286a22 | 91 | /* size_t sockqueuesize(struct socket *sk); */ |
1ff9e8ea | 92 | size_t socktqueuesize(struct socket *sk); |
81286a22 | 93 | ssize_t sockqueueleft(struct socket *sk); |
d3372da9 | 94 | int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data); |
95 | struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen); | |
2b9a1911 | 96 | struct socket *netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen); |
d3372da9 | 97 | int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); |
a88a5873 | 98 | int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf); |
f96d0914 FT |
99 | int lstgetremotename(struct lport *lp, struct sockaddr **namebuf, socklen_t *lenbuf); |
100 | int lstgetremotename2(struct lport *lp, struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); | |
d3372da9 | 101 | void closesock(struct socket *sk); |
2b9a1911 | 102 | void closelport(struct lport *lp); |
d3372da9 | 103 | void *sockgetinbuf(struct socket *sk, size_t *size); |
104 | struct socket *wrapsock(int fd); | |
105 | size_t sockgetdatalen(struct socket *sk); | |
d3372da9 | 106 | int socksettos(struct socket *sk, int tos); |
99a28d47 | 107 | int addreq(struct sockaddr *x, struct sockaddr *y); |
d3372da9 | 108 | char *formataddress(struct sockaddr *arg, socklen_t arglen); |
2b9a1911 | 109 | char *formatsockpeer(struct socket *sk); |
336539c2 | 110 | void sockpushdata(struct socket *sk, void *buf, size_t size); |
81286a22 | 111 | /* void sockblock(struct socket *sk, int block); */ |
2b9a1911 FT |
112 | int sockpeeraddr(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); |
113 | int getucred(struct socket *sk, uid_t *uid, gid_t *gid); | |
114 | int sockfamily(struct socket *sk); | |
1ff9e8ea | 115 | void quitsock(struct socket *sk); |
b2e73d7b | 116 | void socksetdebug(struct socket *sk, int level, char *nm, ...); |
284e199a | 117 | void sockread(struct socket *sk); |
d3372da9 | 118 | |
119 | #endif |