1 /* moved over from bin/pap/pap.c */
13 static void tickle_handler()
15 if (client.tickle++ < 4)
16 pap_tickle(client.pap, client.pap->pap_connid, &client.pap->pap_sat);
18 kill(client.pid, SIGTERM);
19 syslog(LOG_ERR, "pap_alarm: connection timed out.");
25 PAP pap_open(PAP pap, struct nbpnve *nn, u_int8_t quantum, int flags)
27 struct atp_block atpb;
28 struct timeval stv, tv;
33 pap->pap_connid = getpid() & 0xff;
34 pap->cmdbuf[ 0 ] = pap->pap_connid;
35 pap->cmdbuf[ 1 ] = PAP_OPEN;
36 pap->cmdbuf[ 2 ] = pap->cmdbuf[ 3 ] = 0;
37 pap->cmdbuf[ 4 ] = atp_sockaddr( pap->pap_atp )->sat_port;
38 pap->cmdbuf[ 5 ] = quantum; /* flow quantum */
40 if ( gettimeofday( &stv, NULL ) < 0 ) {
41 perror( "gettimeofday" );
46 if ( flags & PAPFLAG_CUTS ) {
49 if ( gettimeofday( &tv, NULL ) < 0 ) {
50 perror( "gettimeofday" );
53 waiting = htons( tv.tv_sec - stv.tv_sec );
56 memcpy(pap->cmdbuf + 6, &waiting, sizeof( waiting ));
57 atpb.atp_saddr = &nn->nn_sat;
58 atpb.atp_sreqdata = pap->cmdbuf;
59 atpb.atp_sreqdlen = 8; /* bytes in OpenConn request */
60 atpb.atp_sreqto = 2; /* retry timer */
61 atpb.atp_sreqtries = 5; /* retry count */
62 if ( atp_sreq( atp, &atpb, 1, ATP_XO ) < 0 ) {
67 iov.iov_base = pap->data;
68 iov.iov_len = sizeof( rbuf );
69 atpb.atp_rresiov = &iov;
70 atpb.atp_rresiovcnt = 1;
71 if ( atp_rresp( atp, &atpb ) < 0 ) {
72 perror( "atp_rresp" );
73 if ( connattempts-- <= 0 ) {
74 fprintf( stderr, "Can't connect!\n" );
81 if ( iov.iov_len < 8 || pap->data[ 0 ] != pap->pap_connid ||
82 pap->data[ 1 ] != PAP_OPENREPLY ) {
83 fprintf( stderr, "Bad response!\n" );
84 continue; /* This is weird, since TIDs must match... */
88 printf( "%.*s\n", iov.iov_len - 9, iov.iov_base + 9 );
90 updatestatus( iov.iov_base + 9, iov.iov_len - 9 );
92 bcopy( &rbuf[ 6 ], &result, sizeof( result ));
96 memcpy(&pap->pap_sat, &nn.nn_sat, sizeof( struct sockaddr_at ));
97 pap->pap_sat.sat_port = rbuf[ 4 ];
98 pap->pap_quantum = rbuf[ 5 ];
104 printf( "Connected to %.*s:%.*s@%.*s.\n",
105 nn.nn_objlen, nn.nn_obj,
106 nn.nn_typelen, nn.nn_type,
107 nn.nn_zonelen, nn.nn_zone );
110 /* open a second atp connection */
111 if (( atp = atp_open( 0 )) == NULL ) {
112 perror( "atp_open" );
121 /* wait around for tickles */