Solved

passing the ipaddress

Posted on 2000-05-11
18
811 Views
Last Modified: 2007-10-18
I am in the process of developing a NIC miniport driver. Is there any way of finding out the ipaddress, subnet mask and the default gateway from the driver.. Is there an ndis call which returns these entities to the driver..

Please write in as much detail as possible




0
Comment
Question by:sreeramkr
  • 9
  • 8
18 Comments
 

Author Comment

by:sreeramkr
ID: 2812765
no one to answer this question???
0
 
LVL 3

Expert Comment

by:DVB
ID: 2816971
Checked it out, but I am not a windows expert, and definitely not windows 2000. (Haven't even seen it yet). Sorry
0
 

Author Comment

by:sreeramkr
ID: 2818091
is tehre anyway i can get help?
0
 

Expert Comment

by:chen_levkovich
ID: 2986434
by trapping the OID_GEN_NETWORK_LAYER_ADDRESSES you can find the nic ip address. read about this OID in the DDK.
0
 

Author Comment

by:sreeramkr
ID: 2993739
Hi chen,
 Thanks for the reply. I have trapped that in setinformation handler. I am giving the details here. check out and tell me whether it is correct. Becoz there is little that is given in ddk on that.

case OID_GEN_NETWORK_LAYER_ADDRESSES:
            NetworkAddressList = (NETWORK_ADDRESS_LIST *)InformationBuffer;
            if(InformationBufferLength==4)
            {
                  for(i=0;i<(NetworkAddressList->AddressCount);i++)
                  {
                        if(NetworkAddressList->AddressCount!=0 &&
                              NetworkAddressList->Address[i].AddressType == NDIS_PROTOCOL_ID_TCP_IP
                              )
                        {
                              for(j=0;j<InformationBufferLength;j++)
                              {
                                    Adapter->IpAddress.Address[j]=NetworkAddressList->Address[i].Address[j];
                              }
                              Adapter->IpAddress.AddressType=NetworkAddressList->Address[i].AddressType;
                              Adapter->IpAddress.AddressLength=NetworkAddressList->Address[i].AddressLength;
                              *NumBytesRead=InformationBufferLength;
                              Status=NDIS_STATUS_SUCCESS;
                              break;
                        }
                  }
            }
            else
                  Status=NDIS_STATUS_NOT_SUPPORTED;
            break;


does it suceed? tell me whats wrong with this.
waiting for ur reply.

regards
sreeram
0
 

Expert Comment

by:chen_levkovich
ID: 3065937
chen_levkovich changed the proposed answer to a comment
0
 

Expert Comment

by:chen_levkovich
ID: 3066170
to find the ip from the buffer :
1) if (NetworkAddressList->AddressCount = 0) and (NetworkAddressList->AddressType = NDIS_PROTOCOL_ID_TCP_IP) then this call is for clearing the IP
2) else if (NetworkAddressList->Address[0].AddressType == NDIS_PROTOCOL_ID_TCP_IP) then the ip addres is in NetworkAddressList->Address[0].Address[4] (4 bytes ofcourse)

very very important :

if the undelaying nic return error don't pass it. You need to return ALWAIS success (or tcp/ip will stop to send this oid). of course when an error is returned by the nic you'll have to set the buffer.
Check also the returned value in the PtRequestComplete function (when the oporation is delayed)

Bye
Chen Levkovich
chen@arx.com

0
 

Author Comment

by:sreeramkr
ID: 3073912
Hi,
  Atlast I am getting it. Can you please be elaborate on this. I mean with respect to my comment above (showing how i trapped ip adderss in setinformation handler). Can you please how put the above code correctly please

regards
sreeram
0
 

Expert Comment

by:chen_levkovich
ID: 3082993
chen_levkovich changed the proposed answer to a comment
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Expert Comment

by:chen_levkovich
ID: 3083030

read my last answer to understand this code :

this in the MPSetInformation function

