From 64bc6412188b141c010ac3b8e813b837dd991e80 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Sun, 14 May 2000 04:16:35 +0000 Subject: Initial revision --- libc/inet/Makefile | 43 ++ libc/inet/addr.c | 85 ++++ libc/inet/resolv.c | 892 +++++++++++++++++++++++++++++++++++++++++ libc/inet/rpc/Makefile | 27 ++ libc/inet/rpc/auth_none.c | 133 ++++++ libc/inet/rpc/auth_unix.c | 319 +++++++++++++++ libc/inet/rpc/authunix_prot.c | 66 +++ libc/inet/rpc/bindresvport.c | 78 ++++ libc/inet/rpc/clnt_generic.c | 115 ++++++ libc/inet/rpc/clnt_perror.c | 310 ++++++++++++++ libc/inet/rpc/clnt_raw.c | 238 +++++++++++ libc/inet/rpc/clnt_simple.c | 112 ++++++ libc/inet/rpc/clnt_tcp.c | 466 +++++++++++++++++++++ libc/inet/rpc/clnt_udp.c | 442 ++++++++++++++++++++ libc/inet/rpc/get_myaddress.c | 108 +++++ libc/inet/rpc/getrpcent.c | 286 +++++++++++++ libc/inet/rpc/getrpcport.c | 55 +++ libc/inet/rpc/pmap_clnt.c | 115 ++++++ libc/inet/rpc/pmap_getmaps.c | 84 ++++ libc/inet/rpc/pmap_getport.c | 87 ++++ libc/inet/rpc/pmap_prot.c | 57 +++ libc/inet/rpc/pmap_prot2.c | 116 ++++++ libc/inet/rpc/pmap_rmt.c | 408 +++++++++++++++++++ libc/inet/rpc/rpc_callmsg.c | 190 +++++++++ libc/inet/rpc/rpc_commondata.c | 41 ++ libc/inet/rpc/rpc_dtablesize.c | 46 +++ libc/inet/rpc/rpc_prot.c | 289 +++++++++++++ libc/inet/rpc/svc.c | 492 +++++++++++++++++++++++ libc/inet/rpc/svc_auth.c | 114 ++++++ libc/inet/rpc/svc_auth_unix.c | 134 +++++++ libc/inet/rpc/svc_raw.c | 166 ++++++++ libc/inet/rpc/svc_run.c | 72 ++++ libc/inet/rpc/svc_simple.c | 143 +++++++ libc/inet/rpc/svc_tcp.c | 421 +++++++++++++++++++ libc/inet/rpc/svc_udp.c | 475 ++++++++++++++++++++++ libc/inet/rpc/xdr.c | 576 ++++++++++++++++++++++++++ libc/inet/rpc/xdr_array.c | 153 +++++++ libc/inet/rpc/xdr_float.c | 272 +++++++++++++ libc/inet/rpc/xdr_mem.c | 184 +++++++++ libc/inet/rpc/xdr_rec.c | 580 +++++++++++++++++++++++++++ libc/inet/rpc/xdr_reference.c | 132 ++++++ libc/inet/rpc/xdr_stdio.c | 189 +++++++++ 42 files changed, 9311 insertions(+) create mode 100644 libc/inet/Makefile create mode 100644 libc/inet/addr.c create mode 100644 libc/inet/resolv.c create mode 100644 libc/inet/rpc/Makefile create mode 100644 libc/inet/rpc/auth_none.c create mode 100644 libc/inet/rpc/auth_unix.c create mode 100644 libc/inet/rpc/authunix_prot.c create mode 100644 libc/inet/rpc/bindresvport.c create mode 100644 libc/inet/rpc/clnt_generic.c create mode 100644 libc/inet/rpc/clnt_perror.c create mode 100644 libc/inet/rpc/clnt_raw.c create mode 100644 libc/inet/rpc/clnt_simple.c create mode 100644 libc/inet/rpc/clnt_tcp.c create mode 100644 libc/inet/rpc/clnt_udp.c create mode 100644 libc/inet/rpc/get_myaddress.c create mode 100644 libc/inet/rpc/getrpcent.c create mode 100644 libc/inet/rpc/getrpcport.c create mode 100644 libc/inet/rpc/pmap_clnt.c create mode 100644 libc/inet/rpc/pmap_getmaps.c create mode 100644 libc/inet/rpc/pmap_getport.c create mode 100644 libc/inet/rpc/pmap_prot.c create mode 100644 libc/inet/rpc/pmap_prot2.c create mode 100644 libc/inet/rpc/pmap_rmt.c create mode 100644 libc/inet/rpc/rpc_callmsg.c create mode 100644 libc/inet/rpc/rpc_commondata.c create mode 100644 libc/inet/rpc/rpc_dtablesize.c create mode 100644 libc/inet/rpc/rpc_prot.c create mode 100644 libc/inet/rpc/svc.c create mode 100644 libc/inet/rpc/svc_auth.c create mode 100644 libc/inet/rpc/svc_auth_unix.c create mode 100644 libc/inet/rpc/svc_raw.c create mode 100644 libc/inet/rpc/svc_run.c create mode 100644 libc/inet/rpc/svc_simple.c create mode 100644 libc/inet/rpc/svc_tcp.c create mode 100644 libc/inet/rpc/svc_udp.c create mode 100644 libc/inet/rpc/xdr.c create mode 100644 libc/inet/rpc/xdr_array.c create mode 100644 libc/inet/rpc/xdr_float.c create mode 100644 libc/inet/rpc/xdr_mem.c create mode 100644 libc/inet/rpc/xdr_rec.c create mode 100644 libc/inet/rpc/xdr_reference.c create mode 100644 libc/inet/rpc/xdr_stdio.c (limited to 'libc/inet') diff --git a/libc/inet/Makefile b/libc/inet/Makefile new file mode 100644 index 000000000..28565cecd --- /dev/null +++ b/libc/inet/Makefile @@ -0,0 +1,43 @@ +# Copyright (C) 1995,1996 Robert de Bath +# Copyright (C) 1998-1999 D. Jeff Dionne +# Copyright (C) 1998 Kenneth Albanowski +# Copyright (C) 1999 D. Jeff Dionne +# under the GNU Library General Public License. + +LIBC=../libc.a + +CC=m68k-pic-coff-gcc +AR=m68k-pic-coff-ar +RANLIB=m68k-pic-coff-ranlib + +CCFLAGS= -O2 -m68000 -msoft-float -fno-builtin -I../include + +ASRC=addr.c +AOBJ=inet_aton.o inet_addr.o inet_ntoa.o + +RSRC=resolv.c +ROBJ= encodeh.o decodeh.o encoded.o decoded.o lengthd.o encodeq.o \ +decodeq.o lengthq.o encodea.o decodea.o encodep.o decodep.o \ +formquery.o dnslookup.o resolveaddress.o resolvemailbox.o \ +opennameservers.o closenameservers.o resolvename.o gethostbyname.o\ +gethostbyaddr.o + +OBJ=$(AOBJ) $(ROBJ) + +CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) + +all: $(LIBC) + @$(RM) $(OBJ) + +$(LIBC): $(LIBC)($(OBJ)) + +$(LIBC)($(AOBJ)): $(ASRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)($(ROBJ)): $(RSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +clean: + rm -f *.o libc.a diff --git a/libc/inet/addr.c b/libc/inet/addr.c new file mode 100644 index 000000000..bb27753bf --- /dev/null +++ b/libc/inet/addr.c @@ -0,0 +1,85 @@ +/* Copyright (C) 1995,1996 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#include +#include +#include + + +#ifdef L_inet_aton +int +inet_aton(cp, inp) +const char *cp; +struct in_addr *inp; +{ + unsigned long addr; + int value; + int part; + + if (!inp) + return 0; + + addr = 0; + for (part=1;part<=4;part++) { + + if (!isdigit(*cp)) + return 0; + + value = 0; + while (isdigit(*cp)) { + value *= 10; + value += *cp++ - '0'; + if (value > 255) + return 0; + } + + if (*cp++ != ((part == 4) ? '\0' : '.')) + return 0; + + addr <<= 8; + addr |= value; + } + + inp->s_addr = htonl(addr); + + return 1; +} +#endif + +#ifdef L_inet_addr +unsigned long +inet_addr(cp) +const char *cp; +{ + struct in_addr a; + if (!inet_aton(cp, &a)) + return -1; + else + return a.s_addr; +} +#endif + +#ifdef L_inet_ntoa + +extern char * itoa(int); + +char * +inet_ntoa(in) +struct in_addr in; +{ + static char buf[18]; + unsigned long addr = ntohl(in.s_addr); + + strcpy(buf, itoa((addr >> 24) & 0xff)); + strcat(buf, "."); + strcat(buf, itoa((addr >> 16) & 0xff)); + strcat(buf, "."); + strcat(buf, itoa((addr >> 8) & 0xff)); + strcat(buf, "."); + strcat(buf, itoa(addr & 0xff)); + + return buf; +} +#endif diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c new file mode 100644 index 000000000..b4cfab104 --- /dev/null +++ b/libc/inet/resolv.c @@ -0,0 +1,892 @@ +/* resolv.c: DNS Resolver + * + * Copyright (C) 1998 Kenneth Albanowski , + * The Silver Hammer Group, Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DNS_SERVICE 53 +#define MAX_RECURSE 5 +#define REPLY_TIMEOUT 10 +#define MAX_RETRIES 15 + +#undef DEBUG +#ifdef DEBUG +#define DPRINTF(X,args...) printf(X,args...) +#else +#define DPRINTF(X,args...) +#endif /* DEBUG */ + +#ifdef L_encodeh +int encode_header(struct resolv_header * h, unsigned char * dest, int maxlen) +{ + if (maxlen < 12) + return -1; + + dest[0] = (h->id & 0xff00) >> 8; + dest[1] = (h->id & 0x00ff) >> 0; + dest[2] = (h->qr ? 0x80 : 0) | + ((h->opcode & 0x0f) << 3) | + (h->aa ? 0x04 : 0) | + (h->tc ? 0x02 : 0) | + (h->rd ? 0x01 : 0); + dest[3] = (h->ra ? 0x80 : 0) | + (h->rcode & 0x0f); + dest[4] = (h->qdcount & 0xff00) >> 8; + dest[5] = (h->qdcount & 0x00ff) >> 0; + dest[6] = (h->ancount & 0xff00) >> 8; + dest[7] = (h->ancount & 0x00ff) >> 0; + dest[8] = (h->nscount & 0xff00) >> 8; + dest[9] = (h->nscount & 0x00ff) >> 0; + dest[10] = (h->arcount & 0xff00) >> 8; + dest[11] = (h->arcount & 0x00ff) >> 0; + + return 12; +} +#endif + +#ifdef L_decodeh +int decode_header(unsigned char * data, struct resolv_header * h) +{ + h->id = (data[0] << 8) | data[1]; + h->qr = (data[2] & 0x80) ? 1 : 0; + h->opcode = (data[2] >> 3) & 0x0f; + h->aa = (data[2] & 0x04) ? 1 : 0; + h->tc = (data[2] & 0x02) ? 1 : 0; + h->rd = (data[2] & 0x01) ? 1 : 0; + h->ra = (data[3] & 0x80) ? 1 : 0; + h->rcode = data[3] & 0x0f; + h->qdcount = (data[4] << 8) | data[5]; + h->ancount = (data[6] << 8) | data[7]; + h->nscount = (data[8] << 8) | data[9]; + h->arcount = (data[10] << 8) | data[11]; + + return 12; +} +#endif + +#ifdef L_encoded +/* Encode a dotted string into nameserver transport-level encoding. + This routine is fairly dumb, and doesn't attempt to compress + the data */ + +int encode_dotted(const char * dotted, unsigned char * dest, int maxlen) +{ + int used=0; + + while(dotted && *dotted) { + char * c = strchr(dotted, '.'); + int l = c ? c - dotted : strlen(dotted); + + if (l >= (maxlen-used-1)) + return -1; + + dest[used++] = l; + memcpy(dest+used, dotted, l); + used += l; + + if (c) + dotted = c+1; + else + break; + } + + if (maxlen < 1) + return -1; + + dest[used++] = 0; + + return used; +} +#endif + +#ifdef L_decoded +/* Decode a dotted string from nameserver transport-level encoding. + This routine understands compressed data. */ + +int decode_dotted(const unsigned char * data, int offset, + char * dest, int maxlen) +{ + int l; + int measure=1; + int total = 0; + int used=0; + + if (!data) + return -1; + + while ((measure && total++), (l=data[offset++])) { + + if ((l & 0xc0) == (0xc0)) { + if (measure) + total++; + /* compressed item, redirect */ + offset = ((l & 0x3f) << 8) | data[offset]; + measure = 0; + continue; + } + + if ((used+l+1) >= maxlen) + return -1; + + memcpy(dest+used, data+offset, l); + offset += l; + used += l; + if (measure) + total += l; + + if (data[offset] != 0) + dest[used++] = '.'; + else + dest[used++] = '\0'; + } + + DPRINTF("Total decode len = %d\n", total); + + return total; +} +#endif + +#ifdef L_lengthd + +int length_dotted(const unsigned char * data, int offset) +{ + int orig_offset = offset; + int l; + + if (!data) + return -1; + + while ((l=data[offset++])) { + + if ((l & 0xc0) == (0xc0)) { + offset++; + break; + } + + offset += l; + } + + return offset-orig_offset; +} +#endif + +#ifdef L_encodeq +int encode_question(struct resolv_question * q, + unsigned char * dest, int maxlen) +{ + int i; + + i = encode_dotted(q->dotted, dest, maxlen); + if (i < 0) + return i; + + dest += i; + maxlen -= i; + + if (maxlen < 4) + return -1; + + dest[0] = (q->qtype & 0xff00) >> 8; + dest[1] = (q->qtype & 0x00ff) >> 0; + dest[2] = (q->qclass & 0xff00) >> 8; + dest[3] = (q->qclass & 0x00ff) >> 0; + + return i+4; +} +#endif + +#ifdef L_decodeq +int decode_question(unsigned char * message, int offset, + struct resolv_question * q) +{ + char temp[256]; + int i; + + i = decode_dotted(message, offset, temp, 256); + if (i < 0) + return i; + + offset += i; + + q->dotted = strdup(temp); + q->qtype = (message[offset+0] << 8) | message[offset+1]; + q->qclass = (message[offset+2] << 8) | message[offset+3]; + + return i+4; +} +#endif + +#ifdef L_lengthq +int length_question(unsigned char * message, int offset) +{ + int i; + + i = length_dotted(message, offset); + if (i < 0) + return i; + + return i+4; +} +#endif + +#ifdef L_encodea +int encode_answer(struct resolv_answer * a, + unsigned char * dest, int maxlen) +{ + int i; + + i = encode_dotted(a->dotted, dest, maxlen); + if (i < 0) + return i; + + dest += i; + maxlen -= i; + + if (maxlen < (10+a->rdlength)) + return -1; + + *dest++ = (a->atype & 0xff00) >> 8; + *dest++ = (a->atype & 0x00ff) >> 0; + *dest++ = (a->aclass & 0xff00) >> 8; + *dest++ = (a->aclass & 0x00ff) >> 0; + *dest++ = (a->ttl & 0xff000000) >> 24; + *dest++ = (a->ttl & 0x00ff0000) >> 16; + *dest++ = (a->ttl & 0x0000ff00) >> 8; + *dest++ = (a->ttl & 0x000000ff) >> 0; + *dest++ = (a->rdlength & 0xff00) >> 8; + *dest++ = (a->rdlength & 0x00ff) >> 0; + memcpy(dest, a->rdata, a->rdlength); + + return i+10+a->rdlength; +} +#endif + +#ifdef L_decodea +int decode_answer(unsigned char * message, int offset, + struct resolv_answer * a) +{ + char temp[256]; + int i; + + i = decode_dotted(message, offset, temp, 256); + if (i < 0) + return i; + + message += offset+i; + + a->dotted = strdup(temp); + a->atype = (message[0] << 8) | message[1]; message += 2; + a->aclass = (message[0] << 8) | message[1]; message += 2; + a->ttl = (message[0] << 24) | + (message[1] << 16) | + (message[2] << 8) | + (message[3] << 0); + message += 4; + a->rdlength = (message[0] << 8) | message[1]; message += 2; + a->rdata = message; + a->rdoffset = offset+i+10; + + DPRINTF("i=%d,rdlength=%d\n", i, a->rdlength); + + return i+10+a->rdlength; +} +#endif + +#ifdef L_encodep +int encode_packet(struct resolv_header * h, + struct resolv_question ** q, + struct resolv_question ** an, + struct resolv_question ** ns, + struct resolv_question ** ar, + unsigned char * dest, int maxlen) +{ + int i, total=0; + int j; + + i = encode_header(h, dest, maxlen); + if (i < 0) + return i; + + dest += i; + maxlen -= i; + total += i; + + for(j=0;jqdcount;j++) { + i = encode_question(q[j], dest, maxlen); + if (i < 0) + return i; + dest += i; + maxlen -= i; + total += i; + } + + for(j=0;jancount;j++) { + i = encode_answer(an[j], dest, maxlen); + if (i < 0) + return i; + dest += i; + maxlen -= i; + total += i; + } + for(j=0;jnscount;j++) { + i = encode_answer(ns[j], dest, maxlen); + if (i < 0) + return i; + dest += i; + maxlen -= i; + total += i; + } + for(j=0;jarcount;j++) { + i = encode_answer(ar[j], dest, maxlen); + if (i < 0) + return i; + dest += i; + maxlen -= i; + total += i; + } + + return total; +} +#endif + +#ifdef L_decodep +int decode_packet(unsigned char * data, struct resolv_header * h) +{ + return decode_header(data, h); +} +#endif + +#ifdef L_formquery +int form_query(int id, const char * name, int type, unsigned char * packet, int maxlen) +{ + struct resolv_header h; + struct resolv_question q; + int i,j; + + memset(&h, 0, sizeof(h)); + h.id = id; + h.qdcount = 1; + + q.dotted = (char*)name; + q.qtype = type; + q.qclass = 1 /*CLASS_IN*/; + + i = encode_header(&h, packet, maxlen); + if (i < 0) + return i; + + j = encode_question(&q, packet+i, maxlen-i); + if (j < 0) + return j; + + return i+j; +} +#endif + +#ifdef L_dnslookup + +int dns_caught_signal = 0; +void dns_catch_signal(int signo) { + dns_caught_signal = 1; +} + +int dns_lookup(const char * name, int type, int nscount, const char ** nsip, + unsigned char ** outpacket, struct resolv_answer * a) +{ + static int id=1; + int i,j,len; + int fd; + int pos; + static int ns = 0; + struct sockaddr_in sa; + int oldalarm; + __sighandler_t oldhandler; + struct resolv_header h; + struct resolv_question q; + int retries = 0; + unsigned char * packet = malloc(512); + + if (!packet) + goto fail1; + + DPRINTF("Looking up type %d answer for '%s'\n", type, name); + + + if (!nscount) + goto fail1; + + ns %= nscount; + + fd = -1; + + while (retries++ < MAX_RETRIES) { + + if (fd != -1) + close(fd); + + fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if (fd==-1) + goto fail2; + + + memset(packet, 0, 512); + + memset(&h, 0, sizeof(h)); + h.id = ++id; + h.qdcount = 1; + h.rd = 1; + + DPRINTF("encoding header\n"); + + i = encode_header(&h, packet, 512); + if (i < 0) + goto fail3; + + q.dotted = (char*)name; + q.qtype = type; + q.qclass = 1 /*CLASS_IN*/; + + j = encode_question(&q, packet+i, 512-i); + if (j < 0) + goto fail3; + + len = i+j; + + DPRINTF("On try %d, sending query to port %d of machine %s\n", + retries, DNS_SERVICE, nsip[ns]); + + sa.sin_family = AF_INET; + sa.sin_port = htons(DNS_SERVICE); + sa.sin_addr.s_addr = inet_addr(nsip[ns]); + + if (connect(fd, (struct sockaddr*)&sa, sizeof(sa))==-1) { + if (errno == ENETUNREACH) { + /* routing error, presume not transient */ + goto tryall; + } else + /* retry */ + break; + } + + DPRINTF("Transmitting packet of length %d, id=%d, qr=%d\n", + len, h.id, h.qr); + + send(fd, packet, len, 0); + + dns_caught_signal = 0; + oldalarm = alarm(REPLY_TIMEOUT); + oldhandler = signal(SIGALRM, dns_catch_signal); + + i = recv(fd, packet, 512, 0); + + alarm(0); + signal(SIGALRM, oldhandler); + alarm(oldalarm); + + DPRINTF("Timeout=%d, len=%d\n", + dns_caught_signal, i); + + if (dns_caught_signal) + /* timed out, so retry send and receive, + to next nameserver on queue */ + goto again; + + if (i < 12) + /* too short ! */ + goto again; + + decode_header(packet, &h); + + DPRINTF("id = %d, qr = %d\n", + h.id, h.qr); + + if ((h.id != id) || (!h.qr)) + /* unsolicited */ + goto again; + + DPRINTF("Got response (i think)!\n"); + DPRINTF("qrcount=%d,ancount=%d,nscount=%d,arcount=%d\n", + h.qdcount, h.ancount, h.nscount, h.arcount); + DPRINTF("opcode=%d,aa=%d,tc=%d,rd=%d,ra=%d,rcode=%d\n", + h.opcode,h.aa,h.tc,h.rd,h.ra,h.rcode); + + if ((h.rcode) || (h.ancount < 1)) { + /* negative result, not present */ + goto tryall; + } + + pos = 12; + + for(j=0;jdotted); + DPRINTF("Answer type = |%d|\n", a->atype); + + close(fd); + + if (outpacket) + *outpacket = packet; + else + free(packet); + return (0); /* success! */ + + tryall: + /* if there are other nameservers, give them a go, + otherwise return with error */ + if (retries >= nscount) + break; + again: + ns = (ns + 1) % nscount; + continue; + } + + + +fail3: + close(fd); +fail2: + free(packet); +fail1: + return -1; +} +#endif + +#ifdef L_resolveaddress + +int resolve_address(const char * address, + int nscount, const char ** nsip, + struct in_addr * in) +{ + unsigned char * packet; + struct resolv_answer a; + char temp[256]; + int i; + int nest=0; + + if (!address || !in) + return -1; + + strcpy(temp, address); + + for(;;) { + + i = dns_lookup(temp, 1, nscount, nsip, &packet, &a); + + if (i<0) + return -1; + + free(a.dotted); + + if (a.atype == 5) { /* CNAME*/ + i = decode_dotted(packet, a.rdoffset, temp, 256); + free(packet); + + if (i <0) + return -1; + if (++nest > MAX_RECURSE) + return -1; + continue; + } else if (a.atype == 1) { /* ADDRESS */ + free(packet); + break; + } else { + free(packet); + return -1; + } + } + + if (in) + memcpy(in, a.rdata, 4); + + return 0; +} +#endif + +#ifdef L_resolvemailbox + +int resolve_mailbox(const char * address, + int nscount, const char ** nsip, + struct in_addr * in) +{ + struct resolv_answer a; + unsigned char * packet; + char temp[256]; + int nest=0; + int i; + + if (!address || !in) + return -1; + + /* look up mail exchange */ + i = dns_lookup(address, 15, nscount, nsip, &packet, &a); + + strcpy(temp, address); + + if (i>=0) { + i = decode_dotted(packet, a.rdoffset+2, temp, 256); + free(packet); + } + + for(;;) { + + i = dns_lookup(temp, 1, nscount, nsip, &packet, &a); + + if (i<0) + return -1; + + free(a.dotted); + + if (a.atype == 5) { /* CNAME*/ + i = decode_dotted(packet, a.rdoffset, temp, 256); + free(packet); + if (i<0) + return i; + if (++nest > MAX_RECURSE) + return -1; + continue; + } else if (a.atype == 1) { /* ADDRESS */ + free(packet); + break; + } else { + free(packet); + return -1; + } + } + + if (in) + memcpy(in, a.rdata, 4); + + return 0; +} +#endif + +extern int nameservers; +extern const char * nameserver[3]; + +#ifdef L_opennameservers + +int nameservers; +const char * nameserver[3]; + +int open_nameservers() +{ + FILE *fp; + char **arg; + int i; + + if (fp = fopen("/etc/resolv.conf", "r")) { + if (arg = cfgfind(fp, "nameserver")) { + for (i=1; arg[i]; i++) { + nameserver[nameservers++] = strdup(arg[i]); + } + } + fclose(fp); + } + return 0; +} +#endif + +#ifdef L_closenameservers +void close_nameservers(void) { + + while(nameservers>0) + free(nameserver[--nameservers]); +} +#endif + + +#ifdef L_resolvename + +char * resolve_name(const char * name, int mailbox) +{ + struct in_addr in; + int i; + + /* shortcut: is it a valid IP address to begin with? */ + if (inet_aton(name, &in)) + return name; + + open_nameservers(); + + DPRINTF("looking up '%s', mailbox=%d, nameservers=%d\n", + name, mailbox, nameservers); + + if (mailbox) + i = resolve_mailbox(name, nameservers, nameserver, &in); + else + i = resolve_address(name, nameservers, nameserver, &in); + + if (i<0) + return 0; + + DPRINTF("success = '%s'\n", inet_ntoa(in)); + + return inet_ntoa(in); +} +#endif + +#ifdef L_gethostbyname + +struct hostent * gethostbyname(const char * name) +{ + static struct hostent h; + static char namebuf[256]; + static struct in_addr in; + static struct in_addr *addr_list[2]; + unsigned char * packet; + struct resolv_answer a; + int i; + int nest=0; + + open_nameservers(); + + if (!name) + return 0; + + memset(&h, 0, sizeof(h)); + + addr_list[0] = ∈ + addr_list[1] = 0; + + strcpy(namebuf, name); + + for(;;) { + + i = dns_lookup(namebuf, 1, nameservers, nameserver, &packet, &a); + + if (i<0) + return 0; + + strcpy(namebuf, a.dotted); + free(a.dotted); + + + if (a.atype == 5) { /* CNAME*/ + i = decode_dotted(packet, a.rdoffset, namebuf, 256); + free(packet); + + if (i <0) + return 0; + if (++nest > MAX_RECURSE) + return 0; + continue; + } else if (a.atype == 1) { /* ADDRESS */ + memcpy(&in, a.rdata, sizeof(in)); + h.h_name = namebuf; + h.h_addrtype = AF_INET; + h.h_length = sizeof(in); + h.h_addr_list = (char**)addr_list; + free(packet); + break; + } else { + free(packet); + return 0; + } + } + + return &h; +} +#endif + +#ifdef L_gethostbyaddr + +struct hostent * gethostbyaddr(const char * addr, int len, int type) +{ + static struct hostent h; + static char namebuf[256]; + static struct in_addr in; + static struct in_addr *addr_list[2]; + unsigned char * packet; + struct resolv_answer a; + int i; + int nest=0; + + if (!addr || (len != sizeof(in)) || (type != AF_INET)) + return 0; + + memcpy(&in.s_addr, addr, len); + + open_nameservers(); + + memset(&h, 0, sizeof(h)); + + addr_list[0] = ∈ + addr_list[1] = 0; + + sprintf(namebuf, "%d.%d.%d.%d.in-addr.arpa", + (in.s_addr >> 24) & 0xff, + (in.s_addr >> 16) & 0xff, + (in.s_addr >> 8) & 0xff, + (in.s_addr >> 0) & 0xff + ); + + for(;;) { + + i = dns_lookup(namebuf, 12, nameservers, nameserver, &packet, &a); + + if (i<0) + return 0; + + strcpy(namebuf, a.dotted); + free(a.dotted); + + if (a.atype == 5) { /* CNAME*/ + i = decode_dotted(packet, a.rdoffset, namebuf, 256); + free(packet); + + if (i <0) + return 0; + if (++nest > MAX_RECURSE) + return 0; + continue; + } else if (a.atype == 12) { /* ADDRESS */ + i = decode_dotted(packet, a.rdoffset, namebuf, 256); + free(packet); + + h.h_name = namebuf; + h.h_addrtype = AF_INET; + h.h_length = sizeof(in); + h.h_addr_list = (char**)addr_list; + break; + } else { + free(packet); + return 0; + } + } + + return &h; +} +#endif diff --git a/libc/inet/rpc/Makefile b/libc/inet/rpc/Makefile new file mode 100644 index 000000000..388434165 --- /dev/null +++ b/libc/inet/rpc/Makefile @@ -0,0 +1,27 @@ +CC=m68k-pic-coff-gcc +AR=m68k-pic-coff-ar +RANLIB=m68k-pic-coff-ranlib + +CFLAGS= -O2 -fomit-frame-pointer -Dlinux -I../include + +OBJS = auth_none.o auth_unix.o authunix_prot.o \ + bindresvport.o clnt_generic.o clnt_perror.o \ + clnt_raw.o clnt_simple.o clnt_tcp.o clnt_udp.o \ + get_myaddress.o getrpcent.o getrpcport.o pmap_clnt.o \ + pmap_getmaps.o pmap_getport.o pmap_prot.o pmap_prot2.o \ + pmap_rmt.o rpc_callmsg.o rpc_commondata.o \ + rpc_dtablesize.o rpc_prot.o svc.o svc_auth.o \ + svc_auth_unix.o svc_raw.o svc_run.o svc_simple.o \ + svc_tcp.o svc_udp.o xdr.o xdr_array.o xdr_float.o \ + xdr_mem.o xdr_rec.o xdr_reference.o xdr_stdio.o + +LIBC = ../libc.a + +all: $(LIBC) + +$(LIBC): $(LIBC)($(OBJS)) + +clean: + rm -f *.[oa] *~ core + + diff --git a/libc/inet/rpc/auth_none.c b/libc/inet/rpc/auth_none.c new file mode 100644 index 000000000..630037fb4 --- /dev/null +++ b/libc/inet/rpc/auth_none.c @@ -0,0 +1,133 @@ +/* @(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro"; +#endif + +/* + * auth_none.c + * Creates a client authentication handle for passing "null" + * credentials and verifiers to remote systems. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +#include +#include +#include +#define MAX_MARSHEL_SIZE 20 + +/* + * Authenticator operations routines + */ +static void authnone_verf(); +static void authnone_destroy(); +static bool_t authnone_marshal(); +static bool_t authnone_validate(); +static bool_t authnone_refresh(); + +static struct auth_ops ops = { + authnone_verf, + authnone_marshal, + authnone_validate, + authnone_refresh, + authnone_destroy +}; + +static struct authnone_private { + AUTH no_client; + char marshalled_client[MAX_MARSHEL_SIZE]; + u_int mcnt; +} *authnone_private; + +AUTH * +authnone_create() +{ + register struct authnone_private *ap = authnone_private; + XDR xdr_stream; + register XDR *xdrs; + + if (ap == 0) { + ap = (struct authnone_private *)calloc(1, sizeof (*ap)); + if (ap == 0) + return (0); + authnone_private = ap; + } + if (!ap->mcnt) { + ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth; + ap->no_client.ah_ops = &ops; + xdrs = &xdr_stream; + xdrmem_create(xdrs, ap->marshalled_client, (u_int)MAX_MARSHEL_SIZE, + XDR_ENCODE); + (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_cred); + (void)xdr_opaque_auth(xdrs, &ap->no_client.ah_verf); + ap->mcnt = XDR_GETPOS(xdrs); + XDR_DESTROY(xdrs); + } + return (&ap->no_client); +} + +/*ARGSUSED*/ +static bool_t +authnone_marshal(client, xdrs) + AUTH *client; + XDR *xdrs; +{ + register struct authnone_private *ap = authnone_private; + + if (ap == 0) + return (0); + return ((*xdrs->x_ops->x_putbytes)(xdrs, + ap->marshalled_client, ap->mcnt)); +} + +static void +authnone_verf() +{ +} + +static bool_t +authnone_validate() +{ + + return (TRUE); +} + +static bool_t +authnone_refresh() +{ + + return (FALSE); +} + +static void +authnone_destroy() +{ +} diff --git a/libc/inet/rpc/auth_unix.c b/libc/inet/rpc/auth_unix.c new file mode 100644 index 000000000..87ff2b648 --- /dev/null +++ b/libc/inet/rpc/auth_unix.c @@ -0,0 +1,319 @@ +/* @(#)auth_unix.c 2.2 88/08/01 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro"; +#endif + +/* + * auth_unix.c, Implements UNIX style authentication parameters. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + * + * The system is very weak. The client uses no encryption for it's + * credentials and only sends null verifiers. The server sends backs + * null verifiers or optionally a verifier that suggests a new short hand + * for the credentials. + * + */ + +#include + +#include +#include +#include +#include + +/* + * Unix authenticator operations vector + */ +static void authunix_nextverf(); +static bool_t authunix_marshal(); +static bool_t authunix_validate(); +static bool_t authunix_refresh(); +static void authunix_destroy(); + +static struct auth_ops auth_unix_ops = { + authunix_nextverf, + authunix_marshal, + authunix_validate, + authunix_refresh, + authunix_destroy +}; + +/* + * This struct is pointed to by the ah_private field of an auth_handle. + */ +struct audata { + struct opaque_auth au_origcred; /* original credentials */ + struct opaque_auth au_shcred; /* short hand cred */ + u_long au_shfaults; /* short hand cache faults */ + char au_marshed[MAX_AUTH_BYTES]; + u_int au_mpos; /* xdr pos at end of marshed */ +}; +#define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private) + +static bool_t marshal_new_auth(); + + +/* + * Create a unix style authenticator. + * Returns an auth handle with the given stuff in it. + */ +AUTH * +authunix_create(machname, uid, gid, len, aup_gids) + char *machname; + int uid; + int gid; + register int len; + int *aup_gids; +{ + struct authunix_parms aup; + char mymem[MAX_AUTH_BYTES]; + struct timeval now; + XDR xdrs; + register AUTH *auth; + register struct audata *au; + + /* + * Allocate and set up auth handle + */ + auth = (AUTH *)mem_alloc(sizeof(*auth)); +#ifndef KERNEL + if (auth == NULL) { + (void)fprintf(stderr, "authunix_create: out of memory\n"); + return (NULL); + } +#endif + au = (struct audata *)mem_alloc(sizeof(*au)); +#ifndef KERNEL + if (au == NULL) { + (void)fprintf(stderr, "authunix_create: out of memory\n"); + return (NULL); + } +#endif + auth->ah_ops = &auth_unix_ops; + auth->ah_private = (caddr_t)au; + auth->ah_verf = au->au_shcred = _null_auth; + au->au_shfaults = 0; + + /* + * fill in param struct from the given params + */ + (void)gettimeofday(&now, (struct timezone *)0); + aup.aup_time = now.tv_sec; + aup.aup_machname = machname; + aup.aup_uid = uid; + aup.aup_gid = gid; + aup.aup_len = (u_int)len; + aup.aup_gids = aup_gids; + + /* + * Serialize the parameters into origcred + */ + xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE); + if (! xdr_authunix_parms(&xdrs, &aup)) + abort(); + au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs); + au->au_origcred.oa_flavor = AUTH_UNIX; +#ifdef KERNEL + au->au_origcred.oa_base = mem_alloc((u_int) len); +#else + if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) { + (void)fprintf(stderr, "authunix_create: out of memory\n"); + return (NULL); + } +#endif + bcopy(mymem, au->au_origcred.oa_base, (u_int)len); + + /* + * set auth handle to reflect new cred. + */ + auth->ah_cred = au->au_origcred; + marshal_new_auth(auth); + return (auth); +} + +/* + * Returns an auth handle with parameters determined by doing lots of + * syscalls. + */ +AUTH * +authunix_create_default() +{ + register int len; + char machname[MAX_MACHINE_NAME + 1]; + register int uid; + register int gid; + int gids[NGRPS]; + + if (gethostname(machname, MAX_MACHINE_NAME) == -1) + abort(); + machname[MAX_MACHINE_NAME] = 0; + uid = geteuid(); + gid = getegid(); + if ((len = getgroups(NGRPS, gids)) < 0) + abort(); + return (authunix_create(machname, uid, gid, len, gids)); +} + +/* + * authunix operations + */ + +static void +authunix_nextverf(auth) + AUTH *auth; +{ + /* no action necessary */ +} + +static bool_t +authunix_marshal(auth, xdrs) + AUTH *auth; + XDR *xdrs; +{ + register struct audata *au = AUTH_PRIVATE(auth); + + return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos)); +} + +static bool_t +authunix_validate(auth, verf) + register AUTH *auth; + struct opaque_auth verf; +{ + register struct audata *au; + XDR xdrs; + + if (verf.oa_flavor == AUTH_SHORT) { + au = AUTH_PRIVATE(auth); + xdrmem_create(&xdrs, verf.oa_base, verf.oa_length, XDR_DECODE); + + if (au->au_shcred.oa_base != NULL) { + mem_free(au->au_shcred.oa_base, + au->au_shcred.oa_length); + au->au_shcred.oa_base = NULL; + } + if (xdr_opaque_auth(&xdrs, &au->au_shcred)) { + auth->ah_cred = au->au_shcred; + } else { + xdrs.x_op = XDR_FREE; + (void)xdr_opaque_auth(&xdrs, &au->au_shcred); + au->au_shcred.oa_base = NULL; + auth->ah_cred = au->au_origcred; + } + marshal_new_auth(auth); + } + return (TRUE); +} + +static bool_t +authunix_refresh(auth) + register AUTH *auth; +{ + register struct audata *au = AUTH_PRIVATE(auth); + struct authunix_parms aup; + struct timeval now; + XDR xdrs; + register int stat; + + if (auth->ah_cred.oa_base == au->au_origcred.oa_base) { + /* there is no hope. Punt */ + return (FALSE); + } + au->au_shfaults ++; + + /* first deserialize the creds back into a struct authunix_parms */ + aup.aup_machname = NULL; + aup.aup_gids = (int *)NULL; + xdrmem_create(&xdrs, au->au_origcred.oa_base, + au->au_origcred.oa_length, XDR_DECODE); + stat = xdr_authunix_parms(&xdrs, &aup); + if (! stat) + goto done; + + /* update the time and serialize in place */ + (void)gettimeofday(&now, (struct timezone *)0); + aup.aup_time = now.tv_sec; + xdrs.x_op = XDR_ENCODE; + XDR_SETPOS(&xdrs, 0); + stat = xdr_authunix_parms(&xdrs, &aup); + if (! stat) + goto done; + auth->ah_cred = au->au_origcred; + marshal_new_auth(auth); +done: + /* free the struct authunix_parms created by deserializing */ + xdrs.x_op = XDR_FREE; + (void)xdr_authunix_parms(&xdrs, &aup); + XDR_DESTROY(&xdrs); + return (stat); +} + +static void +authunix_destroy(auth) + register AUTH *auth; +{ + register struct audata *au = AUTH_PRIVATE(auth); + + mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length); + + if (au->au_shcred.oa_base != NULL) + mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length); + + mem_free(auth->ah_private, sizeof(struct audata)); + + if (auth->ah_verf.oa_base != NULL) + mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length); + + mem_free((caddr_t)auth, sizeof(*auth)); +} + +/* + * Marshals (pre-serializes) an auth struct. + * sets private data, au_marshed and au_mpos + */ +static bool_t +marshal_new_auth(auth) + register AUTH *auth; +{ + XDR xdr_stream; + register XDR *xdrs = &xdr_stream; + register struct audata *au = AUTH_PRIVATE(auth); + + xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE); + if ((! xdr_opaque_auth(xdrs, &(auth->ah_cred))) || + (! xdr_opaque_auth(xdrs, &(auth->ah_verf)))) { + perror("auth_none.c - Fatal marshalling problem"); + } else { + au->au_mpos = XDR_GETPOS(xdrs); + } + XDR_DESTROY(xdrs); +} diff --git a/libc/inet/rpc/authunix_prot.c b/libc/inet/rpc/authunix_prot.c new file mode 100644 index 000000000..a60d99a57 --- /dev/null +++ b/libc/inet/rpc/authunix_prot.c @@ -0,0 +1,66 @@ +/* @(#)authunix_prot.c 2.1 88/07/29 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro"; +#endif + +/* + * authunix_prot.c + * XDR for UNIX style authentication parameters for RPC + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + + +#include +#include +#include +#include + +/* + * XDR for unix authentication parameters. + */ +bool_t +xdr_authunix_parms(xdrs, p) + register XDR *xdrs; + register struct authunix_parms *p; +{ + + if (xdr_u_long(xdrs, &(p->aup_time)) + && xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME) + && xdr_int(xdrs, &(p->aup_uid)) + && xdr_int(xdrs, &(p->aup_gid)) + && xdr_array(xdrs, (caddr_t *)&(p->aup_gids), + &(p->aup_len), NGRPS, sizeof(int), xdr_int) ) { + return (TRUE); + } + return (FALSE); +} + diff --git a/libc/inet/rpc/bindresvport.c b/libc/inet/rpc/bindresvport.c new file mode 100644 index 000000000..71803dd41 --- /dev/null +++ b/libc/inet/rpc/bindresvport.c @@ -0,0 +1,78 @@ +static char sccsid[] = "@(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC 1.8 88/02/08 SMI"; +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +#include +#include +#include +#include + +/* + * Bind a socket to a privileged IP port + */ +bindresvport(sd, sin) + int sd; + struct sockaddr_in *sin; +{ + int res; + static short port; + struct sockaddr_in myaddr; + extern int errno; + int i; + +#define STARTPORT 600 +#define ENDPORT (IPPORT_RESERVED - 1) +#define NPORTS (ENDPORT - STARTPORT + 1) + + if (sin == (struct sockaddr_in *)0) { + sin = &myaddr; + bzero(sin, sizeof (*sin)); + sin->sin_family = AF_INET; + } else if (sin->sin_family != AF_INET) { + errno = EPFNOSUPPORT; + return (-1); + } + if (port == 0) { + port = (getpid() % NPORTS) + STARTPORT; + } + res = -1; + errno = EADDRINUSE; + for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) { + sin->sin_port = htons(port++); + if (port > ENDPORT) { + port = STARTPORT; + } + res = bind(sd, sin, sizeof(struct sockaddr_in)); + } + return (res); +} diff --git a/libc/inet/rpc/clnt_generic.c b/libc/inet/rpc/clnt_generic.c new file mode 100644 index 000000000..9124ccf16 --- /dev/null +++ b/libc/inet/rpc/clnt_generic.c @@ -0,0 +1,115 @@ +/* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI"; +#endif +/* + * Copyright (C) 1987, Sun Microsystems, Inc. + */ +#include +#include +#include +#include + +/* + * Generic client creation: takes (hostname, program-number, protocol) and + * returns client handle. Default options are set, which the user can + * change using the rpc equivalent of ioctl()'s. + */ +CLIENT * +clnt_create(hostname, prog, vers, proto) + char *hostname; + unsigned prog; + unsigned vers; + char *proto; +{ + struct hostent *h; + struct protoent *p; + struct sockaddr_in sin; + int sock; + struct timeval tv; + CLIENT *client; + + h = gethostbyname(hostname); + if (h == NULL) { + rpc_createerr.cf_stat = RPC_UNKNOWNHOST; + return (NULL); + } + if (h->h_addrtype != AF_INET) { + /* + * Only support INET for now + */ + rpc_createerr.cf_stat = RPC_SYSTEMERROR; + rpc_createerr.cf_error.re_errno = EAFNOSUPPORT; + return (NULL); + } +#ifdef linux + bzero((char *) &sin, sizeof(sin)); +#endif + sin.sin_family = h->h_addrtype; + sin.sin_port = 0; +#ifndef linux + bzero(sin.sin_zero, sizeof(sin.sin_zero)); +#endif + bcopy(h->h_addr, (char*)&sin.sin_addr, h->h_length); + p = getprotobyname(proto); + if (p == NULL) { + rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; + rpc_createerr.cf_error.re_errno = EPFNOSUPPORT; + return (NULL); + } + sock = RPC_ANYSOCK; + switch (p->p_proto) { + case IPPROTO_UDP: + tv.tv_sec = 5; + tv.tv_usec = 0; + client = clntudp_create(&sin, prog, vers, tv, &sock); + if (client == NULL) { + return (NULL); + } + tv.tv_sec = 25; + clnt_control(client, CLSET_TIMEOUT, &tv); + break; + case IPPROTO_TCP: + client = clnttcp_create(&sin, prog, vers, &sock, 0, 0); + if (client == NULL) { + return (NULL); + } + tv.tv_sec = 25; + tv.tv_usec = 0; + clnt_control(client, CLSET_TIMEOUT, &tv); + break; + default: + rpc_createerr.cf_stat = RPC_SYSTEMERROR; + rpc_createerr.cf_error.re_errno = EPFNOSUPPORT; + return (NULL); + } + return (client); +} diff --git a/libc/inet/rpc/clnt_perror.c b/libc/inet/rpc/clnt_perror.c new file mode 100644 index 000000000..80f51aa79 --- /dev/null +++ b/libc/inet/rpc/clnt_perror.c @@ -0,0 +1,310 @@ +/* @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro"; +#endif + +/* + * clnt_perror.c + * + * Copyright (C) 1984, Sun Microsystems, Inc. + * + */ +#include + +#include +#include +#include + +extern char *sys_errlist[]; +static char *auth_errmsg(); + +extern char *strcpy(); + +static char *buf; + +static char * +_buf() +{ + + if (buf == 0) + buf = (char *)malloc(256); + return (buf); +} + +/* + * Print reply error info + */ +char * +clnt_sperror(rpch, s) + CLIENT *rpch; + char *s; +{ +#if 0 + struct rpc_err e; + void clnt_perrno(); + char *err; + char *str = _buf(); + char *strstart = str; + + if (str == 0) + return (0); + CLNT_GETERR(rpch, &e); + + (void) sprintf(str, "%s: ", s); + str += strlen(str); + + (void) strcpy(str, clnt_sperrno(e.re_status)); + str += strlen(str); + + switch (e.re_status) { + case RPC_SUCCESS: + case RPC_CANTENCODEARGS: + case RPC_CANTDECODERES: + case RPC_TIMEDOUT: + case RPC_PROGUNAVAIL: + case RPC_PROCUNAVAIL: + case RPC_CANTDECODEARGS: + case RPC_SYSTEMERROR: + case RPC_UNKNOWNHOST: + case RPC_UNKNOWNPROTO: + case RPC_PMAPFAILURE: + case RPC_PROGNOTREGISTERED: + case RPC_FAILED: + break; + + case RPC_CANTSEND: + case RPC_CANTRECV: + (void) sprintf(str, "; errno = %s", + sys_errlist[e.re_errno]); + str += strlen(str); + break; + + case RPC_VERSMISMATCH: + (void) sprintf(str, + "; low version = %lu, high version = %lu", + e.re_vers.low, e.re_vers.high); + str += strlen(str); + break; + + case RPC_AUTHERROR: + err = auth_errmsg(e.re_why); + (void) sprintf(str,"; why = "); + str += strlen(str); + if (err != NULL) { + (void) sprintf(str, "%s",err); + } else { + (void) sprintf(str, + "(unknown authentication error - %d)", + (int) e.re_why); + } + str += strlen(str); + break; + + case RPC_PROGVERSMISMATCH: + (void) sprintf(str, + "; low version = %lu, high version = %lu", + e.re_vers.low, e.re_vers.high); + str += strlen(str); + break; + + default: /* unknown */ + (void) sprintf(str, + "; s1 = %lu, s2 = %lu", + e.re_lb.s1, e.re_lb.s2); + str += strlen(str); + break; + } + (void) sprintf(str, "\n"); + return(strstart) ; +#endif +} + +void +clnt_perror(rpch, s) + CLIENT *rpch; + char *s; +{ + (void) fprintf(stderr,"%s",clnt_sperror(rpch,s)); +} + + +struct rpc_errtab { + enum clnt_stat status; + char *message; +}; +#if 0 +static struct rpc_errtab rpc_errlist[] = { + { RPC_SUCCESS, + "RPC: Success" }, + { RPC_CANTENCODEARGS, + "RPC: Can't encode arguments" }, + { RPC_CANTDECODERES, + "RPC: Can't decode result" }, + { RPC_CANTSEND, + "RPC: Unable to send" }, + { RPC_CANTRECV, + "RPC: Unable to receive" }, + { RPC_TIMEDOUT, + "RPC: Timed out" }, + { RPC_VERSMISMATCH, + "RPC: Incompatible versions of RPC" }, + { RPC_AUTHERROR, + "RPC: Authentication error" }, + { RPC_PROGUNAVAIL, + "RPC: Program unavailable" }, + { RPC_PROGVERSMISMATCH, + "RPC: Program/version mismatch" }, + { RPC_PROCUNAVAIL, + "RPC: Procedure unavailable" }, + { RPC_CANTDECODEARGS, + "RPC: Server can't decode arguments" }, + { RPC_SYSTEMERROR, + "RPC: Remote system error" }, + { RPC_UNKNOWNHOST, + "RPC: Unknown host" }, + { RPC_UNKNOWNPROTO, + "RPC: Unknown protocol" }, + { RPC_PMAPFAILURE, + "RPC: Port mapper failure" }, + { RPC_PROGNOTREGISTERED, + "RPC: Program not registered"}, + { RPC_FAILED, + "RPC: Failed (unspecified error)"} +}; +#endif + +/* + * This interface for use by clntrpc + */ +char * +clnt_sperrno(stat) + enum clnt_stat stat; +{ +#if 0 + int i; + + for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) { + if (rpc_errlist[i].status == stat) { + return (rpc_errlist[i].message); + } + } +#endif + return ("RPC: (unknown error code)"); +} + +void +clnt_perrno(num) + enum clnt_stat num; +{ + (void) fprintf(stderr,"%s",clnt_sperrno(num)); +} + + +char * +clnt_spcreateerror(s) + char *s; +{ +#if 0 + extern int sys_nerr; + extern char *sys_errlist[]; + char *str = _buf(); + + if (str == 0) + return(0); + (void) sprintf(str, "%s: ", s); + (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat)); + switch (rpc_createerr.cf_stat) { + case RPC_PMAPFAILURE: + (void) strcat(str, " - "); + (void) strcat(str, + clnt_sperrno(rpc_createerr.cf_error.re_status)); + break; + + case RPC_SYSTEMERROR: + (void) strcat(str, " - "); + if (rpc_createerr.cf_error.re_errno > 0 + && rpc_createerr.cf_error.re_errno < sys_nerr) + (void) strcat(str, + sys_errlist[rpc_createerr.cf_error.re_errno]); + else + (void) sprintf(&str[strlen(str)], "Error %d", + rpc_createerr.cf_error.re_errno); + break; + } + (void) strcat(str, "\n"); + return (str); +#endif +} + +void +clnt_pcreateerror(s) + char *s; +{ + (void) fprintf(stderr,"%s",clnt_spcreateerror(s)); +} + +struct auth_errtab { + enum auth_stat status; + char *message; +}; + +static struct auth_errtab auth_errlist[] = { + { AUTH_OK, + "Authentication OK" }, + { AUTH_BADCRED, + "Invalid client credential" }, + { AUTH_REJECTEDCRED, + "Server rejected credential" }, + { AUTH_BADVERF, + "Invalid client verifier" }, + { AUTH_REJECTEDVERF, + "Server rejected verifier" }, + { AUTH_TOOWEAK, + "Client credential too weak" }, + { AUTH_INVALIDRESP, + "Invalid server verifier" }, + { AUTH_FAILED, + "Failed (unspecified error)" }, +}; + +static char * +auth_errmsg(stat) + enum auth_stat stat; +{ + int i; + + for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) { + if (auth_errlist[i].status == stat) { + return(auth_errlist[i].message); + } + } + return(NULL); +} diff --git a/libc/inet/rpc/clnt_raw.c b/libc/inet/rpc/clnt_raw.c new file mode 100644 index 000000000..89059ae2d --- /dev/null +++ b/libc/inet/rpc/clnt_raw.c @@ -0,0 +1,238 @@ +/* @(#)clnt_raw.c 2.2 88/08/01 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro"; +#endif + +/* + * clnt_raw.c + * + * Copyright (C) 1984, Sun Microsystems, Inc. + * + * Memory based rpc for simple testing and timing. + * Interface to create an rpc client and server in the same process. + * This lets us similate rpc and get round trip overhead, without + * any interference from the kernal. + */ + +#include + +#define MCALL_MSG_SIZE 24 + +/* + * This is the "network" we will be moving stuff over. + */ +static struct clntraw_private { + CLIENT client_object; + XDR xdr_stream; + char _raw_buf[UDPMSGSIZE]; + char mashl_callmsg[MCALL_MSG_SIZE]; + u_int mcnt; +} *clntraw_private; + +static enum clnt_stat clntraw_call(); +static void clntraw_abort(); +static void clntraw_geterr(); +static bool_t clntraw_freeres(); +static bool_t clntraw_control(); +static void clntraw_destroy(); + +static struct clnt_ops client_ops = { + clntraw_call, + clntraw_abort, + clntraw_geterr, + clntraw_freeres, + clntraw_destroy, + clntraw_control +}; + +void svc_getreq(); + +/* + * Create a client handle for memory based rpc. + */ +CLIENT * +clntraw_create(prog, vers) + u_long prog; + u_long vers; +{ + register struct clntraw_private *clp = clntraw_private; + struct rpc_msg call_msg; + XDR *xdrs = &clp->xdr_stream; + CLIENT *client = &clp->client_object; + + if (clp == 0) { + clp = (struct clntraw_private *)calloc(1, sizeof (*clp)); + if (clp == 0) + return (0); + clntraw_private = clp; + } + /* + * pre-serialize the staic part of the call msg and stash it away + */ + call_msg.rm_direction = CALL; + call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; + call_msg.rm_call.cb_prog = prog; + call_msg.rm_call.cb_vers = vers; + xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE); + if (! xdr_callhdr(xdrs, &call_msg)) { + perror("clnt_raw.c - Fatal header serialization error."); + } + clp->mcnt = XDR_GETPOS(xdrs); + XDR_DESTROY(xdrs); + + /* + * Set xdrmem for client/server shared buffer + */ + xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE); + + /* + * create client handle + */ + client->cl_ops = &client_ops; + client->cl_auth = authnone_create(); + return (client); +} + +static enum clnt_stat +clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout) + CLIENT *h; + u_long proc; + xdrproc_t xargs; + caddr_t argsp; + xdrproc_t xresults; + caddr_t resultsp; + struct timeval timeout; +{ + register struct clntraw_private *clp = clntraw_private; + register XDR *xdrs = &clp->xdr_stream; + struct rpc_msg msg; + enum clnt_stat status; + struct rpc_err error; + + if (clp == 0) + return (RPC_FAILED); +call_again: + /* + * send request + */ + xdrs->x_op = XDR_ENCODE; + XDR_SETPOS(xdrs, 0); + ((struct rpc_msg *)clp->mashl_callmsg)->rm_xid ++ ; + if ((! XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) || + (! XDR_PUTLONG(xdrs, (long *)&proc)) || + (! AUTH_MARSHALL(h->cl_auth, xdrs)) || + (! (*xargs)(xdrs, argsp))) { + return (RPC_CANTENCODEARGS); + } + (void)XDR_GETPOS(xdrs); /* called just to cause overhead */ + + /* + * We have to call server input routine here because this is + * all going on in one process. Yuk. + */ + svc_getreq(1); + + /* + * get results + */ + xdrs->x_op = XDR_DECODE; + XDR_SETPOS(xdrs, 0); + msg.acpted_rply.ar_verf = _null_auth; + msg.acpted_rply.ar_results.where = resultsp; + msg.acpted_rply.ar_results.proc = xresults; + if (! xdr_replymsg(xdrs, &msg)) + return (RPC_CANTDECODERES); + _seterr_reply(&msg, &error); + status = error.re_status; + + if (status == RPC_SUCCESS) { + if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) { + status = RPC_AUTHERROR; + } + } /* end successful completion */ + else { + if (AUTH_REFRESH(h->cl_auth)) + goto call_again; + } /* end of unsuccessful completion */ + + if (status == RPC_SUCCESS) { + if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) { + status = RPC_AUTHERROR; + } + if (msg.acpted_rply.ar_verf.oa_base != NULL) { + xdrs->x_op = XDR_FREE; + (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf)); + } + } + + return (status); +} + +static void +clntraw_geterr() +{ +} + + +static bool_t +clntraw_freeres(cl, xdr_res, res_ptr) + CLIENT *cl; + xdrproc_t xdr_res; + caddr_t res_ptr; +{ + register struct clntraw_private *clp = clntraw_private; + register XDR *xdrs = &clp->xdr_stream; + bool_t rval; + + if (clp == 0) + { + rval = (bool_t) RPC_FAILED; + return (rval); + } + xdrs->x_op = XDR_FREE; + return ((*xdr_res)(xdrs, res_ptr)); +} + +static void +clntraw_abort() +{ +} + +static bool_t +clntraw_control() +{ + return (FALSE); +} + +static void +clntraw_destroy() +{ +} diff --git a/libc/inet/rpc/clnt_simple.c b/libc/inet/rpc/clnt_simple.c new file mode 100644 index 000000000..043ce0a3e --- /dev/null +++ b/libc/inet/rpc/clnt_simple.c @@ -0,0 +1,112 @@ +/* @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro"; +#endif + +/* + * clnt_simple.c + * Simplified front end to rpc. + * + * Copyright (C) 1984, Sun Microsystems, Inc. + */ + +#include +#include +#include +#include +#include + +static struct callrpc_private { + CLIENT *client; + int socket; + int oldprognum, oldversnum, valid; + char *oldhost; +} *callrpc_private; + +callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) + char *host; + xdrproc_t inproc, outproc; + char *in, *out; +{ + register struct callrpc_private *crp = callrpc_private; + struct sockaddr_in server_addr; + enum clnt_stat clnt_stat; + struct hostent *hp; + struct timeval timeout, tottimeout; + + if (crp == 0) { + crp = (struct callrpc_private *)calloc(1, sizeof (*crp)); + if (crp == 0) + return (0); + callrpc_private = crp; + } + if (crp->oldhost == NULL) { + crp->oldhost = malloc(256); + crp->oldhost[0] = 0; + crp->socket = RPC_ANYSOCK; + } + if (crp->valid && crp->oldprognum == prognum && crp->oldversnum == versnum + && strcmp(crp->oldhost, host) == 0) { + /* reuse old client */ + } else { + crp->valid = 0; + (void)close(crp->socket); + crp->socket = RPC_ANYSOCK; + if (crp->client) { + clnt_destroy(crp->client); + crp->client = NULL; + } + if ((hp = gethostbyname(host)) == NULL) + return ((int) RPC_UNKNOWNHOST); + timeout.tv_usec = 0; + timeout.tv_sec = 5; + bcopy(hp->h_addr, (char *)&server_addr.sin_addr, hp->h_length); + server_addr.sin_family = AF_INET; + server_addr.sin_port = 0; + if ((crp->client = clntudp_create(&server_addr, (u_long)prognum, + (u_long)versnum, timeout, &crp->socket)) == NULL) + return ((int) rpc_createerr.cf_stat); + crp->valid = 1; + crp->oldprognum = prognum; + crp->oldversnum = versnum; + (void) strcpy(crp->oldhost, host); + } + tottimeout.tv_sec = 25; + tottimeout.tv_usec = 0; + clnt_stat = clnt_call(crp->client, procnum, inproc, in, + outproc, out, tottimeout); + /* + * if call failed, empty cache + */ + if (clnt_stat != RPC_SUCCESS) + crp->valid = 0; + return ((int) clnt_stat); +} diff --git a/libc/inet/rpc/clnt_tcp.c b/libc/inet/rpc/clnt_tcp.c new file mode 100644 index 000000000..2222bc657 --- /dev/null +++ b/libc/inet/rpc/clnt_tcp.c @@ -0,0 +1,466 @@ +/* @(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC */ +/* + * Sun RPC is a product of Sun Microsystems, Inc. and is provided for + * unrestricted use provided that this legend is included on all tape + * media and as a part of the software program in whole or part. Users + * may copy or modify Sun RPC without charge, but are not authorized + * to license or distribute it to anyone else except as part of a product or + * program developed by the user. + * + * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE + * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. + * + * Sun RPC is provided with no support and without any obligation on the + * part of Sun Microsystems, Inc. to assist in its use, correction, + * modification or enhancement. + * + * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE + * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC + * OR ANY PART THEREOF. + * + * In no event will Sun Microsystems, Inc. be liable for any lost revenue + * or profits or other special, indirect and consequential damages, even if + * Sun has been advised of the possibility of such damages. + * + * Sun Microsystems, Inc. + * 2550 Garcia Avenue + * Mountain View, California 94043 + */ +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro"; +#en