Hi experts,
i need one sample code for the address hook routine for the dhcp
server in vxworks. i need it very urgent.
and one more doubt in the lease hook routine whether the
initialization of dos file system is required. In my system TrueFFS is
used, and when i used the write and read operation without the dos
file system operation its working fine. any problem in my
implementation please help. I am pasting the code below.

thanks in advance
Dino Joseph Mycle




/* Include these declarations if hooks are defined. */

/*STATUS DHCPS_LEASE_HOOK (int, char *, int); */

STATUS dhcpsLeaseStorageHook (int, char *, int);
STATUS dhcpsAddressHook(int, char *, char *, char *, char *);



BOOL myFsInit = FALSE;
BOOL myFileInit = FALSE;
BOOL endOfData = FALSE;

int myWriteDesc;
int myReadDesc;



STATUS dhcpsLeaseStorageHook (int op, char *recData, int dataLen)
{
int result;
int offset;
int length;
char delim;
char buffer[10];



printf("\n Inside DHCPS_ADDRESS_HOOK\n");



switch (op)
{
case DHCPS_STORAGE_START:

printf("DHCPS_STORAGE_START\n");
#if 0

if (myFsInit == FALSE)
{

/* Set up the BLK_DEV structure to
access the ATA device. */
printf("Calling cbioLibInit()\n");
cbioLibInit();
printf("Calling dosFsLibInit()\n");
dosFsLibInit(20);
printf("Calling dosFsFatInit()\n");
dosFsFatInit();
printf("Calling dosFsFmtLibInit()\n");
dosFsFmtLibInit();
printf("Calling dosVDirLibInit()\n");
dosVDirLibInit();
printf("Calling dosChkLibInit()\n");
dosChkLibInit();

printf("Calling ataDevCreate()\n");
blk_device = tffsDevCreate(0,0,0,0);

printf("Calling dcacheDevCreate()\n");
pCbio = dcacheDevCreate(blk_device, 0, 0, "/tffs0/");

printf("Calling dpartDevCreate()\n");
cbio1 = dpartDevCreate( pCbio, 1, usrFdiskPartRead );

printf("Calling dosFsDevCreate(a)\n");
dosFsDevCreate("/tffs0", dpartPartGet(cbio1,0), 0, 0 );

pBlkDev0 = tffsDevCreate(0,0,0,0);

ataDiskInit(pBlkDev0);

dosFsConfigShow();
/* Access an existing DOS file system. */

pVolDesc = dosFsDevInit("/tffs0", pBlkDev, &configStruct);
if (pVolDesc == NULL)
return (ERROR);
myFsInit = TRUE;



}

#endif
if (myFileInit == FALSE)
{
myWriteDesc = open(AP_DHCPS_LEASE_FILENAME, O_WRONLY, 0);

if (myWriteDesc == ERROR)
{
/* Create new dhcps lease file file */
myWriteDesc = creat(AP_DHCPS_LEASE_FILENAME, O_WRONLY |O_CREAT);
endOfData = TRUE;
}
if (myWriteDesc == ERROR)
return (ERROR);

myReadDesc = open(AP_DHCPS_LEASE_FILENAME,O_RDONLY, 0);
if (myReadDesc == ERROR)
return (ERROR);

myFileInit = TRUE;
#ifdef DHCPS_DEBUG
printf("myFileInit = true\n");
#endif


}


break;

case DHCPS_STORAGE_WRITE:

printf("DHCPS_STORAGE_WRITE\n");

/* Store active leases. Return ERROR if START operation failed. */
#if 0
if (myFsInit == FALSE || myFileInit == FALSE)
return (ERROR);
#else
if (myFileInit == FALSE)
return (ERROR);
#endif

/* Store the length for later retrieval by READ operation. */
sprintf(buffer, "%d:", dataLen);
result = write (myWriteDesc, buffer, strlen (buffer));
if (result != strlen (buffer))
return (ERROR);

/* Store the record of the lease. */

result = write (myWriteDesc, recData, dataLen);
if (result != dataLen)
return (ERROR);

#ifdef DHCPS_DEBUG
printf("Store the record of the lease. success\n");
#endif

/*
* Force write to file - each operation must be independent,
* so can't rely on close() call in the DHCPS_STORAGE_STOP code.
*/

result = ioctl (myWriteDesc, FIOFLUSH, 0);
if (result == ERROR)
return (ERROR);

#ifdef DHCPS_DEBUG
printf("Force write to file. success\n");
#endif

endOfData = FALSE; /* Data available. */


#if 1

/* need to confirm with windriver whther this is required or not*/

result = read(myReadDesc, recData, length);
if(result == 0) /* Unexpected end-of-file */
{
endOfData = TRUE;
return (ERROR);
}
if (result == ERROR)
return (ERROR);
if (result != length)
return (ERROR);

#endif

break;


case DHCPS_STORAGE_READ:

printf("DHCPS_STORAGE_READ\n");

/*
* Retrieve active leases. Return ERROR if START failed or if
* no data is available.
*/
#if 0
if (myFsInit == FALSE || myFileInit == FALSE)
return (ERROR);
#else
if ( myFileInit == FALSE)
return (ERROR);

#endif

if (endOfData == TRUE)
return (ERROR);

offset = 0;

while (offset < 10)
{
result = read (myReadDesc, &delim, 1);

if (result == 0) /* Unexpected end-of-file. */
{
endOfData = TRUE;
#ifdef DHCPS_DEBUG
printf("DHCP error: Unexpected end-of-file\n");
#endif

return (ERROR);
}

if (result == ERROR)
{
#ifdef DHCPS_DEBUG
printf("Read error inside READ end-of-file\n");
#endif
return (ERROR);
}

if (delim == ':')
break;

buffer [offset++] = delim;
}

if (offset == 10) /* Buffer overflow - bad file format. */
return (ERROR);
else
buffer [offset] = '\0';

length = atoi (buffer);

result = read (myReadDesc, recData, length);
if (result == 0) /* Unexpected end-of-file. */
{
endOfData = TRUE;
return (ERROR);
}
if (result == ERROR)
return (ERROR);
if (result != length)
return (ERROR);

#ifdef DHCPS_DEBUG
printf("DHCPS_STORAGE_READ. success\n");
#endif

break;


case DHCPS_STORAGE_CLEAR:

printf("DHCPS_STORAGE_CLEAR\n");

myFileInit = FALSE;
endOfData = TRUE;
/* Remove and recreate underlying file. */

close (myWriteDesc);

close (myReadDesc);

result = remove(AP_DHCPS_LEASE_FILENAME);
if (result == ERROR)
return (ERROR);

myWriteDesc = creat(AP_DHCPS_LEASE_FILENAME, O_WRONLY |O_CREAT);
if (myWriteDesc == ERROR)
return (ERROR);

myReadDesc = open(AP_DHCPS_LEASE_FILENAME,O_RDONLY, 0);
if (myReadDesc == ERROR)
return (ERROR);

myFileInit = TRUE;

#ifdef DHCPS_DEBUG
printf("DHCPS_STORAGE_CLEAR. success\n");
#endif



break;

case DHCPS_STORAGE_STOP:

printf("DHCPS_STORAGE_STOP\n");

myFileInit = FALSE;
endOfData = FALSE;
close (myWriteDesc);
close (myReadDesc);
#ifdef DHCPS_DEBUG
printf("DHCPS_STORAGE_STOP. success\n");
#endif

break;

default:
printf("ERROR: Wrong Input DHCPS_ADDRESS_HOOK routine \n");
return (ERROR);
break;



}
return (OK);
}