AddIpAddress

Win32 Programming

    Next

  • 1. NamedPipe windows 98
    Hi, CreateNamedPipe doesn't work on Win 95/98, is there any other function in order to create a NamedPipe server on Win98? or there're no way to run a any NamedPipe servers on Win 95/98!? Thanks in advance.. Ale
  • 2. Intelligent Trafficshaping via TCP/IP Stack?
    Hello Group, I wonder how much work it would be to implement a wrapper driver for the Windows 2k/XP (winsock ?!) TCP/IP-stack that would forward all calls to the wrapped stack - with one exception! By checking the name of the calling application or smth else you could shape the Traffic by Application (i.e. prioritize Media-Streams / Games / remote x11 sessions and such). One other possible application could be statistics. Methinks its a very versatile idea :-) I'm not into Win32 driver/dll programming but would like to start with smth. worth investing time in. Is my project easy or difficult to implement and where should I look to get decent information about the way winsock is called and the such? TIA paul technical university berlin, germany
  • 3. Get network drive serial number on 95/98/Me
    Is there a way to get the drive serial number of a network drive when running 95/98/Me? There are the GetVolumeInformation() and GetFileInformationByHandle() API calls, but if run from a 95/98/Me workstation, they both return zero for the drive serial number if the drive is remote. I need to be able to access the drive serial number, even if the drive is remote and the workstation is 95/98/Me. Can this be done, or must I drop support for non-NT platforms? -- Kenneth Brody

AddIpAddress

Postby SWduYWNpbw » Wed, 22 Dec 2004 22:53:03 GMT

Hi:

I try to use the api function AddIpAddress in VB.net, the definition is:

DWORD AddIPAddress(
IPAddr Address,
IPMask IpMask,
DWORD IfIndex,
PULONG NTEContext,
PULONG NTEInstance 
);


I declare this function in VB.net

    Declare Function AddIPAddress Lib "Iphlpapi" (ByVal Address As UInt64, 
ByRef IpMask As UInt64, ByRef IfIndex As Integer, ByVal NTEContext As IntPtr, 
ByVal NTEInstance As IntPtr) As Integer
 
and because I need convert Ip sting to IPAddr, use the function inet_addr 
with this definition:

unsigned long inet_addr(
  const char* cp
);

in VB.net
    Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As 
IntPtr) As UInt64

when I call this function :

    Dim ip_str As String
    Dim mask_str As String
    Dim NTEContext As IntPtr
    Dim NTEInstance As IntPtr
    Dim iRetVal As Integer

    Dim ptr_ip As IntPtr = IntPtr.Zero
    Dim ptr_mask As IntPtr = IntPtr.Zero
    Dim IPAddress As UInt64
    Dim IPMask As UInt64

    ip_str = "192.168.0.100" 
    ptr_ip = Marshal.StringToHGlobalAnsi(ip_str)
    IPAddress = inet_addr(ptr_ip)

    mask_str = "255.255.255.0"
    ptr_mask = Marshal.StringToHGlobalAnsi(mask_str)
    IPMask = inet_addr(ptr_mask)

    iRetVal = AddIPAddress(IPAddress, IPMask, 1, NTEContext, NTEInstance) 
'in this case 1 is the Ifindex of the loopback interface

    iRetVal = AddIPAddress(IPAddress, IPMask, 16777219, NTEContext, 
NTEInstance)
' in this case 16777219 is the IfIndex of the ethernet interface y get this 
number with GetIfTable

when I use the AddIPAddress the return value is 87, INVALID_PARAMETER, in 
both cases. 

I dont known what is the error, Can you help me?

Thanks.

Re: AddIpAddress

Postby Eugene Gershnik » Thu, 23 Dec 2004 13:57:08 GMT



Should be UInt32


Same here


And same here


What I don't understand is why you bother with all this. You are on .NET so 
you can write a small DLL in managed C++ that will perfrom this call without 
all the mess and expose the result in .NET friendly way.




Re: AddIpAddress

Postby SWduYWNpbw » Thu, 23 Dec 2004 17:43:02 GMT







When I change the parameters address, ipmask and if index to uint 32, I nedd 
change the function inet_addr to return uint32, but when i realized this 
changes the call to AddIpAddres return the error 87 again.



I try to make a NT service, this service realize a get to a web server, if 
the get, failure, this service add a new ip address in one interface. what do 
you thing is the best form to do it?


Thanks.

Re: AddIpAddress

Postby Eugene Gershnik » Thu, 23 Dec 2004 18:10:20 GMT






And this should be ByVal


And this too




Re: AddIpAddress

Postby SWduYWNpbw » Thu, 23 Dec 2004 18:53:01 GMT











I realize this changes:

    Declare Function AddIPAddress Lib "Iphlpapi" (ByVal Address As UInt32, 
ByVal IpMask As UInt32, ByVal IfIndex As UInt32, ByVal NTEContext As IntPtr, 
ByVal NTEInstance As IntPtr) As Integer
    Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As 
IntPtr) As UInt32

And the call

        Dim NTEContext As IntPtr
        Dim NTEInstance As IntPtr
        Dim iRetVal As Integer

        Dim IPAddress As UInt32
        Dim ip_str As String
        ip_str = "192.168.10.11"
        Dim ptr_ip As IntPtr = IntPtr.Zero
        ptr_ip = Marshal.StringToCoTaskMemAnsi(ip_str)
        IPAddress = inet_addr(ptr_ip)

        Dim IPMask As UInt32
        Dim mask_str As String
        mask_str = "255.255.255.0"
        Dim ptr_mask As IntPtr = IntPtr.Zero
        ptr_mask = Marshal.StringToCoTaskMemAnsi(mask_str)
        IPMask = inet_addr(ptr_mask)

        iRetVal = AddIPAddress(IPAddress, IPMask, UInt32.Parse("16777219"), 
NTEContext, NTEInstance)

