| 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 */ |
| 28 | #define SOCK_TOS_MINDELAY 4 |
| 29 | #define SOCK_TOS_MAXTP 3 |
| 30 | #define SOCK_TOS_MAXREL 2 |
| 31 | #define SOCK_TOS_MINCOST 1 |
| 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 *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data); |
| 96 | struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data); |
| 97 | int pollsocks(int timeout); |
| 98 | void sockqueue(struct socket *sk, void *data, size_t size); |
| 99 | size_t sockqueuesize(struct socket *sk); |
| 100 | int netresolve(char *addr, void (*callback)(struct sockaddr *addr, int addrlen, void *data), void *data); |
| 101 | struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen); |
| 102 | struct socket *netdupsock(struct socket *sk); |
| 103 | void netdgramconn(struct socket *sk, struct sockaddr *addr, socklen_t addrlen); |
| 104 | int sockgetlocalname(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); |
| 105 | int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *lenbuf); |
| 106 | void closesock(struct socket *sk); |
| 107 | void *sockgetinbuf(struct socket *sk, size_t *size); |
| 108 | struct socket *wrapsock(int fd); |
| 109 | size_t sockgetdatalen(struct socket *sk); |
| 110 | int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf); |
| 111 | int socksettos(struct socket *sk, int tos); |
| 112 | int addreq(struct sockaddr *x, struct sockaddr *y); |
| 113 | char *formataddress(struct sockaddr *arg, socklen_t arglen); |
| 114 | void sockpushdata(struct socket *sk, void *buf, size_t size); |
| 115 | |
| 116 | #endif |