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