case OID_GEN_NETWORK_LAYER_ADDRESSES:
      if ((Status == NDIS_STATUS_NOT_SUPPORTED) || (Status == NDIS_STATUS_INVALID_OID))
      {
            Status = NDIS_STATUS_SUCCESS;
            *BytesRead = InformationBufferLength;
            *BytesNeeded = 0;
      }
      NetworkAddressList = (NETWORK_ADDRESS_LIST *)InformationBuffer;
      if (NetworkAddressList->AddressCount)
      {
            if(NetworkAddressList->AddressCount!=0 && NetworkAddressList->Address[i].AddressType == NDIS_PROTOCOL_ID_TCP_IP )
            {
                  Adapter->IpAddress.Address[0]=(DWORD)NetworkAddressList->Address[0].Address[4];                                                                         
            }       
      }
      else
      {
            if (NetworkAddressList->AddressType == NDIS_PROTOCOL_ID_TCP_IP)
            {
                  Adapter->IpAddress.Address[0] = 0;                                    
            }
      }
      break;


this in the PtRequestComplete function

if (Oid == OID_GEN_NETWORK_LAYER_ADDRESSES)
{
      if ((Status == NDIS_STATUS_NOT_SUPPORTED) || (Status == NDIS_STATUS_INVALID_OID))
      {
            Status = NDIS_STATUS_SUCCESS ;
            switch(NdisRequest->RequestType)
            {
            case NdisRequestQueryInformation:                        
                  break;
            case NdisRequestSetInformation:
                  NdisRequest->DATA.SET_INFORMATION.BytesRead = NdisRequest->DATA.SET_INFORMATION.InformationBufferLength;
                  NdisRequest->DATA.SET_INFORMATION.BytesNeeded = 0;            
                  break;
            }
      }
}      
0
 

Author Comment

by:sreeramkr
ID: 3115610
Hi,
I am really perplexed with PtRequestcomplete and MpSetInformation. I dont know abut PtRequestComplete.

Actually I tell the ndis to look for setinformation function by giving a function name in the driver entry so that NDIS looks into that function  when it wants to set something.

So i gave a set information function. Now in the query information(as per characteristics provided in the driver entry) which is also same as set information. I say in supported_oids to look for oid_network_layer_address. This oid is mandatory in set information as per DDK help.

now in my setinformation function i want to fill up the network address.  I did as shown above. is it correct? if not then how can i fill it up? I know u have given me the code but am confused with mpsetinformation and ptrequestcomplete function. Which one to use in my set information function. mpsetinformation looks promising but if i use that code should i have to do some other handling?

do reply me

sreeram
0
 

Expert Comment

by:chen_levkovich
ID: 3116890
chen_levkovich changed the proposed answer to a comment
0
 

Expert Comment

by:chen_levkovich
ID: 3116913
Hi !

The first code igave u is to be placed in the setinformation  this code read the ip address.

but in order to continue getting this oid u have to be soure that u return success to tcp/ip. in order to do so u must return a success value. this is done by
if ((Status == NDIS_STATUS_NOT_SUPPORTED) || (Status == NDIS_STATUS_INVALID_OID))
{
Status = NDIS_STATUS_SUCCESS;
*BytesRead = InformationBufferLength;
*BytesNeeded = 0;
}

in the setinformation   function and by

if (Oid == OID_GEN_NETWORK_LAYER_ADDRESSES)
{
if ((Status == NDIS_STATUS_NOT_SUPPORTED) || (Status == NDIS_STATUS_INVALID_OID))
{
Status = NDIS_STATUS_SUCCESS ;
switch(NdisRequest->RequestType)
{
case NdisRequestQueryInformation:
break;
case NdisRequestSetInformation:
NdisRequest->DATA.SET_INFORMATION.BytesRead = NdisRequest->DATA.SET_INFORMATION.InformationBufferLength;
NdisRequest->DATA.SET_INFORMATION.BytesNeeded = 0;            
break;
}
}
}
the the ptrequestcomplete function.

