Exemplo n.º 1
0
        private static DhcpServerClient GetClientVQ(DhcpServer Server, IntPtr SearchInfo)
        {
            try
            {
                IntPtr clientPtr;

                DhcpErrors result = Api.DhcpGetClientInfoVQ(Server.ipAddress.ToString(), SearchInfo, out clientPtr);

                if (result == DhcpErrors.JET_ERROR)
                {
                    return(null);
                }

                if (result != DhcpErrors.SUCCESS)
                {
                    throw new DhcpServerException("DhcpGetClientInfoVQ", result);
                }

                try
                {
                    var client = (DHCP_CLIENT_INFO_VQ)Marshal.PtrToStructure(clientPtr, typeof(DHCP_CLIENT_INFO_VQ));

                    return(DhcpServerClient.FromNative(Server, client));
                }
                finally
                {
                    Api.DhcpRpcFreeMemory(clientPtr);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(SearchInfo);
            }
        }
Exemplo n.º 2
0
 internal DhcpServerException(string apiFunction, DhcpErrors error, string additionalMessage)
 {
     ApiFunction     = apiFunction;
     this.error      = error;
     ApiErrorMessage = BuildApiErrorMessage(error);
     message         = BuildMessage(apiFunction, additionalMessage, error, ApiErrorMessage);
 }
Exemplo n.º 3
0
        internal DhcpServerException(string ApiFunction, DhcpErrors Error)
        {
            this.ApiFunction = ApiFunction;
            this.error       = Error;

            this.errorMessage = new Lazy <string>(this.GetApiErrorMessage);
        }
Exemplo n.º 4
0
        internal static DhcpServerAuditLog GetParams(DhcpServer Server)
        {
            string auditLogDir;
            int    diskCheckInterval, maxLogFilesSize, minSpaceOnDisk;

            DhcpErrors result = Api.DhcpAuditLogGetParams(Server.ipAddress.ToString(), 0, out auditLogDir, out diskCheckInterval, out maxLogFilesSize, out minSpaceOnDisk);

            if (result != DhcpErrors.SUCCESS)
            {
                throw new DhcpServerException("DhcpAuditLogGetParams", result);
            }

            return(new DhcpServerAuditLog(auditLogDir, diskCheckInterval, maxLogFilesSize, minSpaceOnDisk));
        }
Exemplo n.º 5
0
        private string BuildApiErrorMessage(DhcpErrors error)
        {
            var errorType = typeof(DhcpErrors).GetMember(error.ToString());

            if (errorType.Length != 0)
            {
                var errorAttribute = errorType[0].GetCustomAttributes(typeof(DhcpErrorDescriptionAttribute), false);

                if (errorAttribute.Length != 0)
                {
                    return(((DhcpErrorDescriptionAttribute)errorAttribute[0]).Description);
                }
            }

            return("Unknown Error");
        }
Exemplo n.º 6
0
        private static IEnumerable <DhcpServerClient> GetClientsVQ(DhcpServer Server, DHCP_IP_ADDRESS SubnetAddress)
        {
            IntPtr clientsPtr;
            IntPtr resultHandle = IntPtr.Zero;
            int    clientsRead, clientsTotal;

            DhcpErrors result = Api.DhcpEnumSubnetClientsVQ(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal);

            if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA)
            {
                throw new DhcpServerException("DhcpEnumSubnetClientsVQ", result);
            }

            while (result == DhcpErrors.SUCCESS || result == DhcpErrors.ERROR_MORE_DATA)
            {
                try
                {
                    using (var clients = DHCP_CLIENT_INFO_ARRAY_VQ.Read(clientsPtr))
                    {
                        foreach (var client in clients.Clients)
                        {
                            yield return(DhcpServerClient.FromNative(Server, client.Item2));
                        }
                    }
                }
                finally
                {
                    Api.DhcpRpcFreeMemory(clientsPtr);
                    clientsPtr = IntPtr.Zero;
                }

                if (result == DhcpErrors.SUCCESS)
                {
                    yield break; // Last results
                }
                clientsRead  = 0;
                clientsTotal = 0;

                result = Api.DhcpEnumSubnetClientsVQ(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal);

                if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA)
                {
                    throw new DhcpServerException("DhcpEnumSubnetClientsVQ", result);
                }
            }
        }
Exemplo n.º 7
0
        private string BuildMessage(string apiFunction, string additionalMessage, DhcpErrors error, string apiErrorMessage)
        {
            var builder = new StringBuilder();

            if (apiFunction != null)
            {
                builder.Append("An error occurred calling '").Append(apiFunction).Append("'. ");
            }

            if (additionalMessage != null)
            {
                builder.Append(additionalMessage).Append(". ");
            }

            builder.Append(apiErrorMessage).Append(" [").Append(error.ToString()).Append(' ').Append((uint)error).Append(']');

            return(builder.ToString());
        }
Exemplo n.º 8
0
        private static IEnumerable <DhcpServerClient> GetClientsV5(DhcpServer Server, DHCP_IP_ADDRESS SubnetAddress)
        {
            IntPtr clientsPtr;
            IntPtr resultHandle = IntPtr.Zero;
            int    clientsRead, clientsTotal;

            DhcpErrors result = Api.DhcpEnumSubnetClientsV5(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal);

            if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA && result != DhcpErrors.ERROR_NO_MORE_ITEMS)
            {
                throw new DhcpServerException("DhcpEnumSubnetClientsV5", result);
            }

            while (result == DhcpErrors.SUCCESS || result == DhcpErrors.ERROR_MORE_DATA)
            {
                try
                {
                    var clients = (DHCP_CLIENT_INFO_ARRAY_V5)Marshal.PtrToStructure(clientsPtr, typeof(DHCP_CLIENT_INFO_ARRAY_V5));

                    foreach (var client in clients.Clients)
                    {
                        yield return(DhcpServerClient.FromNative(Server, client));
                    }
                }
                finally
                {
                    Api.DhcpRpcFreeMemory(clientsPtr);
                }

                if (result == DhcpErrors.SUCCESS)
                {
                    yield break; // Last results
                }
                result = Api.DhcpEnumSubnetClientsV5(Server.ipAddress.ToString(), SubnetAddress, ref resultHandle, 65536, out clientsPtr, out clientsRead, out clientsTotal);

                if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA && result != DhcpErrors.ERROR_NO_MORE_ITEMS)
                {
                    throw new DhcpServerException("DhcpEnumSubnetClientsV5", result);
                }
            }
        }
Exemplo n.º 9
0
 internal DhcpServerException(string apiFunction, DhcpErrors error)
     : this(apiFunction, error, null)
 {
 }
Exemplo n.º 10
0
 internal DhcpServerException(string ApiFunction, DhcpErrors Error, string AdditionalMessage)
     : this(ApiFunction, Error)
 {
     this.additionalMessage = AdditionalMessage;
 }