Imported Upstream version 2.5.1
[debian/amanda] / common-src / dgram.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1999 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: James da Silva, Systems Design and Analysis Group
24  *                         Computer Science Department
25  *                         University of Maryland at College Park
26  */
27 /*
28  * $Id: dgram.h,v 1.15 2006/05/25 01:47:11 johnfranks Exp $
29  *
30  * interface for datagram module
31  */
32 #ifndef DGRAM_H
33 #define DGRAM_H
34
35 #include "amanda.h"
36
37 /*
38  * Maximum datagram (UDP packet) we can generate.  Size is limited by
39  * a 16 bit length field in an IPv4 header (65535), which must include
40  * the 24 byte IP header and the 8 byte UDP header.
41  */
42 #define MAX_DGRAM      (((1<<16)-1)-24-8)
43
44 typedef struct dgram_s {
45     char *cur;
46     int socket;
47     size_t len;
48     char data[MAX_DGRAM+1];
49 } dgram_t;
50
51 int     dgram_bind(dgram_t *dgram, in_port_t *portp);
52 void    dgram_socket(dgram_t *dgram, int sock);
53 int     dgram_send(char *hostname, in_port_t port, dgram_t *dgram);
54 int     dgram_send_addr(struct sockaddr_in addr, dgram_t *dgram);
55 ssize_t dgram_recv(dgram_t *dgram, int timeout, struct sockaddr_in *fromaddr);
56 void    dgram_zero(dgram_t *dgram);
57 int     dgram_cat(dgram_t *dgram, const char *fmt, ...)
58     __attribute__ ((format (printf, 2, 3)));
59 void dgram_eatline(dgram_t *dgram);
60
61 #endif /* ! DGRAM_H */