/* * This is sample code generated by rpcgen. * These are only templates and you can use them * as a guideline for developing your own functions. */ #include "prot.h" #include #include #define PROT_MAP_DEBUG static const PortMap *portMaps = 0; static unsigned numMaps = 0; static in_addr_t ipAddr = INADDR_NONE; void setPortMaps(in_addr_t addr, const PortMap *maps, unsigned nMaps) { portMaps = maps; numMaps = nMaps; ipAddr = addr; } bool_t rssib_map_echo_0_svc(void *argp, void *result, struct svc_req *rqstp) { /* PING */ return 1; } bool_t rssib_map_lkup_0_svc(struct MapReq *argp, struct MapReq *result, struct svc_req *rqstp) { int i,j; result->ports.ports_len = 0; result->ports.ports_val = 0; #ifdef PROT_MAP_DEBUG { struct in_addr ina; ina.s_addr = htonl( argp->ipAddr ); printf( "MAP: Lookup request for %s\n", inet_ntoa( ina ) ); } #endif if ( htonl( argp->ipAddr ) == ipAddr ) { result->ipAddr = argp->ipAddr; result->ports.ports_len = argp->ports.ports_len; result->ports.ports_val = mem_alloc( sizeof(result->ports.ports_val[0])*result->ports.ports_len ); if ( ! result->ports.ports_val ) { /* no memory */ return 0; } for ( i=0; iports.ports_len; i++ ) { result->ports.ports_val[i].portNum = 0; #ifdef PROT_MAP_DEBUG printf("Checking requested port %u%s\n", argp->ports.ports_val[i].portNum, argp->ports.ports_val[i].hasRssi ? " (r)" : "" ); #endif for ( j = 0; j < numMaps; j++ ) { if ( portMaps[j].reqPort == argp->ports.ports_val[i].portNum ) { #ifdef PROT_MAP_DEBUG printf("FOUND in slot %u", j); #endif if ( !! argp->ports.ports_val[i].hasRssi == !! (portMaps[j].flags & MAP_PORT_DESC_FLG_RSSI) ) { result->ports.ports_val[i].portNum = portMaps[j].actPort; #ifdef PROT_MAP_DEBUG printf(" rssi MATCH\n"); #endif } #ifdef PROT_MAP_DEBUG else { printf(" rssi MISMATCH\n"); } #endif break; } } } return 1; } return 0; } int rssib_map_0_freeresult (SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) { xdr_free (xdr_result, result); /* * Insert additional freeing code here, if needed */ return 1; }