]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_open.c
implemented config.h
[netatalk.git] / libatalk / atp / atp_open.c
1 /*
2  * Copyright (c) 1990,1991 Regents of The University of Michigan.
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation, and that the name of The University
10  * of Michigan not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. This software is supplied as is without expressed or
13  * implied warranties of any kind.
14  *
15  *      Research Systems Unix Group
16  *      The University of Michigan
17  *      c/o Mike Clark
18  *      535 W. William Street
19  *      Ann Arbor, Michigan
20  *      +1-313-763-0525
21  *      netatalk@itd.umich.edu
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <sys/param.h>
33
34 #include <netatalk/at.h>
35 #include <netatalk/endian.h>
36
37 #include <atalk/netddp.h>
38 #include <atalk/ddp.h>
39 #include <atalk/atp.h>
40
41 #include "atp_internals.h"
42
43 ATP atp_open(port, saddr)
44     u_int8_t port;
45     const struct at_addr *saddr;
46 {
47     struct sockaddr_at  addr;
48     int                 s;
49     ATP                 atp;
50     struct timeval      tv;
51     int                 pid;
52
53 #ifdef EBUG
54     printf( "<%d> atp_open\n", getpid());
55 #endif
56
57     memset(&addr, 0, sizeof(addr));
58     addr.sat_port = port;
59     if (saddr) 
60       memcpy(&addr.sat_addr, saddr, sizeof(struct at_addr));
61     if ((s = netddp_open(&addr, NULL)) < 0)
62         return NULL;
63
64     if (( atp = (ATP) atp_alloc_buf()) == NULL ) {
65         netddp_close(s);
66         return NULL;
67     }
68
69     /* initialize the atp handle */
70     memset(atp, 0, sizeof( struct atp_handle ));
71     memcpy(&atp->atph_saddr, &addr, sizeof(addr));
72
73     atp->atph_socket = s;
74     atp->atph_reqto = -1;
75     gettimeofday( &tv, (struct timezone *) 0 );
76     pid = getpid();
77     atp->atph_tid = tv.tv_sec ^ ((( pid << 8 ) & 0xff00 ) | ( pid >> 8 ));
78
79 #ifdef EBUG
80 srandom( tv.tv_sec );
81 #endif
82
83     return atp;
84 }