|
@@ -53,7 +53,9 @@ clnt_create (const char *hostname, u_long prog, u_long vers,
|
|
|
struct hostent hostbuf, *h;
|
|
|
size_t hstbuflen;
|
|
|
char *hsttmpbuf;
|
|
|
- struct protoent *p;
|
|
|
+ struct protoent protobuf, *p;
|
|
|
+ size_t prtbuflen;
|
|
|
+ char *prttmpbuf;
|
|
|
struct sockaddr_in sin;
|
|
|
struct sockaddr_un sun;
|
|
|
int sock;
|
|
@@ -113,14 +115,23 @@ clnt_create (const char *hostname, u_long prog, u_long vers,
|
|
|
memset (sin.sin_zero, 0, sizeof (sin.sin_zero));
|
|
|
memcpy ((char *) &sin.sin_addr, h->h_addr, h->h_length);
|
|
|
|
|
|
-#warning getprotobyname is not reentrant... Add getprotobyname_r
|
|
|
- p = getprotobyname(proto);
|
|
|
- if (p == NULL) {
|
|
|
- struct rpc_createerr *ce = &get_rpc_createerr ();
|
|
|
- ce->cf_stat = RPC_UNKNOWNPROTO;
|
|
|
- ce->cf_error.re_errno = EPFNOSUPPORT;
|
|
|
- return NULL;
|
|
|
- }
|
|
|
+ prtbuflen = 1024;
|
|
|
+ prttmpbuf = alloca (prtbuflen);
|
|
|
+ while (getprotobyname_r (proto, &protobuf, prttmpbuf, prtbuflen, &p) != 0
|
|
|
+ || p == NULL)
|
|
|
+ if (errno != ERANGE)
|
|
|
+ {
|
|
|
+ struct rpc_createerr *ce = &get_rpc_createerr ();
|
|
|
+ ce->cf_stat = RPC_UNKNOWNPROTO;
|
|
|
+ ce->cf_error.re_errno = EPFNOSUPPORT;
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ prtbuflen *= 2;
|
|
|
+ prttmpbuf = alloca (prtbuflen);
|
|
|
+ }
|
|
|
|
|
|
sock = RPC_ANYSOCK;
|
|
|
switch (p->p_proto)
|