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