CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Posts
    290

    2 adapters,one can broadcast and the other can not.

    PC A have 2 adapters,One adapter's IP is "192.168.0.95";another is "192.168.0.188".Everything is well and sendto return the bytes right.but the application in PC B can received from "192.168.0.188" but not "192.168.0.95".I can ping "192.168.0.95" from PC B.I disabled 192.168.0.188 and can copy files from PC B. indicates that the network status is good.

    Anyone help me? thanks a lot.

    the code is:
    int iReturn;
    SOCKET socketResponse;
    sockaddr_in stSendToAddress;
    BOOL bSocket = TRUE;
    bool opt = true;
    int nlen = sizeof(stSendToAddress);
    stSendToAddress.sin_family = AF_INET;
    stSendToAddress.sin_addr.s_addr = INADDR_BROADCAST;
    stSendToAddress.sin_port = htons(68);

    socketResponse = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    iReturn = setsockopt(socketResponse,SOL_SOCKET,SO_BROADCAST,(char FAR *)&opt,sizeof(opt));

    sockaddr_in stAdapterAddress;
    memset(&stAdapterAddress,0,sizeof(stAdapterAddress));
    stAdapterAddress.sin_family = AF_INET;
    //different only in m_szDHCPIP
    stAdapterAddress.sin_addr.s_addr = inet_addr(m_szDHCPIP);
    stAdapterAddress.sin_port = htons(68);

    if(WaitForSingleObject(theApp.m_hMutex,20000) == WAIT_OBJECT_0)
    {
    iReturn = bind(socketResponse,(sockaddr *)&stAdapterAddress,sizeof(sockaddr_in));
    if(iReturn==SOCKET_ERROR)
    {
    DWORD dwError = WSAGetLastError();
    TRACE("bind socket error.\r\n");
    }
    iReturn = sendto(socketResponse,(const char*)&stDHCPResponsePacket,BOOTP_MIN_LEN,0,(sockaddr*)&stSendToAddress,nlen);

    if(iReturn==SOCKET_ERROR)
    {
    TRACE("send error\r\n");
    // AfxMessageBox("send error\r\n");
    }
    else
    {
    // AfxMessageBox("send\r\n");
    }
    closesocket(socketResponse);
    ReleaseMutex(theApp.m_hMutex);
    }

  2. #2
    Join Date
    Jun 2004
    Location
    Scotland
    Posts
    59

    Re: 2 adapters,one can broadcast and the other can not.

    Hi,

    Maybe not a C++ issue, is there a switch or router between PC B and the adaptor with 192.168.0.95? The fact that you can ping between them doesn't mean you can send a broadcast. Networks are often set up so that broadcast is only possible over the local segment.


    Cheers,
    Alan

  3. #3
    Join Date
    Mar 2002
    Posts
    290
    Sorry for having not express clearly.

    My OS is WINDOWS 2000.
    I need to develop a DHCP server which support multi-adapter so that if one adapter can not work the other may serve as well.

    I found that if the first adapter(first means I retrieve by gethostbyname the first list in pstHostInfo->h_addr_list, and also the first return by ipconfig /all) is disconnect one error symbol appear in the task bar. Then all other adapters can not send broadcast message.

    So I guess that windows 2000 judge the network status by the first adapter.if the first adapter is not connected then all other adapter can not broadcast. And now I have proved my assumption.

    I have one way to resolved this problem.If the first adapter is not connected I disable it and then everything is well. and now I need to know how to disable the first adapter.

    thanks a lot.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: 2 adapters,one can broadcast and the other can not.

    [ Moved thread ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured