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 #include"drd64_libdrd64.h"
42 struct cmsgcred t_cred;
43 } Drd64_Server_SendCMsg;
45 Drd64_Server_SendCMsg gt_sendmsg_cmsg;
46 struct msghdr gt_sendmsg_msghdr;
47 struct iovec gt_sendmsg_iovec;
51 Drd64_LibDrd64_Socket_InitSendBuffer(
54 struct cmsghdr *p_cmsghdr;
56 memset( >_sendmsg_cmsg, 0x00,
57 sizeof( struct cmsghdr ) + sizeof( struct cmsgcred ) );
58 memset( >_sendmsg_msghdr, 0x00, sizeof( struct msghdr ) );
60 p_cmsghdr = (struct cmsghdr *)>_sendmsg_cmsg;
61 p_cmsghdr->cmsg_len = sizeof( struct cmsghdr )
62 + sizeof( struct cmsgcred );
63 p_cmsghdr->cmsg_level = SOL_SOCKET;
64 p_cmsghdr->cmsg_type = SCM_CREDS;
66 gt_sendmsg_msghdr.msg_name = NULL;
67 gt_sendmsg_msghdr.msg_namelen = 0;
68 gt_sendmsg_msghdr.msg_iov = >_sendmsg_iovec;
69 gt_sendmsg_msghdr.msg_iovlen = 1;
70 gt_sendmsg_msghdr.msg_control = (caddr_t)>_sendmsg_cmsg;
71 gt_sendmsg_msghdr.msg_controllen
72 = sizeof( struct cmsghdr ) + sizeof( struct cmsgcred );
79 Drd64_LibDrd64_Socket_Send_Cert(
84 gt_sendmsg_iovec.iov_base = pv_data;
85 gt_sendmsg_iovec.iov_len = i_wsize;
87 return sendmsg( i_socket, >_sendmsg_msghdr, 0x00 );
92 Drd64_LibDrd64_Socket_InitSocket_Local(
93 const char *pstr_socket )
97 struct sockaddr_un t_sun;
99 i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 );
100 if( -1 == i_socket ) { return -1; }
102 t_sun.sun_family = AF_UNIX;
103 strcpy( t_sun.sun_path, pstr_socket );
105 i_err = connect( i_socket, &t_sun, SUN_LEN( &t_sun ));
106 if( -1 == i_err ) { return -2; }
113 Drd64_LibDrd64_Socket_ReadSocket(
126 struct timeval t_wait;
131 FD_ZERO( &t_fds_socket );
132 FD_SET( i_socket, &t_fds_socket );
135 t_wait.tv_sec = i_wait;
139 memcpy( &t_fds_temp, &t_fds_socket, sizeof( fd_set ) );
142 i_err = select( i_socket+1, &t_fds_temp, NULL, NULL, &t_wait );
146 } else if ( 0 == i_err ) {
151 if( FD_ISSET( i_socket, &t_fds_temp ) ) {
152 i_reads = read( i_socket, pb_now, i_bytes );
154 if( -1 == i_reads ) {
162 memcpy( &t_fds_temp, &t_fds_socket, sizeof( fd_set ) );
163 } while( i_bytes > 0 );
166 i_ret = i_size - i_bytes;
173 /* EOF of drd64_.c ----------------------------------- */