From 1aede748b3ae62ca85c8958579b526b48298c8fb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 11 May 2016 13:24:01 -0400 Subject: fix network enumeration --- MediaBrowser.ServerApplication/Networking/NetworkManager.cs | 1 + MediaBrowser.ServerApplication/Networking/NetworkShares.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.ServerApplication/Networking') diff --git a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs index 978a29db0..cc9061fcd 100644 --- a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs +++ b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs @@ -29,6 +29,7 @@ namespace MediaBrowser.ServerApplication.Networking /// IEnumerable{NetworkShare}. public IEnumerable GetNetworkShares(string path) { + Logger.Info("Getting network shares from {0}", path); return new ShareCollection(path).OfType().Select(ToNetworkShare); } diff --git a/MediaBrowser.ServerApplication/Networking/NetworkShares.cs b/MediaBrowser.ServerApplication/Networking/NetworkShares.cs index 91bd167b8..f9a59203d 100644 --- a/MediaBrowser.ServerApplication/Networking/NetworkShares.cs +++ b/MediaBrowser.ServerApplication/Networking/NetworkShares.cs @@ -390,7 +390,9 @@ namespace MediaBrowser.ServerApplication.Networking Type t = (2 == level) ? typeof(SHARE_INFO_2) : typeof(SHARE_INFO_1); int offset = Marshal.SizeOf(t); - for (int i = 0, lpItem = pBuffer.ToInt32(); i < entriesRead; i++, lpItem += offset) + var lpItem = pBuffer.ToInt64(); + + for (int i = 0; i < entriesRead; i++, lpItem += offset) { IntPtr pItem = new IntPtr(lpItem); if (1 == level) -- cgit v1.2.3 From c8b4e580bb827166fcf45a109751702e15be982e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 14 Jun 2016 23:36:40 -0400 Subject: fix windows network browser --- .../Networking/NetworkManager.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'MediaBrowser.ServerApplication/Networking') diff --git a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs index cc9061fcd..ed60de9d2 100644 --- a/MediaBrowser.ServerApplication/Networking/NetworkManager.cs +++ b/MediaBrowser.ServerApplication/Networking/NetworkManager.cs @@ -89,19 +89,21 @@ namespace MediaBrowser.ServerApplication.Networking /// /// Arraylist that represents all the SV_TYPE_WORKSTATION and SV_TYPE_SERVER /// PC's in the Domain - private IEnumerable GetNetworkDevicesInternal() + private List GetNetworkDevicesInternal() { //local fields const int MAX_PREFERRED_LENGTH = -1; var SV_TYPE_WORKSTATION = 1; var SV_TYPE_SERVER = 2; - var buffer = IntPtr.Zero; - var tmpBuffer = IntPtr.Zero; + IntPtr buffer = IntPtr.Zero; + IntPtr tmpBuffer = IntPtr.Zero; var entriesRead = 0; var totalEntries = 0; var resHandle = 0; var sizeofINFO = Marshal.SizeOf(typeof(_SERVER_INFO_100)); + var returnList = new List(); + try { //call the DllImport : NetServerEnum with all its required parameters @@ -118,7 +120,7 @@ namespace MediaBrowser.ServerApplication.Networking //get pointer to, Pointer to the buffer that received the data from //the call to NetServerEnum. Must ensure to use correct size of //STRUCTURE to ensure correct location in memory is pointed to - tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO)); + tmpBuffer = new IntPtr((Int64)buffer + (i * sizeofINFO)); //Have now got a pointer to the list of SV_TYPE_WORKSTATION and //SV_TYPE_SERVER PC's, which is unmanaged memory //Needs to Marshal data from an unmanaged block of memory to a @@ -129,7 +131,7 @@ namespace MediaBrowser.ServerApplication.Networking //add the PC names to the ArrayList if (!string.IsNullOrEmpty(svrInfo.sv100_name)) { - yield return svrInfo.sv100_name; + returnList.Add(svrInfo.sv100_name); } } } @@ -140,6 +142,8 @@ namespace MediaBrowser.ServerApplication.Networking //the memory that the NetApiBufferAllocate function allocates NativeMethods.NetApiBufferFree(buffer); } + + return returnList; } /// -- cgit v1.2.3