Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 871
  • Last Modified:

passing the ipaddress

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
sreeramkr
Asked:
sreeramkr
  • 9
  • 8
1 Solution
 
sreeramkrAuthor Commented:
no one to answer this question???
0
 
DVBCommented:
Checked it out, but I am not a windows expert, and definitely not windows 2000. (Haven't even seen it yet). Sorry
0
 
sreeramkrAuthor Commented:
is tehre anyway i can get help?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
chen_levkovichCommented:
by trapping the OID_GEN_NETWORK_LAYER_ADDRESSES you can find the nic ip address. read about this OID in the DDK.
0
 
sreeramkrAuthor Commented:
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
 
chen_levkovichCommented:
chen_levkovich changed the proposed answer to a comment
0
 
chen_levkovichCommented:
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
 
sreeramkrAuthor Commented:
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
 
chen_levkovichCommented:
chen_levkovich changed the proposed answer to a comment
0
 
chen_levkovichCommented:

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
 
sreeramkrAuthor Commented:
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
 
chen_levkovichCommented:
chen_levkovich changed the proposed answer to a comment
0
 
chen_levkovichCommented:
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
 
sreeramkrAuthor Commented:
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
 
chen_levkovichCommented:
chen_levkovich changed the proposed answer to a comment
0
 
chen_levkovichCommented:
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
 
sreeramkrAuthor Commented:
Answer accepted
0
 
sreeramkrAuthor Commented:
Thanks for this answer. Can I get an answer from my new question please

Regards
SReeram
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now