1 /* moved over from bin/pap/pap.c */
9 static void tickle_handler()
11 if (client.tickle++ < 4)
12 pap_tickle(client.pap, client.pap->pap_connid, &client.pap->pap_sat);
14 kill(client.pid, SIGTERM);
15 syslog(LOG_ERR, "pap_alarm: connection timed out.");
21 PAP pap_open(PAP pap, struct nbpnve *nn, u_int8_t quantum, int flags)
23 struct atp_block atpb;
24 struct timeval stv, tv;
29 pap->pap_connid = getpid() & 0xff;
30 pap->cmdbuf[ 0 ] = pap->pap_connid;
31 pap->cmdbuf[ 1 ] = PAP_OPEN;
32 pap->cmdbuf[ 2 ] = pap->cmdbuf[ 3 ] = 0;
33 pap->cmdbuf[ 4 ] = atp_sockaddr( pap->pap_atp )->sat_port;
34 pap->cmdbuf[ 5 ] = quantum; /* flow quantum */
36 if ( gettimeofday( &stv, NULL ) < 0 ) {
37 perror( "gettimeofday" );
42 if ( flags & PAPFLAG_CUTS ) {
45 if ( gettimeofday( &tv, NULL ) < 0 ) {
46 perror( "gettimeofday" );
49 waiting = htons( tv.tv_sec - stv.tv_sec );
52 memcpy(pap->cmdbuf + 6, &waiting, sizeof( waiting ));
53 atpb.atp_saddr = &nn->nn_sat;
54 atpb.atp_sreqdata = pap->cmdbuf;
55 atpb.atp_sreqdlen = 8; /* bytes in OpenConn request */
56 atpb.atp_sreqto = 2; /* retry timer */
57 atpb.atp_sreqtries = 5; /* retry count */
58 if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
63 iov.iov_base = pap->data;
64 iov.iov_len = sizeof( rbuf );
65 atpb.atp_rresiov = &iov;
66 atpb.atp_rresiovcnt = 1;
67 if ( atp_rresp( atp, &atpb ) < 0 ) {
68 perror( "atp_rresp" );
69 if ( connattempts-- <= 0 ) {
70 fprintf( stderr, "Can't connect!\n" );
77 if ( iov.iov_len < 8 || pap->data[ 0 ] != pap->pap_connid ||
78 pap->data[ 1 ] != PAP_OPENREPLY ) {
79 fprintf( stderr, "Bad response!\n" );
80 continue; /* This is weird, since TIDs must match... */
84 printf( "%.*s\n", iov.iov_len - 9, iov.iov_base + 9 );
86 updatestatus( iov.iov_base + 9, iov.iov_len - 9 );
88 bcopy( &rbuf[ 6 ], &result, sizeof( result ));
92 memcpy(&pap->pap_sat, &nn.nn_sat, sizeof( struct sockaddr_at ));
93 pap->pap_sat.sat_port = rbuf[ 4 ];
94 pap->pap_quantum = rbuf[ 5 ];
100 printf( "Connected to %.*s:%.*s@%.*s.\n",
101 nn.nn_objlen, nn.nn_obj,
102 nn.nn_typelen, nn.nn_type,
103 nn.nn_zonelen, nn.nn_zone );
106 /* open a second atp connection */
107 if (( atp = atp_open( 0 )) == NULL ) {
108 perror( "atp_open" );
117 /* wait around for tickles */