1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 */ 9 /* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */ 10 /* 11 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 12 * unrestricted use provided that this legend is included on all tape 13 * media and as a part of the software program in whole or part. Users 14 * may copy or modify Sun RPC without charge, but are not authorized 15 * to license or distribute it to anyone else except as part of a product or 16 * program developed by the user. 17 * 18 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 19 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 20 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 21 * 22 * Sun RPC is provided with no support and without any obligation on the 23 * part of Sun Microsystems, Inc. to assist in its use, correction, 24 * modification or enhancement. 25 * 26 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 27 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 28 * OR ANY PART THEREOF. 29 * 30 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 31 * or profits or other special, indirect and consequential damages, even if 32 * Sun has been advised of the possibility of such damages. 33 * 34 * Sun Microsystems, Inc. 35 * 2550 Garcia Avenue 36 * Mountain View, California 94043 37 */ 38 #if !defined(lint) && defined(SCCSIDS) 39 static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI"; 40 #endif 41 /* 42 * Copyright (C) 1987, Sun Microsystems, Inc. 43 */ 44 #include <rpc/rpc.h> 45 #include <string.h> 46 47 /* 48 * Generic client creation: takes (hostname, program-number, protocol) and 49 * returns client handle. Default options are set, which the user can 50 * change using the rpc equivalent of ioctl()'s. 51 */ 52 CLIENT *clnt_create(const char *hostname, const unsigned long prog, 53 const unsigned long vers, const char *proto) 54 { 55 int sock; 56 struct sockaddr_in server; 57 struct addrinfo hint, *res = NULL; 58 struct timeval tv; 59 CLIENT *client; 60 int ret; 61 62 memset(&hint, 0, sizeof(hint)); 63 ret = getaddrinfo(hostname, NULL, &hint, &res); 64 if (ret != 0) 65 { 66 rt_kprintf("getaddrinfo err: %d '%s'\n", ret, hostname); 67 return NULL; 68 } 69 70 memcpy(&server, res->ai_addr, sizeof(struct sockaddr_in)); 71 freeaddrinfo(res); 72 73 sock = -1; 74 if (strcmp(proto, "udp") == 0) 75 { 76 tv.tv_sec = 5; 77 tv.tv_usec = 0; 78 client = clntudp_create(&server, prog, vers, tv, &sock); 79 if (client == NULL) return NULL; 80 tv.tv_sec = 1; 81 clnt_control(client, CLSET_TIMEOUT, (char *)&tv); 82 } 83 else 84 { 85 rt_kprintf("unknow protocol\n"); 86 return NULL; 87 } 88 89 return (client); 90 } 91 92 void clnt_perror(CLIENT *rpch, const char *s) 93 { 94 rt_kprintf("rpc client error:%s\n", s); 95 } 96