1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_MARSHALD_CINFO
38 #include"drd64_marshald.h"
40 Drd64_Marshald_ConnectInfo *gp_marshald_cinfo;
41 int gi_marshald_cinfo_max;
42 int gi_marshald_cinfo_now;
46 Drd64_Marshald_ConnectInfo *
47 Drd64_Marshald_SearchINetConnection(
48 struct in_addr *p_addr )
51 Drd64_Marshald_ConnectInfo *p_cinfo;
55 for( i_cnt = 0; i_cnt < gi_marshald_cinfo_now; i_cnt++ ) {
56 p_cinfo = (gp_marshald_cinfo + i_cnt);
58 if( -1 == p_cinfo->i_cinfo_id ) { continue; }
61 if( DRD64_MARSHALD_CINFOTYPE_CLIENT
62 == p_cinfo->b_cinfo_type ) {
63 if( 0x00 == Drd64_LibBrownie_INetAddr_CmpInAddr(
64 p_addr, &(p_cinfo->t_dest_addr_inet)) )
68 else if( DRD64_MARSHALD_CINFOTYPE_SERVER
69 == p_cinfo->b_cinfo_type ) {
70 if( 0x00 == Drd64_LibBrownie_INetAddr_CmpInAddr(
71 p_addr, &(p_cinfo->t_src_addr_inet)) )
81 Drd64_Marshald_ConnectInfo *
82 Drd64_Marshald_Search_DebugdConnection(
86 Drd64_Marshald_ConnectInfo *p_cinfo;
90 for( i_cnt = 0; i_cnt < gi_marshald_cinfo_now; i_cnt++ ) {
91 p_cinfo = (gp_marshald_cinfo + i_cnt);
93 if( -1 == p_cinfo->i_cinfo_id ) { continue; }
95 if( DRD64_MARSHALD_CINFOTYPE_DEBUGD
96 == p_cinfo->b_cinfo_type ) {
97 if( i_prog_pid == p_cinfo->i_prog_pid )
106 EXTERN_MARSHALD_CINFO
107 Drd64_Marshald_ConnectInfo *
108 Drd64_Marshald_CInfo_GetConnectInfo(
111 if(( 0 > i_cinfo_id ) || ( gi_marshald_cinfo_max < i_cinfo_id ))
113 return (gp_marshald_cinfo + i_cinfo_id);
118 EXTERN_MARSHALD_CINFO
119 Drd64_Marshald_ConnectInfo *
120 Drd64_Marshald_CInfo_AllocConnectInfo(
125 Drd64_Marshald_ConnectInfo *p_cinfo_temp;
126 Drd64_Marshald_ConnectInfo *p_cinfo_now;
131 if( gi_marshald_cinfo_now == gi_marshald_cinfo_max ) {
132 for( i_cnt = 0; i_cnt < gi_marshald_cinfo_max; i_cnt++ ) {
133 p_cinfo_temp = gp_marshald_cinfo + i_cnt;
135 if( -1 == p_cinfo_temp->i_cinfo_id ) {
136 i_cinfo_newid = i_cnt;
141 if( -1 == i_cinfo_newid ) {
143 = (Drd64_Marshald_ConnectInfo *)
144 realloc( gp_marshald_cinfo,
145 sizeof( Drd64_Marshald_ConnectInfo )
146 * ( gi_marshald_cinfo_max
147 + DRD64_MARSHALD_CINFO_UNITS) );
148 if( NULL == p_cinfo_temp ) { return NULL; }
150 gp_marshald_cinfo = p_cinfo_temp;
151 gi_marshald_cinfo_max += DRD64_MARSHALD_CINFO_UNITS;
152 i_cinfo_newid = gi_marshald_cinfo_now++;
156 i_cinfo_newid = gi_marshald_cinfo_now++;
159 if( -1 != i_cinfo_newid ) {
160 p_cinfo_now = gp_marshald_cinfo + i_cinfo_newid;
162 memset( p_cinfo_now, 0x00, sizeof( Drd64_Marshald_ConnectInfo ) );
163 p_cinfo_now->i_cinfo_id = i_cinfo_newid;
164 p_cinfo_now->i_dest_cinfo_id = DRD64_CONNECTID_NONE;
165 p_cinfo_now->i_dest_socket = -1;
166 p_cinfo_now->p_dest_cinfo_connection = NULL;
167 p_cinfo_now->i_src_cinfo_id = DRD64_CONNECTID_NONE;
168 p_cinfo_now->i_src_socket = -1;
169 p_cinfo_now->p_src_cinfo_connection = NULL;
170 p_cinfo_now->i_debugd_socket = -1;
171 p_cinfo_now->i_client_socket = -1;
179 EXTERN_MARSHALD_CINFO
181 Drd64_Marshald_Cinfo_FreeConnectInfo(
182 Drd64_Marshald_ConnectInfo *p_cinfo )
185 Drd64_Marshald_ConnectInfo *p_cinfo_temp;
187 if( NULL == p_cinfo ) { return 0x01; }
189 //if( p_cinfo->i_cinfo_id + 1 == gi_marshald_cinfo_now )
190 //{ gi_marshald_cinfo_now--; }
191 for( i_cnt = gi_marshald_cinfo_now - 1; i_cnt >= 0 ; i_cnt-- ) {
192 p_cinfo_temp = (gp_marshald_cinfo + i_cnt);
193 assert( NULL != p_cinfo_temp );
195 if( -1 < p_cinfo_temp->i_cinfo_id ) { break; }
198 gi_marshald_cinfo_now = i_cnt + 1;
199 p_cinfo->i_cinfo_id = -1;
205 EXTERN_MARSHALD_CINFO
207 Drd64_Marshald_CInfo_InitConnectInfo(
212 = (Drd64_Marshald_ConnectInfo *)malloc(
213 sizeof( Drd64_Marshald_ConnectInfo )
214 * DRD64_MARSHALD_CINFO_UNITS );
216 if( NULL == gp_marshald_cinfo ) {
220 memset( gp_marshald_cinfo, 0x00,
221 sizeof( Drd64_Marshald_ConnectInfo )
222 * DRD64_MARSHALD_CINFO_UNITS );
224 gi_marshald_cinfo_max = DRD64_MARSHALD_CINFO_UNITS;
225 gi_marshald_cinfo_now = 0;
231 EXTERN_MARSHALD_CINFO
233 Drd64_Marshald_CInfo_TermConnectInfo(
236 if( NULL != gp_marshald_cinfo ) {
237 free( gp_marshald_cinfo );
238 gp_marshald_cinfo = NULL;
241 gi_marshald_cinfo_max = DRD64_MARSHALD_CINFO_UNITS;
242 gi_marshald_cinfo_now = 0;
248 /* EOF of drd64_.c ----------------------------------- */