private void ProcessPacket(IAsyncResult ar)
{
try {
UdpClient udp = (UdpClient)((UdpState)(ar.AsyncState)).Udp;
IPEndPoint endpoint = (IPEndPoint)((UdpState)(ar.AsyncState)).Endpoint;
AsyncCallback callback = (AsyncCallback)((UdpState)(ar.AsyncState)).Callback;
byte[] bytes = udp.EndReceive(ar, ref endpoint);
IPAddress localAddress = IPAddress.Loopback;
IPEndPoint localEndpoint = (IPEndPoint)udp.Client.LocalEndPoint;
if (localEndpoint != null) localAddress = localEndpoint.Address;
//bool isLocal = IPAddress.IsLoopback(endpoint.Address);
//bool isLAN = IsInSameSubnet(localAddress, endpoint.Address);
//string receivedFrom = endpoint.ToString();
// start listening again
udp.BeginReceive(callback, ar.AsyncState);
// bubble up the event
if (this.PacketReceived != null) this.PacketReceived(bytes, endpoint);
}
catch (Exception e) {
// swallow any exceptions (this handles the case when Growl is stopped while still listening for network notifications)
}
}