/* * Please do not edit this file. * It was generated using rpcgen. */ #include "prot.h" #include #include #include #include #include #include #include #include #include #include #include #include #include static int probe(struct sockaddr_in *mcsa, int quiet) { CLIENT *clnt = 0; struct timeval tout; int stat; const char *srvr = "127.0.0.1"; struct sockaddr_in srva; struct McAddr mca; int sd; int rval = -1; srva.sin_family = AF_INET; srva.sin_addr.s_addr = inet_addr( srvr ); srva.sin_port = htons( RELAY_SERVER_PORT ); sd = RPC_ANYSOCK; if ( ! (clnt = clnttcp_create( &srva, RSSIB_REL, RSSIB_REL_V0, &sd, 0, 0 )) ) { if ( ! quiet ) { clnt_pcreateerror( srvr ); fprintf(stderr,"ERROR: unable to create MAP client\n"); } goto bail; } tout.tv_sec = 1; tout.tv_usec = 0; stat = clnt_call( clnt, RSSIB_REL_GETMCPORT, (xdrproc_t)xdr_void, (caddr_t)0, (xdrproc_t)xdr_McAddr , (caddr_t)&mca, tout ); if ( RPC_SUCCESS != stat ) { clnt_perrno(stat); fprintf(stderr,"ERROR: RPC RSSIB_REL_GETMCPORT failed\n"); goto bail; } if ( mcsa ) { mcsa->sin_family = AF_INET; mcsa->sin_port = htons( mca.portno ); mcsa->sin_addr.s_addr = htonl( mca.ipaddr ); } #ifdef PROT_MAP_DEBUG printf("Remote port for multicast: %hu\n", mca.portno); printf("Remote addr for multicast: %s\n", inet_ntoa( htonl( mca.ipaddr ) )); #endif if ( ! clnt_freeres( clnt, (xdrproc_t)xdr_McAddr, (caddr_t)&mca ) ) { fprintf(stderr, "ERROR: unable to free results!\n"); goto bail; } rval = 0; bail: if ( clnt ) { clnt_destroy( clnt ); } return rval; } int rpcProbeRelay(struct sockaddr_in *mcsa) { pid_t relay; pid_t parent; sigset_t mask, omask; int got; if ( probe( mcsa, 1 ) ) { fprintf(stderr,"No RELAY seems to be running!; try to start one...\n"); sigemptyset( &mask ); sigaddset ( &mask, SIGUSR1 ); sigprocmask( SIG_BLOCK, &mask, &omask ); parent = getpid(); relay = daemonize(); if ( (pid_t)0 == relay ) { /* daemon child */ SVCXPRT *relsvc; sigprocmask( SIG_SETMASK, &omask, 0 ); openlog( "RSSIB Relay", LOG_CONS, LOG_DAEMON ); syslog( LOG_ERR, "Relay starting up\n"); printErrMsgTo( PRINT_ERR_MSG_SYSLOG ); relsvc = protRelay(); /* let the parent know */ kill( parent, SIGUSR1 ); if ( relsvc ) { svc_run(); } /* This exits the daemon child */ exit(1); } sigwait( &mask, &got ); sigprocmask( SIG_SETMASK, &omask, 0 ); fprintf( stderr,"Relay started; PID: %lu\n", (unsigned long) relay ); if ( probe( mcsa, 0 ) ) { fprintf(stderr,"Second attempt to probe RELAY failed\n"); return 1; } } return 0; }