Try to hide join/leave messages.
[doldaconnect.git] / daemon / net.h
CommitLineData
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>
9e5f2b29 23#include <sys/un.h>
d3372da9 24
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 */
e6252feb 29#define SOCK_TOS_MINDELAY 4
30#define SOCK_TOS_MAXTP 3
31#define SOCK_TOS_MAXREL 2
32#define SOCK_TOS_MINCOST 1
d3372da9 33
34struct dgrambuf
35{
36 struct dgrambuf *next;
37 struct sockaddr *addr;
38 socklen_t addrlen;
39 void *data;
40 size_t size;
41};
42
43struct socket
44{
45 struct socket *next, *prev;
46 int refcount;
47 int fd;
48 int isrealsocket; /* Bleh... */
49 int family;
50 int tos;
51 int type;
52 int state;
53 int ignread;
54 int events;
55 int close;
56 struct sockaddr *remote;
57 socklen_t remotelen;
9e5f2b29 58 struct ucred ucred;
d3372da9 59 union
60 {
61 struct
62 {
63 struct dgrambuf *f, *l;
64 } d;
65 struct
66 {
67 void *buf;
68 size_t bufsize;
69 size_t datasize;
70 } s;
71 } outbuf;
72 union
73 {
74 struct
75 {
76 struct dgrambuf *f, *l;
77 } d;
78 struct
79 {
80 void *buf;
81 size_t bufsize;
82 size_t datasize;
83 } s;
84 } inbuf;
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);
90 void *data;
91};
92
93void putsock(struct socket *sk);
94void getsock(struct socket *sk);
cab0b442 95struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
96struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
97struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data);
98struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
d3372da9 99int pollsocks(int timeout);
100void sockqueue(struct socket *sk, void *data, size_t size);
101size_t sockqueuesize(struct socket *sk);
102int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data);
103struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen);
104struct socket *netdupsock(struct socket *sk);
105void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen);
106int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
107int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
a88a5873 108int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf);
d3372da9 109void closesock(struct socket *sk);
110void *sockgetinbuf(struct socket *sk, size_t *size);
111struct socket *wrapsock(int fd);
112size_t sockgetdatalen(struct socket *sk);
113int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf);
114int socksettos(struct socket *sk, int tos);
99a28d47 115int addreq(struct sockaddr *x, struct sockaddr *y);
d3372da9 116char *formataddress(struct sockaddr *arg, socklen_t arglen);
336539c2 117void sockpushdata(struct socket *sk, void *buf, size_t size);
d3372da9 118
119#endif