/* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ /* bos720 src/bos/usr/samples/tcpip/dynload/rnd_pr.c 1.2 */ /* */ /* Licensed Materials - Property of IBM */ /* */ /* Restricted Materials of IBM */ /* */ /* COPYRIGHT International Business Machines Corp. 1999 */ /* All Rights Reserved */ /* */ /* US Government Users Restricted Rights - Use, duplication or */ /* disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /* */ /* IBM_PROLOG_END_TAG */ /* NOTICE TO USERS OF THE SOURCE CODE EXAMPLES INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THE SOURCE CODE EXAMPLES, BOTH INDIVIDUALLY AND AS ONE OR MORE GROUPS, "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOURCE CODE EXAMPLES, BOTH INDIVIDUALLY AND AS ONE OR MORE GROUPS, IS WITH YOU. SHOULD ANY PART OF THE SOURCE CODE EXAMPLES PROVE DEFECTIVE, YOU (AND NOT IBM OR AN AUTHORIZED RISC System/6000* WORKSTATION DEALER) ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. RISC System/6000 is a trademark of International Business Machines Corporation. */ /* INCLUDE for structure definitions */ #include #include #include #include #include #include #include #include #include typedef struct _pr_pvt { pthread_t pvt_thd; struct protoent pvt_protoent; /* protoent for return */ } pr_pvt; void *pr_pvtinit(); void pr_close(); void pr_rewind(); void pr_minimize(); struct protoent *ho_next(); struct protoent *ho_byname(); struct protoent *ho_bynumber(); struct protoent *rnd_makeprotocol(); void * pr_pvtinit() { /* Step 1: Allocate memory and clear it */ pr_pvt *pvt = (pr_pvt *)malloc(sizeof(*pvt)); bzero(pvt,sizeof(*pvt)); /* Step 2: Initialize whatever needs be done per-process */ pvt->pvt_thd = pthread_self(); return pvt; } /* * pr_close() - inverse of pr_pvtinit(); */ void pr_close(void *this) { if (!this) return; free(this); } /* * pr_rewind() - reset lookup; per-call init */ void pr_rewind(void *this) { pr_pvt *pvt = NULL; if (!this) return; pvt = (pr_pvt *)this; } void pr_minimize(void *this) { /* Nothing to do */ } /* pr_next is not supported in this example, since * we are not sequentially searching... */ /* * pr_byname() return a protoent struct, given a protocol name */ struct protoent * pr_byname(void *this, const char *name) { pr_pvt *pvt = NULL; if (!this) { errno = EINVAL; return(NULL); } pvt = (pr_pvt *)this; /* build up our protoent */ return(rnd_makeprotocol(this, name, -1)); } /* * pr_bynumber() - return a protoent struct, given an protocol number */ struct protoent * pr_bynumber(void *this, int proto) { pr_pvt *pvt = NULL; /* Get private struct */ if (!this) { errno = EINVAL; return(NULL); } pvt = (pr_pvt *)this; /* make and return hostent from data */ return(rnd_makeprotocol(this,NULL, proto)); } /* * rnd_makeprotocol() - internal function to build protoent from private data */ struct protoent * rnd_makeprotocol(void *this, char *protocol_name, int protocol_num) { pr_pvt *pvt = (pr_pvt *)this; /* getprotobynum case */ if ( protocol_name == NULL ) { char pre_name[]="protocol"; char format[1024]; bzero(format, sizeof format); pvt->pvt_protoent.p_aliases = NULL; pvt->pvt_protoent.p_proto = protocol_num; sprintf(format, "%d", protocol_num); pvt->pvt_protoent.p_name = (char *) malloc(strlen(pre_name) + strlen(format) + 1); bzero(pvt->pvt_protoent.p_name, sizeof pvt->pvt_protoent.p_name); strcpy(pvt->pvt_protoent.p_name, pre_name); strcat(pvt->pvt_protoent.p_name, format); } /* getprotobyname */ else if ( protocol_num == -1 ) { pvt->pvt_protoent.p_name = protocol_name; pvt->pvt_protoent.p_aliases = NULL; pvt->pvt_protoent.p_name = protocol_name; pvt->pvt_protoent.p_proto = strlen(protocol_name); } /* Return */ return(&(pvt->pvt_protoent)); }