because nic often return pending in the setinformation function u got to check the returned value in the ptrequestcomplete function

chen levkovich
chen@arx.com



0
 

Author Comment

by:sreeramkr
ID: 3125278
Hi,
  I am again sorry for asking you the same thing. I have the code like this. the queryinformation and the set information. I dont understand ptrequestcomplete and the otehr. why are they different and where do they have to be inserted? please see my code both for queryinformation and setinformation and gimme ur comments of what and where i have to change. sorry for the trouble

regards
sreeram


code---------------------------------------------------------

NDIS_STATUS
QueryInformation(
                                 IN NDIS_HANDLE MiniportAdapterContext,
                                 IN NDIS_OID Oid,
                                 IN PVOID InformationBuffer,
                                 IN ULONG InformationBufferLength,
                                 OUT PULONG NumBytesWritten,
                                 OUT PULONG NumBytesNeeded
                                 )
{
    // order is important here because the OIDs should be in order
    // of increasing value
      
      static
            NDIS_OID        SupportedGlobalOids[] =
      {
            OID_GEN_SUPPORTED_LIST,
                  OID_GEN_HARDWARE_STATUS,
                  OID_GEN_MEDIA_SUPPORTED,
                  OID_GEN_MEDIA_IN_USE,
                  OID_GEN_MAXIMUM_LOOKAHEAD,
                  OID_GEN_MAXIMUM_FRAME_SIZE,
                  OID_GEN_LINK_SPEED,
                  OID_GEN_TRANSMIT_BUFFER_SPACE,
                  OID_GEN_RECEIVE_BUFFER_SPACE,
                  OID_GEN_TRANSMIT_BLOCK_SIZE,
                  OID_GEN_RECEIVE_BLOCK_SIZE,
                  OID_GEN_VENDOR_ID,
                  OID_GEN_VENDOR_DESCRIPTION,
                  OID_GEN_VENDOR_DRIVER_VERSION,
                  OID_GEN_CURRENT_PACKET_FILTER,
                  OID_GEN_CURRENT_LOOKAHEAD,
                  OID_GEN_DRIVER_VERSION,
                  OID_GEN_MAXIMUM_TOTAL_SIZE,
                  OID_GEN_PROTOCOL_OPTIONS,
                  OID_GEN_MAC_OPTIONS,
                  //        OID_GEN_MEDIA_CONNECT_STATUS,
                  OID_GEN_MAXIMUM_SEND_PACKETS,
                  OID_GEN_NETWORK_LAYER_ADDRESSES,
                  OID_GEN_XMIT_OK,
                  OID_GEN_RCV_OK,
                  OID_GEN_XMIT_ERROR,
                  OID_GEN_RCV_ERROR,
                  OID_GEN_RCV_NO_BUFFER,
                  //        OID_GEN_RX_CRC_ERROR,
                  OID_GEN_TRANSMIT_QUEUE_LENGTH,
                  OID_802_3_PERMANENT_ADDRESS,
                  OID_802_3_CURRENT_ADDRESS,
                  OID_802_3_MULTICAST_LIST,
                  OID_802_3_MAXIMUM_LIST_SIZE,
                  /* for ndis 4 packet priority
                  OID_802_3_MAC_OPTIONS,
                  */
                  OID_802_3_RCV_ERROR_ALIGNMENT,
                  OID_802_3_XMIT_ONE_COLLISION,
                  OID_802_3_XMIT_MORE_COLLISIONS,
      };
      
      
      // String describing our adapter
      char VendorDescriptor[] = VENDORDESCRIPTOR;
      UCHAR           VendorId[4];
      NDIS_MEDIUM     Medium = NdisMedium802_3;
      PACB100_Adapter Adapter;  // my adapter
      NDIS_HARDWARE_STATUS HardwareStatus;
      
      ULONG           GenericUlong;
      USHORT          GenericUShort;
      UCHAR           GenericArray[6];
      
      NDIS_STATUS     Status = NDIS_STATUS_SUCCESS;
      
      
      PVOID MoveSource = (PVOID)(&GenericUlong);
      ULONG MoveBytes = sizeof(GenericUlong);
      
      Adapter=(PACB100_Adapter)(MiniportAdapterContext);
      HardwareStatus = Adapter->HardwareStatus;
      
      
      *NumBytesWritten=0;
      *NumBytesNeeded=0;
      
      switch(Oid)
      {
      case OID_GEN_MAC_OPTIONS:
            //check whether uint or ulong
            GenericUlong=(ULONG)(NDIS_MAC_OPTION_TRANSFERS_NOT_PEND|NDIS_MAC_OPTION_NO_LOOPBACK);
            break;
            
      case OID_GEN_SUPPORTED_LIST:
            MoveSource=(PVOID)(ACB100SupportedGlobalOids);
            MoveBytes=sizeof(ACB100SupportedGlobalOids);
            break;
            
      case OID_GEN_HARDWARE_STATUS:
            MoveSource=(PVOID)(&HardwareStatus);       //..check... on what basis?
            MoveBytes=sizeof(NDIS_HARDWARE_STATUS);
            break;
            
      case OID_GEN_MEDIA_SUPPORTED:
      case OID_GEN_MEDIA_IN_USE:
            MoveSource=(PVOID)(&Medium);                  //..ok
            MoveBytes=sizeof(NDIS_MEDIUM);
            break;
            
      case OID_GEN_MAXIMUM_LOOKAHEAD:
      case OID_GEN_MAXIMUM_FRAME_SIZE:
            GenericUlong=MAX_ETH_PACKET_SIZE - ETHERNET_HEADER_SIZE; //...never understood!
            break;
            
      case OID_GEN_LINK_SPEED:
            GenericUlong =  ((ULONG) Adapter->CurrentLineSpeed); //100mbps
            break;
            
      case OID_GEN_CURRENT_LOOKAHEAD:
      case OID_GEN_MAXIMUM_TOTAL_SIZE:
      case OID_GEN_TRANSMIT_BLOCK_SIZE:
      case OID_GEN_RECEIVE_BLOCK_SIZE:
            GenericUlong=(ULONG) MAX_ETH_PACKET_SIZE;
            break;
            
      case OID_GEN_TRANSMIT_BUFFER_SPACE:
            //NumTx_Frames have to be read fromt he application where user has the ability to change
            GenericUlong = (ULONG) MAX_ETH_PACKET_SIZE *
                                    Adapter->NumTxFrames;
            break;
            
            
      case OID_GEN_RECEIVE_BUFFER_SPACE:
            GenericUlong = (ULONG) MAX_ETH_PACKET_SIZE *
                                          Adapter -> NumRxFrames;
            break;
            
            
      case OID_GEN_VENDOR_ID:
            NdisMoveMemory(VendorId, Adapter->PermanentAddress, 4);
            // VendorId[3] = 0x0;
            MoveSource = (PVOID) VendorId;
            MoveBytes = sizeof(VendorId);
            break;
            
            
      case OID_GEN_VENDOR_DESCRIPTION:
            MoveSource = (PVOID) VendorDescriptor;
            MoveBytes = sizeof(VendorDescriptor);
            break;
      case OID_GEN_VENDOR_DRIVER_VERSION:
            GenericUShort = (USHORT)ACB100_VENDOR_DRIVER_VERSION;
            MoveSource = (PVOID)(&GenericUShort);
            MoveBytes = sizeof(GenericUShort);
            
      case OID_GEN_DRIVER_VERSION:
            GenericUShort = (USHORT) ACB100_DRIVER_VERSION;
            MoveSource = (PVOID)(&GenericUShort);
            MoveBytes = sizeof(GenericUShort);
            break;
            
      case OID_802_3_CURRENT_ADDRESS:
      case OID_802_3_PERMANENT_ADDRESS:
            ETH_COPY_NETWORK_ADDRESS(
                  (PCHAR) GenericArray,
                  Adapter->PermanentAddress);
            
            MoveSource = (PVOID) (GenericArray);
            MoveBytes = ETHERNET_ADDRESS_LENGTH;
            break;
            
            
            //if supported multi cast only
      case OID_802_3_MAXIMUM_LIST_SIZE:
            GenericUlong = (ULONG) MAX_MULTICAST_LIST;
            break;
            
            
      case OID_GEN_MAXIMUM_SEND_PACKETS:
            GenericUlong = (ULONG) MAX_SEND_PACKETS;
            break;
            
      default:
            
            switch (Oid)
            {
                  
            case OID_GEN_XMIT_OK:
                  
                  GenericUlong = (ULONG) (Adapter->FramesTxGood);
                  break;
                  
            case OID_GEN_RCV_OK:
                  
                  GenericUlong = (ULONG) (Adapter->FramesRxGood);
                  break;
                  
            case OID_GEN_XMIT_ERROR:
                  
                  GenericUlong = (ULONG) (Adapter->FramesTxError);
                  break;
                  
            case OID_GEN_RCV_ERROR:
                  
                  GenericUlong = (ULONG) (Adapter->FramesRxError);
                  break;
                  
            case OID_GEN_RCV_NO_BUFFER:
                  
                  GenericUlong = (ULONG) (Adapter->FramesRxResourceError);
                  break;
                  
                  
            case OID_GEN_TRANSMIT_QUEUE_LENGTH:
                  
                  GenericUlong = (ULONG) (Adapter->NumTxFrames);
                  break;
                  
            case OID_802_3_RCV_ERROR_ALIGNMENT:
                  
                  GenericUlong = (ULONG) (Adapter->FramesRxAlignError);
                  break;
                  
            case OID_802_3_XMIT_ONE_COLLISION:
                  
                  GenericUlong = (ULONG) Adapter->TryOnce;
                  break;
                  
            case OID_802_3_XMIT_MORE_COLLISIONS:
                  
                  GenericUlong = (ULONG) Adapter->TryManyTimes;
                  break;
                  
                  
            default:
                  Status = NDIS_STATUS_NOT_SUPPORTED;
                  break;
            }
    }
      
    if (Status == NDIS_STATUS_SUCCESS)
    {
        if (MoveBytes > InformationBufferLength)
        {
            // Not enough room in InformationBuffer. Punt
            *NumBytesNeeded = MoveBytes;
                  
            Status = NDIS_STATUS_BUFFER_TOO_SHORT;
        }
        else
        {
            // Copy result into InformationBuffer
            *NumBytesWritten = MoveBytes;
            if (MoveBytes > 0)
                NdisMoveMemory(InformationBuffer, MoveSource, MoveBytes);
        }
    }
      
    return (Status);
}   /* end of D100QueryInformation */


