Novell Home

How to build, send and receive NCP packets

From Developer Community

This code shows how to communicate with a NetWare server using NCP packets. It reads the total number of extended attributes but without calling GetEAInfo(), by assembling NCP packets directly and sending them to the server with NWNCPSend()

Sample Code

#include <errno.h>
#include <nwconn.h>
#include <nwdebug.h>
#include <nwerrno.h>
#include <nwfileng.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct EnumerateEAsLevel0RequestPacket {
   unsigned char  SubFunctionCode;
   unsigned short Flags;
   int            VolumeNumber;
   unsigned long  DirectoryNumber;
   unsigned long  InspectSize;
   unsigned short EnumerateSequence;
   unsigned short KeyLength;
};
struct EnumerateEAsLevel0ReplyPacket {
   unsigned long  ErrorCode;
   unsigned long  TotalEAs;
   unsigned long  TotalDataSizeOfEAs;
   unsigned long  TotalKeySizeOfEAs;
   unsigned long  NewEAHandle;
   unsigned short Reserved0;
   unsigned short Reserved1;
};
int main( int argc, char* argv[]) {
   struct EnumerateEAsLevel0RequestPacket req;
   struct EnumerateEAsLevel0ReplyPacket   rep;
   int                                    ccode;
   if ( argc != 2) {
      puts( "Usage: GetEAInf <filename>");
      return EXIT_FAILURE;
   }
   /*
   // Prepare request packet
   */
   req.SubFunctionCode   = 4;
   req.Flags             = 0;
   req.InspectSize       = 0;
   req.EnumerateSequence = 0;
   req.KeyLength         = 0;
   ccode = FEMapPathVolumeDirToVolumeDir( strupr( argv[ 1]),
                                          0,
                                          0,
                                          &req.VolumeNumber,
                                          &req.DirectoryNumber);
   if ( ccode != ESUCCESS) {
      printf( "FEMapPathVolumeDirToVolumeDir failed, ccode = %d\n", ccode);
      return EXIT_FAILURE;
   }
   /*
   // Send NCP request
   */
   ccode = NWNCPSend( 86, &req, sizeof( req), &rep, sizeof( rep));
   if ( ccode != ESUCCESS) {
      printf( "NWNCPSend failed, ccode = %d\n", ccode);
      return EXIT_FAILURE;
   }
   /*
   // Display received information
   */
   printf( "rep.ErrorCode          = %u\n"
           "rep.TotalEAs           = %u\n"
           "rep.TotalDataSizeOfEAs = %u\n"
           "rep.TotalKeySizeOfEAs  = %u\n",
      rep.ErrorCode,
      rep.TotalEAs,
      rep.TotalDataSizeOfEAs,
      rep.TotalKeySizeOfEAs);
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.