Add version-info to libdcui.
[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>
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
33struct dgrambuf
34{
35 struct dgrambuf *next;
36 struct sockaddr *addr;
37 socklen_t addrlen;
38 void *data;
39 size_t size;
40};
41
42struct 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
91void putsock(struct socket *sk);
92void getsock(struct socket *sk);
cab0b442 93struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
94struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
95struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data);
96struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
d3372da9 97int pollsocks(int timeout);
98void sockqueue(struct socket *sk, void *data, size_t size);
99size_t sockqueuesize(struct socket *sk);
100int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data);
101struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen);
102struct socket *netdupsock(struct socket *sk);
103void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen);
104int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
105int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf);
a88a5873 106int sockgetremotename2(struct socket *sk, struct socket *sk2, struct sockaddr **namebuf, socklen_t *lenbuf);
d3372da9 107void closesock(struct socket *sk);
108void *sockgetinbuf(struct socket *sk, size_t *size);
109struct socket *wrapsock(int fd);
110size_t sockgetdatalen(struct socket *sk);
111int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf);
112int socksettos(struct socket *sk, int tos);
99a28d47 113int addreq(struct sockaddr *x, struct sockaddr *y);
d3372da9 114char *formataddress(struct sockaddr *arg, socklen_t arglen);
336539c2 115void sockpushdata(struct socket *sk, void *buf, size_t size);
d3372da9 116
117#endif