]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_attn.c
Initial revision
[netatalk.git] / libatalk / dsi / dsi_attn.c
1 /*
2  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3  * All rights reserved. See COPYRIGHT.
4  */
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <signal.h>
9 #include <sys/types.h>
10
11 #include <atalk/dsi.h>
12 #include <atalk/afp.h>
13 #include <netatalk/endian.h>
14
15 #ifndef MIN
16 #define MIN(a,b) ((a) < (b) ? (a) : (b))
17 #endif
18
19 /* send an attention. this may get called at any time, so we can't use
20  * DSI buffers to send one. */
21 int dsi_attention(DSI *dsi, AFPUserBytes flags)
22 {
23   /* header + AFPUserBytes */
24   char block[DSI_BLOCKSIZ + sizeof(AFPUserBytes)];
25   sigset_t oldset;
26   u_int32_t len, nlen;
27   u_int16_t id;
28
29   id = htons(dsi_serverID(dsi));
30   flags = htons(flags);
31   len = MIN(sizeof(flags), dsi->attn_quantum);
32   nlen = htonl(len);
33
34   memset(block, 0, sizeof(block));
35   block[0] = DSIFL_REQUEST; /* sending a request */
36   block[1] = DSIFUNC_ATTN;  /* it's an attention */
37   memcpy(block + 2, &id, sizeof(id));
38   /* code = 0 */
39   memcpy(block + 8, &nlen, sizeof(nlen));
40   memcpy(block + 16, &flags, sizeof(flags));
41   /* reserved = 0 */
42
43   /* send an attention */
44   sigprocmask(SIG_BLOCK, &dsi->sigblockset, &oldset);
45   len = dsi_stream_write(dsi, block, DSI_BLOCKSIZ + len);
46   sigprocmask(SIG_SETMASK, &oldset, NULL);
47
48   return len;
49 }