But the iRetVal is 87.

Thks.


Re: AddIpAddress

Postby Arkady Frenkel » Thu, 23 Dec 2004 18:53:01 GMT

Maybe ask on vb forums about parameter definitions for AddIpAddress
Arkady







nedd
so
without
do



Re: AddIpAddress

Postby Eugene Gershnik » Fri, 24 Dec 2004 05:25:50 GMT

Final problem I can see.
The last two parameters should be ByRef UInt32 since you have to pass an 
address to a long in C.



Re: AddIpAddress

Postby SWduYWNpbw » Wed, 29 Dec 2004 20:09:01 GMT

YEAHHHHH!!!!!!

Thks for all, with this final response I find the matter to add the ip 
address and now is easy delete de ip address. I write the code, because 
someone need it, and i dont find any example in the net:

    Declare Function AddIPAddress Lib "Iphlpapi" (ByVal Address As UInt32, 
ByVal IpMask As UInt32, ByVal IfIndex As Integer, ByRef NTEContext As UInt32, 
ByRef NTEInstance As UInt32) As Integer
    Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As IntPtr) As 
UInt32
    Declare Function DeleteIPAddress Lib "Iphlpapi" (ByVal NTEContext As 
UInt32) As UInt32
  
To Add IP Address:

        Dim NTEContext As UInt32
        Dim NTEInstance As UInt32
        Dim iRetVal As Integer

        Dim IPAddress As UInt32
        Dim ip_str As String
        ip_str = "1.2.3.4"
        Dim ptr_ip As IntPtr = IntPtr.Zero
        ptr_ip = Marshal.StringToCoTaskMemAnsi(ip_str)
        IPAddress = inet_addr(ptr_ip)

        Dim IPMask As UInt32
        Dim mask_str As String
        mask_str = "255.255.255.0"
        Dim ptr_mask As IntPtr = IntPtr.Zero
        ptr_mask = Marshal.StringToCoTaskMemAnsi(mask_str)
        IPMask = inet_addr(ptr_mask)

        iRetVal = AddIPAddress(IPAddress, IPMask, 16777220, NTEContext, 
NTEInstance)

To Delete IP Address:

        iRetVal = DeleteIPAddress(NTEContext)

thats all, and thks again to Eugene


"Eugene Gershnik" escribi:


Similar Threads:

1.Send Msg After AddIPAddress

Hi there,

My machine have 2 Network Adapters (NIC). I try to assign different IP
to 1 adapter using IPHelper's AddIPaddress API. Then I used Socket to
bind that IP and send to another machine IP address.
I was unable to send sucessfully. I can send only another NIC IP in my
machine. How do i set socketoptions or gateway setting whenever after i
add new ip address?

Here is code example

// returnCode = AddIPAddress(staticIP, staticMask, adapterIndex, ref
nteContext, ref nteInstance);

Socket s = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
byte[] msgBytes = System.Text.Encoding.ASCII.GetBytes("Hello Server");

// new IPaddress I assign - 10.23.25.101
IPEndPoint localEP = new
IPEndPoint(Dns.Resolve("15.23.25.41").AddressList[0],0);
IPEndPoint remoteEP = new
IPEndPoint(Dns.Resolve("192.168.2.220").AddressList[0],9000);
s.Bind(localEP);
s.Connect(remoteEP);
s.Send(msgBytes);
s.Shutdown(SocketShutdown.Both);
s.Close();

Any idea would be appreciated. thanks in advance

2.AddIpAddress question

I call the AddIpAddress function to add an address. Using ipconfig /all I see 
the address (correctly represented and the correct netmask) but when I ping 
the address, it does not respond. I've also noticed that the address doesn't 
show up under the Local Area Connection->IP->Advanced settings. If I add the 
address via the Advanced settings, it is pingable. Is this correct? If this 
isn't working correctly, does anyone know what I do to determine what is 
wrong ?

3.How to get the IP added by AddIPAddress()

Hello, everyone,
I use AddIPaddress() to add a IP. As you know, if the IP address in Address 
already exists on the network, AddIPAddress returns NO_ERROR and the IP 
address added is 0.0.0.0. So, i want to get the IP added by AddIPAddress, if 
it is 0.0.0.0. I can know there is IP conflict and try another IP.
It seems simple. But i really don't know how to do it. Do you have some 
smart ways? Plz let me know!

Thank you very much!! 


4.AddIPAddress IPV6

Is there support for IPV6 similar to AddIPAddress

5.AddIPAddress Problem

Hi,

I have 2 IP addresses on a single NIC. The first is a dynamic IP
obtained via DHCP and the second one is a static IP obtained via
AddIPAddress() API.

IP-1 (DHCP): 141.183.30.165
IP-2 (AddIPAddress): 192.168.0.4


After the AddIPAddress() call, I observed the following scenarios:
- I can ping other devices on the 192.168.0.xxx network but I can no
longer ping other devices on the 141.183.30.xxx network ("No ARP
response" error is reported).
- I can successfully issue a ping *from* other computers on
141.183.30.xxx network *to* my device
- If I remove the static IP using DeleteIPAddress(), then I can
successfully ping other devices on the 141.183.30.xxx network.


What do I need to do so that my device can access both networks?

Using the GetAdaptersInfo() function, I can see that after calling the
AddIPAddressAPI, the current IP Address is 192.168.0.4. Is there a way
to make the DHCP assigned address the current IP address?


Thanks,
ennui

6. AddIPAddress() on 2008 - bind returns 10049

7. AddIPAddress



Return to Win32 Programming

 

Who is online

Users browsing this forum: No registered users and 32 guest