]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/socket.h
2 * BIRD Socket Interface
4 * (c) 1998--1999 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
9 #ifndef _BIRD_SOCKET_H_
10 #define _BIRD_SOCKET_H_
12 #include "lib/resource.h"
14 typedef struct birdsock
{
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 */
25 byte
*rbuf
, *rpos
; /* NULL=allocate automatically */
27 int (*rx_hook
)(struct birdsock
*, int size
); /* NULL=receiving turned off, returns 1 to clear rx buffer */
29 byte
*tbuf
, *tpos
; /* NULL=allocate automatically */
30 byte
*ttx
; /* Internal */
32 void (*tx_hook
)(struct birdsock
*);
34 void (*err_hook
)(struct birdsock
*, int); /* errno or zero if EOF */
36 ip_addr faddr
; /* For packet protocols: source of current packet */
39 int fd
; /* System-dependent data */
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);
50 sk_send_buffer_empty(sock
*sk
)
52 return sk
->tbuf
== sk
->tpos
;
56 * Socket types SA SP DA DP IF TTL SendTo (?=may, -=must not, *=must)
59 #define SK_TCP_PASSIVE 0 /* ? * - - - ? - */
60 #define SK_TCP_ACTIVE 1 /* ? ? * * - ? - */
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 */
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.