]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_opensess.c
e33d1d78490ba5a7f0eaaf872db2e7313340fd88
[netatalk.git] / libatalk / dsi / dsi_opensess.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 <sys/types.h>
13
14 #include <atalk/dsi.h>
15
16 /* OpenSession. set up the connection */
17 void dsi_opensession(DSI *dsi)
18 {
19   u_int32_t i = 0; /* this serves double duty. it must be 4-bytes long */
20
21   /* parse options */
22   while (i < dsi->cmdlen) {
23     switch (dsi->commands[i++]) {
24     case DSIOPT_ATTNQUANT:
25       memcpy(&dsi->attn_quantum, dsi->commands + i + 1, dsi->commands[i]);
26       dsi->attn_quantum = ntohl(dsi->attn_quantum);
27
28     case DSIOPT_SERVQUANT: /* just ignore these */
29     default:
30       i += dsi->commands[i] + 1; /* forward past length tag + length */
31       break;
32     }
33   }
34
35   /* let the client know the server quantum. we don't use the
36    * max server quantum due to a bug in appleshare client 3.8.6. */
37   dsi->header.dsi_flags = DSIFL_REPLY;
38   /* dsi->header.dsi_command = DSIFUNC_OPEN;*/
39   dsi->cmdlen = 2 + sizeof(i); /* length of data. dsi_send uses it. */
40   dsi->commands[0] = DSIOPT_SERVQUANT;
41   dsi->commands[1] = sizeof(i);
42   i = htonl(( dsi->server_quantum < DSI_SERVQUANT_MIN || 
43               dsi->server_quantum > DSI_SERVQUANT_MAX ) ? 
44             DSI_SERVQUANT_DEF : dsi->server_quantum);
45   memcpy(dsi->commands + 2, &i, sizeof(i));
46
47   dsi_send(dsi);
48 }