]> git.ipfire.org Git - thirdparty/bird.git/blob - lib/socket.h
Added sk_send_buffer_empty().
[thirdparty/bird.git] / lib / socket.h
1 /*
2 * BIRD Socket Interface
3 *
4 * (c) 1998--1999 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #ifndef _BIRD_SOCKET_H_
10 #define _BIRD_SOCKET_H_
11
12 #include "lib/resource.h"
13
14 typedef struct birdsock {
15 resource r;
16 pool *pool; /* Pool for socket data */
17 int type; /* Socket type */
18 void *data; /* User data */
19 ip_addr saddr, daddr; /* IPA_NONE = unspecified */
20 unsigned sport, dport; /* 0 = unspecified (for IP: protocol type) */
21 int tos; /* TOS and priority, -1 = default */
22 int ttl; /* Time To Live, -1 = default */
23 struct iface *iface; /* Interface; specify this for broad/multicast sockets */
24
25 byte *rbuf, *rpos; /* NULL=allocate automatically */
26 unsigned rbsize;
27 int (*rx_hook)(struct birdsock *, int size); /* NULL=receiving turned off, returns 1 to clear rx buffer */
28
29 byte *tbuf, *tpos; /* NULL=allocate automatically */
30 byte *ttx; /* Internal */
31 unsigned tbsize;
32 void (*tx_hook)(struct birdsock *);
33
34 void (*err_hook)(struct birdsock *, int); /* errno or zero if EOF */
35
36 ip_addr faddr; /* For packet protocols: source of current packet */
37 unsigned fport;
38
39 int fd; /* System-dependent data */
40 node n;
41 } sock;
42
43 sock *sk_new(pool *); /* Allocate new socket */
44 int sk_open(sock *); /* Open socket */
45 int sk_send(sock *, unsigned len); /* Send data, <0=err, >0=ok, 0=sleep */
46 int sk_send_to(sock *, unsigned len, ip_addr to, unsigned port); /* sk_send to given destination */
47 void sk_dump_all(void);
48
49 static inline int
50 sk_send_buffer_empty(sock *sk)
51 {
52 return sk->tbuf == sk->tpos;
53 }
54
55 /*
56 * Socket types SA SP DA DP IF TTL SendTo (?=may, -=must not, *=must)
57 */
58
59 #define SK_TCP_PASSIVE 0 /* ? * - - - ? - */
60 #define SK_TCP_ACTIVE 1 /* ? ? * * - ? - */
61 #define SK_TCP 2
62 #define SK_UDP 3 /* ? ? - - - ? ? */
63 #define SK_UDP_MC 4 /* ? ? * * * * - */
64 #define SK_IP 5 /* ? - - * - ? ? */
65 #define SK_IP_MC 6 /* ? - * * * * - */
66 #define SK_MAGIC 7 /* Internal use by sysdep code */
67
68 /*
69 * Multicast sockets are slightly different from the other ones:
70 * If you want to send packets only, just set the destination
71 * address to the corresponding multicast group and iface to
72 * the interface to be used. If you also want receiving, set
73 * source address to the same multicast group as well.
74 */
75
76 #endif