NDIS_STATUS
ACB100SetInformation(
                               IN NDIS_HANDLE MiniportAdapterContext,
                               IN NDIS_OID Oid,
                               IN PVOID InformationBuffer,
                               IN ULONG InformationBufferLength,
                               OUT PULONG NumBytesRead,
                               OUT PULONG NumBytesNeeded
                               )
{
    NDIS_STATUS                        Status;
    ULONG                              PacketFilter;
    PACB100_Adapter                  Adapter;
      NETWORK_ADDRESS_LIST      *NetworkAddressList;
      LONG                              i;
      UINT                              j;
      
      
    Adapter = (PACB100_Adapter)(MiniportAdapterContext);
      
    *NumBytesRead = 0;
    *NumBytesNeeded = 0;
      
    switch (Oid)
    {
      case OID_802_3_MULTICAST_LIST:
            *NumBytesRead=0;
            Status=NDIS_STATUS_NOT_SUPPORTED;
            
    case OID_GEN_CURRENT_LOOKAHEAD:
            
        // Verify the Length
        if (InformationBufferLength != 4)
            return (NDIS_STATUS_INVALID_LENGTH);
            
        *NumBytesRead = 4;
        Status = NDIS_STATUS_SUCCESS;
        break;
            
      case OID_GEN_CURRENT_PACKET_FILTER:
            
        // Verify the Length
        if (InformationBufferLength != 4)
            return (NDIS_STATUS_INVALID_LENGTH);
            
        // Now call the filter package to set the packet filter.
        NdisMoveMemory((PVOID)&PacketFilter, InformationBuffer, sizeof(ULONG));
            
        // Verify bits, if any bits are set that we don't support, leave
        if (PacketFilter &
            ~(NDIS_PACKET_TYPE_DIRECTED |
                  NDIS_PACKET_TYPE_BROADCAST ))
        {
//            Status = NDIS_STATUS_NOT_SUPPORTED;
//            *NumBytesRead = 4;
//            break;
        }
            Status=NDIS_STATUS_SUCCESS;
        *NumBytesRead = InformationBufferLength;
        break;
            
      case OID_GEN_NETWORK_LAYER_ADDRESSES:
            NetworkAddressList = (NETWORK_ADDRESS_LIST *)InformationBuffer;
            //if( InformationBufferLength!=sizeof(NetworkAddressList) ) // may not be correct...check!
            {
                  for(i=0;i<(NetworkAddressList->AddressCount);i++)
                  {
                        if(NetworkAddressList->AddressCount!=0 &&
                              NetworkAddressList->Address[i].AddressType == NDIS_PROTOCOL_ID_TCP_IP
                              )
                        {
                              for(j=0;j<NetworkAddressList->Address->AddressLength;j++)
                              {
                                    DbgPrint("%3d.", NetworkAddressList->Address[i].Address[j]);
                                    if(! (j&3) )DbgPrint("\n");
                                    DbgPrint("just for heck\n");
                                    // Adapter->IpAddress.Address[j]=NetworkAddressList->Address[i].Address[j];
                              }
                              //Adapter->IpAddress.AddressType=NetworkAddressList->Address[i].AddressType;
                              //Adapter->IpAddress.AddressLength=NetworkAddressList->Address[i].AddressLength;
                              
                              *NumBytesRead=InformationBufferLength;
                              Status=NDIS_STATUS_SUCCESS;
                              break;
                        }
                  }
            }
            //else
//            Status=NDIS_STATUS_NOT_SUPPORTED;
            break;
            
      default:
            Status=NDIS_STATUS_NOT_SUPPORTED;
            break;
      }
      
      return Status;
}


