]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_attn.c
fce: afpd: fix event names array
[netatalk.git] / libatalk / dsi / dsi_attn.c
1 /*
2  *
3  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
4  * All rights reserved. See COPYRIGHT.
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif /* HAVE_CONFIG_H */
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <arpa/inet.h>
16
17 #include <atalk/dsi.h>
18 #include <atalk/afp.h>
19
20 #ifndef MIN
21 #define MIN(a,b) ((a) < (b) ? (a) : (b))
22 #endif /* MIN */
23
24 /* send an attention. this may get called at any time, so we can't use
25  * DSI buffers to send one. 
26    return 0 on error
27  
28  */
29 int dsi_attention(DSI *dsi, AFPUserBytes flags)
30 {
31   /* header + AFPUserBytes */
32   char block[DSI_BLOCKSIZ + sizeof(AFPUserBytes)];
33   uint32_t len, nlen;
34   uint16_t id;
35
36   if (dsi->flags & DSI_SLEEPING)
37       return 1;
38
39   if (dsi->in_write) {
40       return -1;
41   }      
42   id = htons(dsi_serverID(dsi));
43   flags = htons(flags);
44   len = MIN(sizeof(flags), dsi->attn_quantum);
45   nlen = htonl(len);
46
47   memset(block, 0, sizeof(block));
48   block[0] = DSIFL_REQUEST; /* sending a request */
49   block[1] = DSIFUNC_ATTN;  /* it's an attention */
50   memcpy(block + 2, &id, sizeof(id));
51   /* code = 0 */
52   memcpy(block + 8, &nlen, sizeof(nlen));
53   memcpy(block + 16, &flags, sizeof(flags));
54   /* reserved = 0 */
55
56   /* send an attention */
57   return dsi_stream_write(dsi, block, DSI_BLOCKSIZ + len, DSI_NOWAIT);
58 }