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