How to retrieve IP network parameters from a DHCP server configured network connection.
The following is an example code for how to retrieve IP network parameters:
//create a socket connection
RSocketServ esock;
TInt err = eSock.Connect();
...
//handle the error
...
RConnection aConnection; //create a RConnection
err = aConnection.Open(esock);
...
//start the connection with necessary preferences
...
err = aConnection.Start(iConnPrefs);
//Retrieve the TFTP server address
TRequestStatus status1;
TTftpServerAddrBuf tftpserveraddr; // Buffer to store TFTP server address
tftpserveraddr().index = 0;
aConnection.Ioctl(KCOLConfiguration, KConnGetTftpServerAddr, status1, &tftpserveraddress);
User::WaitForRequest(status1);
...
//Retrieve the host name of the TFTP server
TRequestStatus status2;
TBuf<256> tftpname; //buffer to store TFTP server name
aConnection.Ioctl(KCOLConfiguration, KConnGetTftpServerName, status2, &tftpname);
User::WaitForRequest(status2);
...
//Retrieve SiAddr field from a DHCP header
TRequestStatus status3;
TConnectionAddrBuf addr;
addr().iAddressFamily = IpAddressFamily();
aConnection.Ioctl(KCOLConfiguration, KConnGetDhcpHdrSiaddr, status3, &addr);
...
//Retrieve SName field from a DHCP header
TRequestStatus status4;
TBuf<64> snamebuf;
aConnection.Ioctl(KCOLConfiguration, KConnGetDhcpHdrSname, status4, &snamebuf);
...
//Retrieve the active IP address
TRequestStatus status5;
TConnectionAddress actaddr;
actaddr().iAddressFamily = IpAddressFamily();
aConnection.Ioctl(KCOLConfiguration, KConnGetCurrentAddr, status5, &actaddr);
...
//Retrieve multiple parameters
Multiple opcodes can be queried to a DHCP server using the
TDhcpRawOptionMultipleDataPckg object.
TBuf8<300> rawbuf;
rawbuf.FillZ(300); //buffer must be large enough for all returned options values
TDhcpRawOptionMultipleDataPckg pckg1(rawbuf);
pckg1.AddRawOptionCodeL(KTFtpServerAddress); //option 150
pckg1.AddRawOptionCodeL(KGeoConfCivicOption); //option 99
pckg1.AddRawOptionCodeL(KTFtpServerName); // option 66
TRequestStatus status6;
// Get raw option data for ip4
aConnection.Ioctl(KCOLConfiguration, KConnDhcpGetMultipleParams, status6, &rawbuf);
User::WaitForRequest(status);
...
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.