please pass ur comments
0
 

Expert Comment

by:chen_levkovich
ID: 3268771
chen_levkovich changed the proposed answer to a comment
0
 

Accepted Solution

by:
chen_levkovich earned 200 total points
ID: 3268821
I'm sorry but i just now realized u'r writting a miniport driver and not intermediate driver.

this is the code to extract the ip address (i didn't try to use all the structs)

case OID_GEN_NETWORK_LAYER_ADDRESSES:
NetworkAddressList = (NETWORK_ADDRESS_LIST *)informationBuffer;
if (NetworkAddressList->AddressCount)
{
if(NetworkAddressList->AddressCount!=0 &&     NetworkAddressList->Address[i].AddressType == NDIS_PROTOCOL_ID_TCP_IP )
{
// here placed the ip address  in the buffer
Adapter->IpAddress.Address[0]=(DWORD)NetworkAddressList->Address[0].Address[4];
}
}
else
{
if (NetworkAddressList->AddressType == NDIS_PROTOCOL_ID_TCP_IP)
{
// this call is to clear the address
Adapter->IpAddress.Address[0] = 0;
}
}

0
 

Author Comment

by:sreeramkr
ID: 3814532
Answer accepted
0
 

Author Comment

by:sreeramkr
ID: 3814534
Thanks for this answer. Can I get an answer from my new question please

Regards
SReeram
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now