private static FoscamDevice CreateDevice(byte[] response) { var macAddress = GetString(response, m_offset_MAC, m_length_MAC); var cameraIP = GetIPAddressString(response, m_offset_Camera_IP); var routerIP = GetIPAddressString(response, m_offset_router_IP); Debug.WriteLine("Found device at " + cameraIP); var device = new FoscamDevice() { CameraInfo = new CameraInfo() { Name = "Foscam: " + cameraIP.ToString(), Id = macAddress, IpAddress = cameraIP, Unauthorized = true } }; return(device); }
static void OnDatagramMessageReceived(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) { var remoteHost = args.RemoteAddress; int expectedResponseLength = m_offset_router_IP + 4; var reader = args.GetDataReader(); uint bytesRead = reader.UnconsumedBufferLength; byte[] data = new byte[bytesRead]; reader.ReadBytes(data); if (bytesRead < expectedResponseLength) { return; } FoscamDevice device = CreateDevice(data); if (DeviceAvailable != null) { DeviceAvailable(device, device); } }