|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T a
Length: 6474 (0x194a) Types: TextFile Names: »acsapns.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« └─⟦de7628f85⟧ └─⟦this⟧ »isode-6.0/acsap/acsapns.c«
/* acsapns.c - "higher performance" nameservice */ #ifndef lint static char *rcsid = "$Header: /f/osi/acsap/RCS/acsapns.c,v 7.2 90/01/11 18:34:53 mrose Exp $"; #endif /* * $Header: /f/osi/acsap/RCS/acsapns.c,v 7.2 90/01/11 18:34:53 mrose Exp $ * * * $Log: acsapns.c,v $ * Revision 7.2 90/01/11 18:34:53 mrose * real-sync * * Revision 7.1 89/12/19 16:18:07 mrose * dgram * * Revision 7.0 89/11/23 21:21:53 mrose * Release 6.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ /* * In next release, make this generic to CL-mode transport: * * UDP, CLTP, or CLTP over UDP * */ /* LINTLIBRARY */ #include <stdio.h> #include "psap.h" #include "isoaddrs.h" #include "tailor.h" #include "dgram.h" #ifdef TCP #include "internet.h" #endif #if defined(SOCKETS) && defined(TCP) #define MAXTRIES 3 /* should be tailorable... */ #define WAITRIES 15 /* .. */ /* \f DATA */ static int ud = NOTOK; static PS ps = NULLPS; /* \f */ PE name2value (name, attribute, real_name) char *name, *attribute; PE *real_name; { struct ns_query nss; register struct ns_query *ns = &nss; PE pe, result; static int id = 0; if (real_name) *real_name = NULLPE; bzero ((char *) ns, sizeof *ns); ns -> ns_id = ++id; ns -> ns_name = name; ns -> ns_attribute = attribute; pe = result = NULLPE; if (build_NS_Query (&pe, 1, NULL, NULLCP, (char *) ns) == NOTOK) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("build of Query failed: %s", PY_pepy)); } else name2value_aux (id, pe, real_name, &result); if (pe) pe_free (pe); return result; } /* \f */ static name2value_aux (id, pe, name, value) int id; PE pe, *name, *value; { int nfds, tries; fd_set ifds, rfds; PE in; static struct ns_response nss; register struct ns_response *ns = &nss; if (ps == NULLPS) { if (udp_open () == NOTOK) return; } else { if (ns -> ns_name) pe_free (ns -> ns_name); if (ns -> ns_value) pe_free (ns -> ns_value); } bzero ((char *) ns, sizeof *ns); FD_ZERO (&ifds); nfds = ud + 1; FD_SET (ud, &ifds); in = NULLPE; for (tries = MAXTRIES; tries > 0; ) { if (pe2ps (ps, pe) == NOTOK) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("unable to write query [%s]", ps_error (ps -> ps_errno))); return; } PLOG (addr_log, print_NS_Message, pe, "message", 0); rfds = ifds; /* struct copy */ if (xselect (nfds, &rfds, NULLFD, NULLFD, WAITRIES) <= 0) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("timer expired")); tries--; continue; } if ((in = ps2pe (ps)) == NULLPE) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("unable to read response [%s]", ps_error (ps -> ps_errno))); return; } if (parse_NS_Response (in, 1, NULLIP, NULLVP, (char *) ns) == NOTOK) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("parse of Response failed: %s", PY_pepy)); goto out; } PLOG (addr_log, print_NS_Message, in, "message", 1); if (ns -> ns_id == id) { if (name) *name = ns -> ns_name; else if (ns -> ns_name) { pe_free (ns -> ns_name); ns -> ns_name = NULLPE; } *value = ns -> ns_value; return; } if (ns -> ns_name) pe_free (ns -> ns_name); if (ns -> ns_value) pe_free (ns -> ns_value); bzero ((char *) ns, sizeof *ns); pe_free (in); in = NULLPE; SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("request-id mismatch; got %d, expecting %d", ns -> ns_id, id)); } SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("no response after %d requests", MAXTRIES)); out: ; if (in) pe_free (in); } /* \f */ static int udp_open () { register int i; register struct NSAPaddr *na; register struct PSAPaddr *pa; struct sockaddr_in lo_socket, in_socket; register struct sockaddr_in *lsock = &lo_socket, *isock = &in_socket; register struct hostent *hp; if ((pa = str2paddr (ns_address)) == NULL) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("unable to parse nameserver address \"%s\"", ns_address)); return NOTOK; } if ((i = pa -> pa_addr.sa_addr.ta_naddr) == 0) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("no network addresses present in \"%s\"", ns_address)); return NOTOK; } for (na = pa -> pa_addr.sa_addr.ta_addrs; i-- > 0; na++) if (na -> na_type == NA_TCP) break; if (i < 0) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("no TCP-based network addresses present in \"%s\"", ns_address)); return NOTOK; } if (na -> na_domain[0] == NULL) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("IP address not specified")); return NOTOK; } if ((hp = gethostbystring (na -> na_domain)) == NULL) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("%s: unknown host", na -> na_domain)); return NOTOK; } if (na -> na_port == 0) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("UDP port not specified")); return NOTOK; } if (na -> na_tset && !(na -> na_tset & NA_TSET_UDP)) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("UDP service not specified in transport-set: 0x%x", na -> na_tset)); return NOTOK; } bzero ((char *) isock, sizeof *isock); isock -> sin_family = hp ? hp -> h_addrtype : AF_INET; isock -> sin_port = na -> na_port; inaddr_copy (hp, isock); bzero ((char *) lsock, sizeof *lsock); lsock -> sin_family = isock -> sin_family; if ((ud = start_udp_client (lsock, 0, 0, 0)) == NOTOK) { SLOG (addr_log, LLOG_EXCEPTIONS, "failed", ("start_udp_client")); return NOTOK; } if (join_udp_server (ud, isock) == NOTOK) { SLOG (addr_log, LLOG_EXCEPTIONS, "connection", ("unable to establish")); (void) close_udp_socket (ud); } if ((ps = ps_alloc (dg_open)) == NULLPS || dg_setup (ps, ud, MAXDGRAM, read_udp_socket, write_udp_socket) == NOTOK) { if (ps) { SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("dg_setup failed: %s", ps_error (ps -> ps_errno))); ps_free (ps), ps = NULLPS; } else SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP, ("ps_alloc failed")); (void) close_udp_socket (ud); return NOTOK; } return OK; } #endif