GetPortName() public method

Returns the port name. (http://msdn.microsoft.com/en-us/library/bb145890.aspx)
public GetPortName ( string &pbstrName ) : int
pbstrName string Returns the name of the port.
return int
        /// <summary>
        /// Adds a port. (http://msdn.microsoft.com/en-ca/library/bb161980.aspx)
        /// </summary>
        /// <param name="pRequest"> An IDebugPortRequest2 object that describes the port to be added. </param>
        /// <param name="ppPort"> Returns an IDebugPort2 object that represents the port. </param>
        /// <returns> VSConstants.S_OK. </returns>
        public int AddPort(IDebugPortRequest2 pRequest, out IDebugPort2 ppPort)
        {
            bool           sucess       = true;
            AD7PortRequest port_request = null;
            AD7Port        port         = null;

            try
            {
                port_request = (AD7PortRequest)pRequest;
            }
            catch
            {
                sucess = false;
                string  portRequestName;
                AD7Port defaultPort = null;
                pRequest.GetPortName(out portRequestName);
                string search = "";
                if (portRequestName.ToLower().Contains("device"))
                {
                    search = "device";
                }
                else if (portRequestName.ToLower().Contains("simulator"))
                {
                    search = "simulator";
                }
                else
                {
                    search = portRequestName.ToLower();
                }
                foreach (var p in m_ports)
                {
                    AD7Port tempPort = p.Value;
                    if (defaultPort == null)
                    {
                        defaultPort = tempPort;
                    }

                    string tempPortName = "";
                    tempPort.GetPortName(out tempPortName);
                    if (tempPortName.ToLower().Contains(search))
                    {
                        port = tempPort;
                        break;
                    }
                    else
                    {
                        string IP = search;
                        do
                        {
                            int pos = IP.LastIndexOf('.');
                            if (pos != -1)
                            {
                                IP = IP.Remove(pos);
                                if (tempPortName.Contains(IP))
                                {
                                    port = tempPort;
                                    break;
                                }
                            }
                            else
                            {
                                IP = "";
                            }
                        } while (IP != "");
                        if (IP != "")
                        {
                            break;
                        }
                    }
                }
                if (port == null)
                {
                    if (defaultPort != null)
                    {
                        port = defaultPort;
                    }
                    else
                    {
                        port = new AD7Port(this, port_request, Guid.NewGuid(), "", "", true, "");
                    }
                }
            }
            if (sucess)
            {
                port = CreatePort(port_request);
                Guid portGuid;
                port.GetPortId(out portGuid);
                m_ports.Add(portGuid, port);
            }
            ppPort = port;
            return(VSConstants.S_OK);
        }