]> arthur.barton.de Git - netatalk.git/blob - libatalk/netddp/netddp_sendto.c
implemented config.h
[netatalk.git] / libatalk / netddp / netddp_sendto.c
1 /* 
2  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
3  * Copyright (c) 1990,1991 Regents of The University of Michigan.
4  * All Rights Reserved. See COPYRIGHT.
5  *
6  * send data.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12
13 static int _netddp_sendto_dummy;
14
15 #ifndef NO_DDP
16 #include <string.h>
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <sys/uio.h>
21 #include <errno.h>
22
23 #ifdef MACOSX_SERVER
24 #include <at/appletalk.h>
25 #include <at/ddp.h>
26 #endif
27
28 #include <netatalk/at.h>
29 #include <netatalk/endian.h>
30 #include <netatalk/ddp.h>
31 #include <atalk/netddp.h>
32
33 #ifndef MAX
34 #define MAX(a, b)  ((a) < (b) ? (b) : (a))
35 #endif
36
37 #ifdef MACOSX_SERVER
38 int netddp_sendto(int fd, void *buf, int buflen, unsigned int dummy, 
39                   const struct sockaddr *addr, unsigned int addrlen)
40 {
41     ssize_t i;
42     struct ddpehdr ddphdr;
43     const struct sockaddr_at *sat = (const struct sockaddr_at *) addr;
44     struct iovec iov[2];
45
46     iov[0].iov_base = (void *) &ddphdr;
47     iov[0].iov_len = sizeof(ddphdr);
48     iov[1].iov_base = buf;
49     iov[1].iov_len = buflen;
50
51     if (!addr)
52       return -1;
53
54     memset(&ddphdr, 0, sizeof(ddphdr));
55     ddphdr.deh_len = htons(sizeof(ddphdr) + buflen);
56     ddphdr.deh_dnet = sat->sat_addr.s_net;
57     ddphdr.deh_dnode = sat->sat_addr.s_node;
58     ddphdr.deh_dport = sat->sat_port;
59     while ((i = writev(fd, iov, 2)) < 0) {
60       if (errno != EINTR)
61         return -1;
62     }
63
64     return MAX(0, i - sizeof(ddphdr));
65 }
66
67 #endif /* os x server */
68 #endif /* no ddp */