ChangeLog update.
[doldaconnect.git] / daemon / net.h
CommitLineData
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
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;
a8c5ada6 58 struct
59 {
60 uid_t uid;
61 gid_t gid;
62 } ucred;
d3372da9 63 union
64 {
65 struct
66 {
67 struct dgrambuf *f, *l;
68 } d;
69 struct
70 {
71 void *buf;
72 size_t bufsize;
73 size_t datasize;
74 } s;
75 } outbuf;
76 union
77 {
78 struct
79 {
80 struct dgrambuf *f, *l;
81 } d;
82 struct
83 {
84 void *buf;
85 size_t bufsize;
86 size_t datasize;
87 } s;
88 } inbuf;
89 void (*conncb)(struct socket *sk, int err, void *data);
90 void (*errcb)(struct socket *sk, int err, void *data);
91 void (*readcb)(struct socket *sk, void *data);
92 void (*writecb)(struct socket *sk, void *data);
93 void (*acceptcb)(struct socket *sk, struct socket *newsk, void *data);
94 void *data;
95};
96
97void putsock(struct socket *sk);
98void getsock(struct socket *sk);
cab0b442 99struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
100struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
101struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data);
102struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
d3372da9 103int pollsocks(int timeout);
104void sockqueue(struct socket *sk, void *data, size_t size);
105size_t sockqueuesize(struct socket *sk);
106int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data);
107struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen);
108struct socket *netdupsock(struct socket *sk);
109void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen);
110int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
111int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
a88a5873 112int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf);
d3372da9 113void closesock(struct socket *sk);
114void *sockgetinbuf(struct socket *sk, size_t *size);
115struct socket *wrapsock(int fd);
116size_t sockgetdatalen(struct socket *sk);
117int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf);
118int socksettos(struct socket *sk, int tos);
99a28d47 119int addreq(struct sockaddr *x, struct sockaddr *y);
d3372da9 120char *formataddress(struct sockaddr *arg, socklen_t arglen);
336539c2 121void sockpushdata(struct socket *sk, void *buf, size_t size);
d3372da9 122
123#endif