Accessing the IP address of multiple network adapters using the MS Winsock Control 
Author Message
 Accessing the IP address of multiple network adapters using the MS Winsock Control

Hello,
How can I access ALL the IP addresses for the different network adapters
I have installed? All I can currently access is the first one bound.

Thanks,
Gary



Sat, 28 Jul 2001 03:00:00 GMT  
 Accessing the IP address of multiple network adapters using the MS Winsock Control
Im not sure you can using the winsock control. (although someone else might
know of a very weird way to do it)
2 months ago or so windows developer journal had an article in c++ about
doing that sort of thing.
Quote:

>Hello,
>How can I access ALL the IP addresses for the different network adapters
>I have installed? All I can currently access is the first one bound.

>Thanks,
>Gary



Sun, 29 Jul 2001 03:00:00 GMT  
 Accessing the IP address of multiple network adapters using the MS Winsock Control
VC is my next step.....I'll use the Netbios API if need be, I just am
unable to find any documentation.

Thanks,
Gary


Quote:
> Im not sure you can using the winsock control. (although someone else might
> know of a very weird way to do it)
> 2 months ago or so windows developer journal had an article in c++ about
> doing that sort of thing.


> >Hello,
> >How can I access ALL the IP addresses for the different network adapters
> >I have installed? All I can currently access is the first one bound.

> >Thanks,
> >Gary



Sun, 29 Jul 2001 03:00:00 GMT  
 Accessing the IP address of multiple network adapters using the MS Winsock Control

If you're interested in using the MS INet control, I have a solution
--
Ricky

ICQ# 4730537             EGN# 16191
kharjes at dgi dot net
http://www.geocities.com/~howdy

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Please Reply To The Newsgroups

Quote:

>Hello,
>How can I access ALL the IP addresses for the different network adapters
>I have installed? All I can currently access is the first one bound.

>Thanks,
>Gary



Sun, 29 Jul 2001 03:00:00 GMT  
 Accessing the IP address of multiple network adapters using the MS Winsock Control
check out the catalyst control at
http://www.catalyst.com/forms/download-wrench.html
Quote:

>> >Hello,
>> >How can I access ALL the IP addresses for the different network adapters
>> >I have installed? All I can currently access is the first one bound.

>> >Thanks,
>> >Gary



Sun, 29 Jul 2001 03:00:00 GMT  
 Accessing the IP address of multiple network adapters using the MS Winsock Control


Quote:
> Hello,
> How can I access ALL the IP addresses for the different network adapters
> I have installed? All I can currently access is the first one bound.

these programs will work in c and you can call the api from vb, but you
will have to do some work to unravel the array of struct in_addr's.
second program requires winsock 2.2

#include <stdio.h>
#pragma warning(disable:4115 4201 4214 4514)
#include <winsock.h>
#pragma warning(default:4115 4201 4214 /*4514*/)
#define IPFAIL(x)               (x==SOCKET_ERROR)
#define BAD_SOCKET(x)   (x==INVALID_SOCKET)
static WSADATA WSAData;
void findIPAddresses(char *name)
        {
        struct hostent *host;
        struct in_addr *ip;
        printf("ip address(es) for %s: ",name);
        if((host=gethostbyname(name))==NULL)
                { WSACleanup(); fprintf(stderr,"gethostbyname fails");
exit(1); }
        while((ip=(struct in_addr *)*host->h_addr_list++)!=NULL)
                printf("%s ",inet_ntoa(*ip));
        printf("\n");
        }
int main(int argc,char *argv[])
        {
        char name[BUFSIZ],*hostName=name;
        int I;
        if(WSAStartup(0x0101,&WSAData))
                { WSACleanup(); fprintf(stderr,"WSAStartup fails");
exit(1); }
        if(argc==1)
                {
                if(IPFAIL(gethostname(name,BUFSIZ-1)))
                        { WSACleanup(); fprintf(stderr,"gethostname fails");
exit(1); }
                printf("gethostname returns: %s\n",name);
                findIPAddresses(name);
                }
                else for(I=1;I<argc;I++)
                        findIPAddresses(argv[I]);
        (void)getchar();
        return WSACleanup();
        }

#include <iostream.h>
#include <winsock2.h>
#include <ws2tcpip.h>

