]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/socket.h
2 * BIRD Socket Interface
4 * (c) 1998--2004 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 where incoming connections should be allocated (for SK_xxx_PASSIVE) */
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 */
24 struct iface
*iface
; /* Interface; specify this for broad/multicast sockets */
26 byte
*rbuf
, *rpos
; /* NULL=allocate automatically */
28 int (*rx_hook
)(struct birdsock
*, int size
); /* NULL=receiving turned off, returns 1 to clear rx buffer */
30 byte
*tbuf
, *tpos
; /* NULL=allocate automatically */
31 byte
*ttx
; /* Internal */
33 void (*tx_hook
)(struct birdsock
*);
35 void (*err_hook
)(struct birdsock
*, int); /* errno or zero if EOF */
37 ip_addr faddr
; /* For packet protocols: source of current packet */
40 int fd
; /* System-dependent data */
42 void *rbuf_alloc
, *tbuf_alloc
;
43 char *password
; /* Password for MD5 authentication */
46 sock
*sk_new(pool
*); /* Allocate new socket */
47 int sk_open(sock
*); /* Open socket */
48 int sk_send(sock
*, unsigned len
); /* Send data, <0=err, >0=ok, 0=sleep */
49 int sk_send_to(sock
*, unsigned len
, ip_addr to
, unsigned port
); /* sk_send to given destination */
50 void sk_reallocate(sock
*); /* Free and allocate tbuf & rbuf */
51 void sk_dump_all(void);
52 int sk_set_ttl(sock
*s
, int ttl
); /* Set TTL for given socket */
53 int sk_set_md5_auth(sock
*s
, ip_addr a
, char *passwd
); /* Add or remove security associations for given passive socket */
56 sk_send_buffer_empty(sock
*sk
)
58 return sk
->tbuf
== sk
->tpos
;
64 #define SKF_V6ONLY 1 /* Use IPV6_V6ONLY socket option */
68 * Socket types SA SP DA DP IF TTL SendTo (?=may, -=must not, *=must)
71 #define SK_TCP_PASSIVE 0 /* ? * - - - ? - */
72 #define SK_TCP_ACTIVE 1 /* ? ? * * - ? - */
74 #define SK_UDP 3 /* ? ? - - - ? ? */
75 #define SK_UDP_MC 4 /* ? ? * * * * - */
76 #define SK_IP 5 /* ? - - * - ? ? */
77 #define SK_IP_MC 6 /* ? - * * * * - */
78 #define SK_MAGIC 7 /* Internal use by sysdep code */
79 #define SK_UNIX_PASSIVE 8
83 * Multicast sockets are slightly different from the other ones:
84 * If you want to send packets only, just set the destination
85 * address to the corresponding multicast group and iface to
86 * the interface to be used. If you also want receiving, set
87 * source address to the same multicast group as well.