OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / deamon / drd64_marshald_connect_debugd.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
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.
16
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.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_MARSHALD_CONNECT_DEBUGD
38 #include"drd64_marshald.h"
39
40
41 /*----------------------------------------------------------------------
42 ----------------------------------------------------------------------*/
43 EXTERN_MARSHALD_CONNECT_DEBUGD
44 Drd64_Marshald_ConnectInfo *
45         Drd64_Marshald_Connect_Debugd(
46                 char    *pstr_socketname_debugd,
47                 int             i_prog_pid,
48                 int             i_debugd_pid )
49 {
50         int                                                     i_socket;
51         Drd64_Marshald_ConnectInfo      *p_cinfo;
52         Drd64_Server_RecvStatus         *p_recv;
53
54         DRD64_LOG_DEBUG("  [DEBUG]SEND: Connect Cmd (for Debugd) Start");
55
56         /* Phase 1 : Check Exist Same-Connection */
57         p_cinfo = Drd64_Marshald_Search_DebugdConnection( i_prog_pid );
58         if( NULL != p_cinfo )   {
59                 p_cinfo->i_cinfo_refcount++;
60                 
61                 DRD64_LOG_DEBUG("  [DEBUG]SEND: Connect Cmd (for Debugd) Exit");
62         }
63         else    {
64                 /* Phase 3 : Create INet-Marshald Socket ------*/
65                 i_socket = Drd64_LibBrownie_Socket_InitSocketClient_Local(
66                                                                 pstr_socketname_debugd );
67                 if( 0 > i_socket )      { return NULL; }
68
69                 p_recv = Drd64_Server_RecvStatus_AllocRecvStatus(
70                                                 i_socket, DRD64_MARSHALD_RECVSTATUS_UNITS );
71                 if( NULL == p_recv )    { return NULL; }
72
73                 Drd64_Marshald_Dispatch_SetFD( i_socket );
74                 Drd64_Server_RecvStatus_InitRecvStatus( p_recv, i_socket );
75                 Drd64_Server_RecvStatus_AddSocketsChain( p_recv );
76
77                 /* Phase 2 : Init & Set Packet Data ----------*/
78                 p_cinfo = Drd64_Marshald_CInfo_AllocConnectInfo();
79                 if( NULL == p_cinfo )   { return NULL; }
80
81                 /* Phase 5 : Set Cinfo Data ------------------*/
82                 p_cinfo->b_cinfo_type                   = DRD64_MARSHALD_CINFOTYPE_DEBUGD;
83                 p_cinfo->i_cinfo_refcount               = 1;
84
85                 Drd64_LibBrownie_INetAddr_SetInAddr_LocalHost(
86                                                         &(p_cinfo->t_dest_addr_inet) );
87                 p_cinfo->i_dest_cinfo_id                = -1;
88                 p_cinfo->i_dest_socket                  = i_socket;
89                 strncpy( p_cinfo->str_dest_addr_local,
90                                         pstr_socketname_debugd, DRD64_MAX_PATH );
91
92                 /* p_cinfo->t_src_addr_inet             = NONE */
93                 p_cinfo->i_src_cinfo_id                 = -1;
94                 p_cinfo->i_src_socket                   = -1;
95
96                 /* t_prog_addr_inet                     = NONE */
97                 p_cinfo->i_prog_pid                             = i_prog_pid;
98
99                 p_cinfo->i_debugd_pid                   = i_debugd_pid;
100                 p_cinfo->i_debugd_socket                = i_socket;
101
102                 /* p_cinfo->t_client_addr_inet  = NONE */
103                 p_cinfo->i_client_socket                = -1;
104                 p_cinfo->i_client_pid                   = -1;
105
106                 Drd64_Server_RecvStatus_SetConnectionInfoPointer(
107                                                                         p_recv, (void *)p_cinfo );
108
109                 DRD64_LOG_DEBUG("  [DEBUG]SEND: Connect Cmd (for Debugd) Ended");
110         }
111
112         return p_cinfo;
113 }
114
115
116 /* EOF of drd64_.c ----------------------------------- */