• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/netatalk-2.2.0/libatalk/atp/
1/*
2 * $Id: atp_rresp.c,v 1.6 2009-10-13 22:55:37 didg Exp $
3 *
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
16 *
17 *	Research Systems Unix Group
18 *	The University of Michigan
19 *	c/o Mike Clark
20 *	535 W. William Street
21 *	Ann Arbor, Michigan
22 *	+1-313-763-0525
23 *	netatalk@itd.umich.edu
24 */
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif /* HAVE_CONFIG_H */
29
30#include <stdlib.h>
31#include <string.h>
32#include <sys/types.h>
33#include <sys/time.h>
34#include <errno.h>
35#include <sys/uio.h>
36#include <sys/socket.h>
37
38#include <netatalk/at.h>
39#include <atalk/atp.h>
40#include <atalk/util.h>
41
42#ifdef EBUG
43#include <stdio.h>
44#endif /* EBUG */
45
46#include "atp_internals.h"
47
48int
49atp_rresp(
50    ATP			ah,		/* open atp handle */
51    struct atp_block	*atpb)		/* parameter block */
52{
53    int		i, rc;
54    size_t	len;
55
56#ifdef EBUG
57    atp_print_bufuse( ah, "atp_rresp" );
58#endif /* EBUG */
59    /* check parameters
60    */
61    if ( atpb->atp_rresiovcnt <= 0 || atpb->atp_rresiovcnt > 8 ) {
62	errno = EINVAL;
63	return( -1 );
64    }
65
66    while (( rc = atp_rsel( ah, atpb->atp_saddr, ATP_TRESP )) == 0 ) {
67	;
68    }
69
70    if ( rc != ATP_TRESP ) {
71	return( rc );
72    }
73
74    for ( i = 0; i < 8; ++i ) {
75	if ( ah->atph_resppkt[ i ] == NULL ) {
76	    break;
77	}
78	len = ah->atph_resppkt[ i ]->atpbuf_dlen - ATP_HDRSIZE;
79	if ( i > atpb->atp_rresiovcnt - 1 ||
80		len > atpb->atp_rresiov[ i ].iov_len ) {
81	    errno = EMSGSIZE;
82	    return( -1 );
83	}
84#ifdef EBUG
85	fprintf( stderr, "atp_rresp copying %ld bytes packet %d\n",
86		len, i );
87	bprint( (char *)ah->atph_resppkt[ i ]->atpbuf_info.atpbuf_data,
88		len + ATP_HDRSIZE );
89#endif /* EBUG */
90	memcpy(atpb->atp_rresiov[ i ].iov_base,
91	       ah->atph_resppkt[ i ]->atpbuf_info.atpbuf_data + ATP_HDRSIZE,
92	       len );
93	atpb->atp_rresiov[ i ].iov_len = len;
94	atp_free_buf( ah->atph_resppkt[ i ] );
95	ah->atph_resppkt[ i ] = NULL;
96    }
97    atpb->atp_rresiovcnt = i;
98
99    return( 0 );
100}
101