]> arthur.barton.de Git - netatalk.git/blob - libatalk/asp/asp_attn.c
Initial revision
[netatalk.git] / libatalk / asp / asp_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 <syslog.h>
9 #include <sys/types.h>
10 #include <sys/uio.h>
11
12 #include <atalk/atp.h>
13 #include <atalk/asp.h>
14 #include <atalk/afp.h>
15
16 /* attentions can get sent at any time. as a consequence, we don't
17  * want to touch anything that might be used elsewhere. */
18 int asp_attention(ASP asp, AFPUserBytes flags)
19 {
20     char cmds[ASP_HDRSIZ], data[ASP_HDRSIZ];
21     struct sockaddr_at  sat;
22     struct atp_block    atpb;
23     struct iovec        iov[ 1 ];
24
25     cmds[0] = ASPFUNC_ATTN;
26     cmds[1] = asp->asp_sid;
27     flags = htons(flags);
28     memcpy(cmds + 2, &flags, sizeof(flags));
29
30     sat = asp->asp_sat;
31     sat.sat_port = asp->asp_wss;
32     atpb.atp_saddr = &sat;
33     atpb.atp_sreqdata = cmds;
34     atpb.atp_sreqdlen = sizeof(cmds);
35     atpb.atp_sreqto = 2;
36     atpb.atp_sreqtries = 5;
37
38     if ( atp_sreq( asp->asp_atp, &atpb, 1, 0 ) < 0 ) {
39         syslog( LOG_ERR, "atp_sreq: %m" );
40         return -1;
41     }
42
43     iov[ 0 ].iov_base = data;
44     iov[ 0 ].iov_len = sizeof( data );
45     atpb.atp_rresiov = iov;
46     atpb.atp_rresiovcnt = sizeof( iov )/sizeof( iov[ 0 ] );
47     if ( atp_rresp( asp->asp_atp, &atpb ) < 0 ) {
48         syslog( LOG_ERR, "atp_rresp: %m" );
49         return -1;
50     }
51
52     return 0;
53 }