INetSharingConfiguration::AddPortMapping method (netcon.h)

[Internet Connection Firewall may be altered or unavailable in subsequent versions. Instead, use the Windows Firewall API.]

The AddPortMapping method adds a service port mapping for this connection.

Syntax

HRESULT AddPortMapping(
  [in]  BSTR                   bstrName,
  [in]  UCHAR                  ucIPProtocol,
  [in]  USHORT                 usExternalPort,
  [in]  USHORT                 usInternalPort,
  [in]  DWORD                  dwOptions,
  [in]  BSTR                   bstrTargetNameOrIPAddress,
  [in]  ICS_TARGETTYPE         eTargetType,
  [out] INetSharingPortMapping **ppMapping
);

Parameters

[in] bstrName

Pointer to a BSTR variable that contains the name for this port mapping.

[in] ucIPProtocol

Specifies the IP Protocol to set for the port mapping. The IP Protocol is one of the following values:

NAT_PROTOCOL_TCP

NAT_PROTOCOL_UDP

[in] usExternalPort

Specifies the external port for this port mapping.

[in] usInternalPort

Specifies the internal port for this port mapping.

[in] dwOptions

This parameter is reserved and not used at this time.

[in] bstrTargetNameOrIPAddress

Pointer to a BSTR variable that contains the name of the target computer for this port mapping. Specify either the target name or the target IP address, but not both.

[in] eTargetType

Indicates target type.

[out] ppMapping

Pointer to a pointer that, on successful return, points to an INetSharingPortMapping interface for the port mapping.

Return value

If the method succeeds the return value is S_OK.

If the method fails, the return value is one of the following error codes.

Return code Description
E_ABORT
The operation was aborted.
E_FAIL
An unspecified error occurred.
E_INVALIDARG
One of the parameters is invalid.
E_NOINTERFACE
A specified interface is not supported.
E_NOTIMPL
A specified method is not implemented.
E_OUTOFMEMORY
The method was unable to allocate required memory.
E_POINTER
A pointer passed as a parameter is not valid.
E_UNEXPECTED
The method failed for unknown reasons.

Remarks

When first added, the new mapping is in a disabled state. To enable the new mapping, use INetSharingPortMapping::Enable.

After it is added, the new definition appears in the Port Mappings list in the ICS/ICF user interface.

Use the INetSharingManager::get_INetSharingConfigurationForINetConnection method to obtain an INetSharingConfiguration interface for a particular connection.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server None supported
Target Platform Windows
Header netcon.h
DLL Hnetcfg.dll

See also

INetSharingConfiguration

Internet Connection Sharing and Internet Connection Firewall Interfaces

Internet Connection Sharing and Internet Connection Firewall Reference