static int files_getprotobyname(void *retval, void *mdata, va_list ap) { struct protoent pe; struct protoent_data *ped; char **cp; int error; char *name; struct protoent *pptr; char *buffer; size_t buflen; int *errnop; name = va_arg(ap, char *); pptr = va_arg(ap, struct protoent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); if ((ped = __protoent_data_init()) == NULL) { *errnop = errno; return (NS_NOTFOUND); } __setprotoent_p(ped->stayopen, ped); while ((error = __getprotoent_p(&pe, ped)) == 0) { if (strcmp(pe.p_name, name) == 0) break; for (cp = pe.p_aliases; *cp != 0; cp++) if (strcmp(*cp, name) == 0) goto found; } found: if (!ped->stayopen) __endprotoent_p(ped); if (error != 0) { *errnop = errno; return (NS_NOTFOUND); } if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { *errnop = errno; return (NS_RETURN); } *((struct protoent **)retval) = pptr; return (NS_SUCCESS); }
static int files_getprotobynumber(void *retval, void *mdata, va_list ap) { struct protoent pe; struct protoent_data *ped; int error; int number; struct protoent *pptr; char *buffer; size_t buflen; int *errnop; number = va_arg(ap, int); pptr = va_arg(ap, struct protoent *); buffer = va_arg(ap, char *); buflen = va_arg(ap, size_t); errnop = va_arg(ap, int *); if ((ped = __protoent_data_init()) == NULL) { *errnop = errno; return (NS_NOTFOUND); } __setprotoent_p(ped->stayopen, ped); while ((error = __getprotoent_p(&pe, ped)) == 0) if (pe.p_proto == number) break; if (!ped->stayopen) __endprotoent_p(ped); if (error != 0) { *errnop = errno; return (NS_NOTFOUND); } if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { *errnop = errno; return (NS_RETURN); } *((struct protoent **)retval) = pptr; return (NS_SUCCESS); }