int doit()
{
    SOCKET sd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
    if (sd == SOCKET_ERROR) {
        cerr << "Failed to get a socket.  Error " <<
                WSAGetLastError() << endl;
        return 1;
    }

    INTERFACE_INFO InterfaceList[20];
    unsigned long nBytesReturned;
    if (WSAIoctl(sd, SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList,
            sizeof(InterfaceList), &nBytesReturned, 0, 0) ==
            SOCKET_ERROR) {
        cerr << "Failed calling WSAIoctl: error " <<
                WSAGetLastError() << endl;
        return 1;
    }

    int nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO);
    cout << "There are " << nNumInterfaces << " interfaces:" << endl;
    for (int I = 0; I < nNumInterfaces; ++I) {
        cout << endl;

        sockaddr_in* pAddress;
        pAddress = (sockaddr_in*)&(InterfaceList[I].iiAddress);
        cout << "    " << inet_ntoa(pAddress->sin_addr);

        pAddress = (sockaddr_in*)&(InterfaceList[I].iiBroadcastAddress);
        cout << " has bcast " << inet_ntoa(pAddress->sin_addr);

        pAddress = (sockaddr_in*)&(InterfaceList[I].iiNetmask);
        cout << " and netmask " << inet_ntoa(pAddress->sin_addr) << endl;

        cout << "    Iface is ";
        u_long nFlags = InterfaceList[I].iiFlags;
        if (nFlags & IFF_UP) cout << "up";
        else cout << "down";
        if (nFlags & IFF_POINTTOPOINT) cout << ", is point-to-point";
        if (nFlags & IFF_LOOPBACK) cout << ", is a loopback iface";
        cout << ", and can do: ";
        if (nFlags & IFF_BROADCAST) cout << "bcast ";
        if (nFlags & IFF_MULTICAST) cout << "multicast ";
        cout << endl;
    }

    return 0;

Quote:
}

int main()
{
    WSADATA WinsockData;
    if (WSAStartup(MAKEWORD(2, 2), &WinsockData) != 0) {
        cerr << "Failed to find Winsock 2.2!" << endl;
        return 2;
    }

    int nRetVal = doit();

    WSACleanup();

    return nRetVal;

Quote:
}

hth
--
Ray (will hack java for food) http://home.pacbell.net/rtayek/
hate Spam? http://www.blighty.com/products/spade/


Thu, 02 Aug 2001 03:00:00 GMT  
 Accessing the IP address of multiple network adapters using the MS Winsock Control
Thanks for the code...I'll have to dig out my C manuals and decode it!
LOL

Thanks again,
Gary



Quote:
> Subject: Re: Accessing the IP address of multiple network adapters using the MS Winsock Control

> Newsgroups: microsoft.public.vb.controls.internet, microsoft.public.vb.general.discussion, microsoft.public.vb.syntax, microsoft.public.vb.winapi, microsoft.public.vb.winapi.networks



> > Hello,
> > How can I access ALL the IP addresses for the different network adapters
> > I have installed? All I can currently access is the first one bound.

> these programs will work in c and you can call the api from vb, but you
> will have to do some work to unravel the array of struct in_addr's.
> second program requires winsock 2.2

> #include <stdio.h>
> #pragma warning(disable:4115 4201 4214 4514)
> #include <winsock.h>
> #pragma warning(default:4115 4201 4214 /*4514*/)
> #define IPFAIL(x)          (x==SOCKET_ERROR)
> #define BAD_SOCKET(x)      (x==INVALID_SOCKET)
> static WSADATA WSAData;
> void findIPAddresses(char *name)
>    {
>    struct hostent *host;
>    struct in_addr *ip;
>    printf("ip address(es) for %s: ",name);
>    if((host=gethostbyname(name))==NULL)
>            { WSACleanup(); fprintf(stderr,"gethostbyname fails");
> exit(1); }
>    while((ip=(struct in_addr *)*host->h_addr_list++)!=NULL)
>            printf("%s ",inet_ntoa(*ip));
>    printf("\n");
>    }
> int main(int argc,char *argv[])
>    {
>    char name[BUFSIZ],*hostName=name;
>    int I;
>    if(WSAStartup(0x0101,&WSAData))
>            { WSACleanup(); fprintf(stderr,"WSAStartup fails");
> exit(1); }
>    if(argc==1)
>            {
>            if(IPFAIL(gethostname(name,BUFSIZ-1)))
>                    { WSACleanup(); fprintf(stderr,"gethostname fails");
> exit(1); }
>            printf("gethostname returns: %s\n",name);
>            findIPAddresses(name);
>            }
>            else for(I=1;I<argc;I++)



Mon, 06 Aug 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Accessing the IP address of multiple network adapters using the MS Winsock Control

2. Accessing the IP address of multiple network adapters using the MS Winsock Control

3. Accessing the IP address of multiple network adapters using the MS Winsock Control

4. Accessinf the IP address of multiple network adapters using the MS Winsock Control

5. Accessinf the IP address of multiple network adapters using the MS Winsock Control

6. Accessinf the IP address of multiple network adapters using the MS Winsock Control

7. Accessinf the IP address of multiple network adapters using the MS Winsock Control

8. Problems finding correct IP address using WINSOCK Control with 2 network adapters

9. Problems finding correct IP address using WINSOCK Control with 2 network adapters

10. Local IP address from multiple adapters through the Winsock control

11. TCP/IP IP address and multiple adapters

12. Network adapter question: how to put ip address and MAC addresses together

 

 
Powered by phpBB® Forum Software