comparison src/g23m-fad/tcpip/rnet/rnet_rt/rnet_rt_api_gethostinfo.c @ 1:d393cd9bb723

src/g23m-*: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
0:b6a5e36de839 1:d393cd9bb723
1 /**
2 * @file rnet_rt_api_gethostinfo.c
3 *
4 * RNET_RT API
5 *
6 * @author Regis Feneon
7 * @version 0.1
8 */
9
10 /*
11 * $Id: rnet_rt_api_gethostinfo.c,v 1.5 2002/10/30 15:23:34 rf Exp $
12 * $Name: ti_20021030 $
13 *
14 * History:
15 *
16 * Date Author Modification
17 * --------------------------------------------------
18 * 3/22/2002 Regis Feneon Create
19 * 4/4/2002 Regis Feneon implementation
20 *
21 * (C) Copyright 2002 by TI, All Rights Reserved
22 *
23 */
24
25 #include "rnet_cfg.h"
26 #ifdef RNET_CFG_REAL_TRANSPORT
27
28 #include "rnet_rt_i.h"
29 #include "rnet_rt_env.h"
30 #include "rnet_message.h"
31 #include "tcpip_int.h"
32
33 /*
34 * Resolver asynchronous callback.
35 * Called by the resolver when a query is completed,
36 * a message with the result is sent back to the application.
37 */
38
39 static void gethost_cb( int code, T_RNET_RT_GETHOSTINFO *data_p)
40 {
41 T_RNET_HOST_INFO msg ;
42 T_RNET_HOST_INFO *msg_p = &msg ;
43 T_RNET_IP_ADDR addr;
44
45 #if 0
46 /* allocate message for reply */
47 msg_p = NULL;
48 if( rvf_get_msg_buf( rnet_rt_env_ctrl_blk_p->mb_id, sizeof( T_RNET_HOST_INFO),
49 RNET_HOST_INFO, (T_RV_HDR **) &msg_p) == RVF_RED) {
50 RNET_RT_SEND_TRACE("RNET_RT: get_host_info: cannot allocate MSG",
51 RV_TRACE_LEVEL_ERROR);
52 }
53 else {
54 #endif /* 0 */
55 /* prepare message */
56 if( code == NG_EDNS_OK) {
57 /* get address, convert to host-byte order */
58 memcpy( &addr, data_p->hostent.h_addr_list[0], sizeof(T_RNET_IP_ADDR));
59 msg_p->host_addr = ngNTOHL( addr);
60 /* get full name */
61 strncpy( msg_p->host_name, data_p->hostent.h_name,
62 RNET_MAX_HOST_NAME_LEN-1);
63 /* null-terminate host_name */
64 msg_p->host_name[RNET_MAX_HOST_NAME_LEN-1] = 0;
65 msg_p->error = RNET_OK;
66 }
67 else {
68 /* host not found... */
69 msg_p->host_addr = RNET_IP_ADDR_ANY;
70 msg_p->host_name[0] = 0;
71 switch( code) {
72 case NG_EDNS_HOST_NOT_FOUND:
73 case NG_EDNS_NO_ADDRESS:
74 case NG_EDNS_NO_RECOVERY:
75 case NG_EDNS_TRY_AGAIN:
76 msg_p->error = RNET_HOST_NOT_FOUND;
77 break;
78 case NG_EDNS_PROTO_SHUTDOWN:
79 msg_p->error = RNET_NOT_READY;
80 break;
81 case NG_EDNS_TIMEDOUT:
82 msg_p->error = RNET_TIMEOUT;
83 break;
84 default:
85 msg_p->error = rnet_rt_ngip_error( code);
86 break;
87 }
88 }
89 msg_p->user_data = data_p->user_data;
90 tcpip_hostinfo_callback(msg_p) ;
91 #if 0
92 if( data_p->return_path.callback_func != NULL) {
93 /* Send the message using callback function. */
94 data_p->return_path.callback_func( msg_p);
95 }
96 else {
97 /* Send the message using mailbox. */
98 rvf_send_msg( data_p->return_path.addr_id, (T_RV_HDR *) msg_p);
99 }
100 }
101 #endif /* 0 */
102
103 /* release data buffer */
104 /* PatternVibrator("o20f10", 1); */
105 rvf_free_buf( data_p);
106 /* PatternVibrator("o20f10", 0); */
107 return;
108 }
109
110 /**
111 * Requests host information corresponding to a host name or to a
112 * network address.
113 *
114 * One of the two parameters name or addr must be NULL.
115 *
116 * This function is bridge function sending a corresponding message to RNET.
117 * The message RNET_HOST_INFO is sent back when the requested information
118 * is available.
119 *
120 * Note that this function does not need a connection identifier and specifies
121 * its own return path.
122 *
123 * @param name Name of the host to resolve [IN].
124 * @param addr Network address [IN].
125 * @param return_path Return path for sending the response.
126 * @return RNET_MEMORY_ERR Not enough memory is available.
127 * RNET_OK The message could be correctly send.
128 */
129 T_RNET_RET rnet_rt_get_host_info (char *name,
130 T_RNET_IP_ADDR addr,
131 T_RV_RETURN_PATH return_path,
132 void * user_data)
133 {
134 T_RNET_RT_GETHOSTINFO *data_p;
135 T_RNET_IP_ADDR naddr;
136 int err;
137
138 /* check if SW entity has been initialised */
139 if( rnet_rt_env_ctrl_blk_p == NULL) {
140 return( RNET_NOT_INITIALIZED);
141 }
142
143 if( ((name == NULL) && (addr == RNET_IP_ADDR_ANY)) ||
144 ((name != NULL) && (addr != RNET_IP_ADDR_ANY))) {
145 return( RNET_INVALID_PARAMETER);
146 }
147
148 /* allocate callback data */
149 if( rvf_get_buf( rnet_rt_env_ctrl_blk_p->mb_id,
150 sizeof( T_RNET_RT_GETHOSTINFO), (T_RVF_BUFFER **)&data_p) == RVF_RED) {
151 RNET_RT_SEND_TRACE("RNET_RT: get_host_info: cannot allocate data ",
152 RV_TRACE_LEVEL_WARNING);
153 return( RNET_MEMORY_ERR);
154 }
155
156 /* save return path and user data */
157 data_p->return_path = return_path;
158 data_p->user_data = user_data;
159
160 /* send query */
161 if( name == NULL) {
162 naddr = ngHTONL( addr);
163 rvf_lock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
164
165 err = ngResolvByAddrAsync( NG_AF_INET,
166 (void *) naddr, /* XXX bug in ngresolv XXX */
167 &data_p->hostent,
168 data_p->tmpbuf,
169 RNET_RT_NGIP_GETHOSTINFO_BUFMAX,
170 0,
171 (NGslv_cb_f) gethost_cb,
172 data_p);
173 rvf_unlock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
174 }
175 else {
176 rvf_lock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
177 err = ngResolvByNameAsync( NG_AF_INET,
178 name,
179 &data_p->hostent,
180 data_p->tmpbuf,
181 RNET_RT_NGIP_GETHOSTINFO_BUFMAX,
182 0,
183 (NGslv_cb_f) gethost_cb,
184 data_p);
185 rvf_unlock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
186 }
187
188 switch( err) {
189 case NG_EDNS_WOULDBLOCK:
190 /* message will be sent later */
191 return( RNET_OK);
192 case NG_EDNS_OK:
193 case NG_EDNS_HOST_NOT_FOUND:
194 case NG_EDNS_NO_ADDRESS:
195 case NG_EDNS_NO_RECOVERY:
196 case NG_EDNS_TIMEDOUT:
197 case NG_EDNS_TRY_AGAIN:
198 /* entry was in cache, send message now */
199 gethost_cb( err, data_p);
200 return( RNET_OK);
201 case NG_EDNS_PROTO_SHUTDOWN:
202 /* invalid configuration */
203 RNET_RT_SEND_TRACE("RNET_RT: get_host_info: invalid configuration.",
204 RV_TRACE_LEVEL_WARNING);
205 err = RNET_NOT_READY;
206 break;
207 default:
208 RNET_RT_SEND_TRACE("RNET_RT: get_host_info: default used.",
209 RV_TRACE_LEVEL_WARNING);
210 err = rnet_rt_ngip_error( err);
211 break;
212 }
213 /* release buffer and return error code */
214 rvf_free_buf( data_p);
215 return((T_RNET_RET)err);
216 }
217
218 #endif /* ifdef RNET_CFG_REAL_TRANSPORT */
219