#include "services.h" /* Name: initservices() * * Description: This routine allocates space for the head and tail of the * `services' structure that is used to store information about the network * services that are available */ void initservices(void) { shead = (services *) malloc(sizeof(services)); sprintf(shead->svcname,"%s","AAAA"); sprintf(shead->type,"%s","AAAA"); sprintf(shead->port,"%s","AAAA"); stail = (services *) malloc(sizeof(services)); sprintf(stail->svcname,"%s","ZZZZ"); sprintf(shead->type,"%s","ZZZZ"); sprintf(shead->port,"%s","ZZZZ"); stail->nodelink = NULL; shead->nodelink = stail; shead->svccount = -1; stail->svccount = MAXSVCS; } /* * Name: dump_svc() * * Description: * This routine can be used to print out the entire list of * services. Some services are actually groups, that contain * a list of services. It will print those as well. */ void dump_svc(int verbose) { /* loop counter to find groups of service names */ int i=0; /* Print a fancy header */ printf("%15s%10s%30s%30s\n","Service","Service","Service","Port"); printf("%15s%10s%30s%30s\n\n","Num","Type","Name","Num"); /* start at the head of the list */ sprev = shead->nodelink; /* continue until with have parsed the whole list */ while(sprev->nodelink != NULL) { /* more complicated to print groups of services. Requires find_services() */ if(strcmp(sprev->type,"group") == 0) { i=0; /*printf("%3d%7s%27s\n",sprev->svccount,sprev->type,sprev->svcname);*/ printf("%15d%30s%30s\n",sprev->svccount,sprev->type,sprev->svcname); while(sprev->group[i] != NULL) { find_services(sprev->group[i]); printf("\n"); i++; } } else /* if its not a 'group' of services, just print out the common * information */ /*printf("%3d%7s%27s%16s\n",sprev->svccount,sprev->type,sprev->svcname,sprev->port);*/ printf("%15d%10s%30s%30s\n",sprev->svccount,sprev->type,sprev->svcname,sprev->port); /* add a carriage return, and advance the structure pointer */ sprev = sprev->nodelink; } } /* * Name: find_services(char *serv) * Description: * This routine is used to search the entire list of services * to find the service name passed into it, and the information * for that service. * * It is mainly used to print services from within a group. */ void find_services(char *serv) { /* pointer used to traverse objects structure, looking for * grpname passed in from dumpnetobj() */ services *service; /* make a copy and don't corrupt original data */ char type[LNSIZE]; char name[LNSIZE]; char port[LNSIZE]; /* start both off at the top of the structure */ service = shead->nodelink; /* continue until we have searched the entire structure, or find * a match first */ while(service->nodelink != NULL) { if((service->svcname != NULL) && (strcmp(service->svcname,serv) == 0)) { if(strcmp(service->type,"group") == 0) { strcpy(type,service->type); if(strlen(type) > 10) type[11] = '\0'; printf("%-10s",service->svcname); } else { if(strcmp(service->type,"group") != 0) { strcpy(name,service->svcname); strcpy(port,service->port); if(strlen(name) > 10) name[11] = '\0'; if(strlen(port) > 10) port[11] = '\0'; printf("%-11s:%-11s%5s",name,port,service->type); } } return; } /* advance pointer to next service */ service = service->nodelink; } }