예제 #1
0
        public virtual void ConnectionRequest(out int auxHandle, out string ipAddress, out int portNumber)
        {
            lock (SyncObject)
            {
                try
                {
                    XdrStream.Write(IscCodes.op_connect_request);
                    XdrStream.Write(IscCodes.P_REQ_async);                        // Connection type
                    XdrStream.Write(_handle);                                     // Related object
                    XdrStream.Write(0);                                           // Partner identification

                    XdrStream.Flush();

                    ReadOperation();

                    auxHandle = XdrStream.ReadInt32();

                    // garbage
                    XdrStream.ReadBytes(8);

                    int respLen = XdrStream.ReadInt32();
                    respLen += respLen % 4;

                    // sin_family
                    XdrStream.ReadBytes(2);
                    respLen -= 2;

                    // sin_port
                    byte[] buffer = XdrStream.ReadBytes(2);
                    portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 0));
                    respLen   -= 2;

                    // * The address returned by the server may be incorrect if it is behind a NAT box
                    // * so we must use the address that was used to connect the main socket, not the
                    // * address reported by the server.
                    // sin_addr
                    buffer = XdrStream.ReadBytes(4);
                    //ipAddress = string.Format(
                    //    CultureInfo.InvariantCulture,
                    //    "{0}.{1}.{2}.{3}",
                    //    buffer[0], buffer[1], buffer[2], buffer[3]);
                    ipAddress = _connection.IPAddress.ToString();
                    respLen  -= 4;

                    // garbage
                    XdrStream.ReadBytes(respLen);

                    // Read Status Vector
                    XdrStream.ReadStatusVector();
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
                }
            }
        }
예제 #2
0
        public virtual void ConnectionRequest(out int auxHandle, out string ipAddress, out int portNumber)
        {
            try
            {
                XdrStream.Write(IscCodes.op_connect_request);
                XdrStream.Write(IscCodes.P_REQ_async);
                XdrStream.Write(_handle);
                XdrStream.Write(PartnerIdentification);

                XdrStream.Flush();

                ReadOperation();

                auxHandle = XdrStream.ReadInt32();

                var garbage1 = new byte[8];
                XdrStream.ReadBytes(garbage1, 8);

                var respLen = XdrStream.ReadInt32();
                respLen += respLen % 4;

                var sin_family = new byte[2];
                XdrStream.ReadBytes(sin_family, 2);
                respLen -= 2;

                var sin_port = new byte[2];
                XdrStream.ReadBytes(sin_port, 2);
                portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(sin_port, 0));
                respLen   -= 2;

                // * The address returned by the server may be incorrect if it is behind a NAT box
                // * so we must use the address that was used to connect the main socket, not the
                // * address reported by the server.
                var sin_addr = new byte[4];
                XdrStream.ReadBytes(sin_addr, 4);
                //ipAddress = string.Format(
                //    CultureInfo.InvariantCulture,
                //    "{0}.{1}.{2}.{3}",
                //    buffer[0], buffer[1], buffer[2], buffer[3]);
                ipAddress = _connection.IPAddress.ToString();
                respLen  -= 4;

                var garbage2 = new byte[respLen];
                XdrStream.ReadBytes(garbage2, respLen);

                XdrStream.ReadStatusVector();
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
            }
        }
 public byte[] ReadBytes(int count)
 {
     return(_inputStream.ReadBytes(count));
 }