• 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_open.c,v 1.5 2001-08-15 02:17:57 srittau 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 <sys/param.h>
35#include <sys/socket.h>
36
37#include <netatalk/at.h>
38#include <netatalk/endian.h>
39
40#include <atalk/netddp.h>
41#include <atalk/ddp.h>
42#include <atalk/atp.h>
43
44#include "atp_internals.h"
45
46ATP atp_open(u_int8_t port, const struct at_addr *saddr)
47{
48    struct sockaddr_at  addr;
49    int			s;
50    ATP			atp;
51    struct timeval	tv;
52    int			pid;
53
54#ifdef DEBUG
55    printf( "<%d> atp_open\n", getpid());
56#endif /* DEBUG */
57
58    memset(&addr, 0, sizeof(addr));
59    addr.sat_port = port;
60    if (saddr)
61      memcpy(&addr.sat_addr, saddr, sizeof(struct at_addr));
62    if ((s = netddp_open(&addr, NULL)) < 0)
63        return NULL;
64
65    if (( atp = (ATP) atp_alloc_buf()) == NULL ) {
66        netddp_close(s);
67	return NULL;
68    }
69
70    /* initialize the atp handle */
71    memset(atp, 0, sizeof( struct atp_handle ));
72    memcpy(&atp->atph_saddr, &addr, sizeof(addr));
73
74    atp->atph_socket = s;
75    atp->atph_reqto = -1;
76    gettimeofday( &tv, (struct timezone *) 0 );
77    pid = getpid();
78    atp->atph_tid = tv.tv_sec ^ ((( pid << 8 ) & 0xff00 ) | ( pid >> 8 ));
79
80#ifdef EBUG
81srandom( tv.tv_sec );
82#endif /* EBUG */
83
84    return atp;
85}
86