#include	<sys/types.h>
#include	<netinet/in.h>
#include	"btconf.h"
#include	"btree.h"
#include	"btintern.h"

void
tonet_page(pp)
     bt_chrp pp;
{
  int keycnt;
  int *keyind;
  off_t *keycld;
  int i;
  int *dummy;
  off_t *dummyo;

  keycnt = KEYCNT(pp);
  keyind = (int *) KEYIND(pp);
  keycld = (off_t *) KEYCLD(pp);

  LSIB(pp) = htonl(LSIB(pp));
  RSIB(pp) = htonl(RSIB(pp));
  HIPT(pp) = htonl(HIPT(pp));

  KEYCNT(pp) = htonl(KEYCNT(pp));
  KEYLEN(pp) = htonl(KEYLEN(pp));
  
  dummy = keyind;
  for(i=0;i<keycnt;i++) {
    *dummy = htonl(*dummy);
    dummy++;
  }

  dummyo = keycld;
  for(i=0;i<keycnt;i++) {
    *dummyo = htonl(*dummyo);
    dummyo++;
  }
}

void
fromnet_page(pp)
     bt_chrp pp;
{
  int keycnt;
  int *keyind;
  off_t *keycld;
  int i;
  int *dummy;
  off_t *dummyo;

  LSIB(pp) = ntohl(LSIB(pp));
  RSIB(pp) = ntohl(RSIB(pp));
  HIPT(pp) = ntohl(HIPT(pp));
  KEYCNT(pp) = ntohl(KEYCNT(pp));
  KEYLEN(pp) = ntohl(KEYLEN(pp));
  
  keycnt = KEYCNT(pp);
  keyind = (int *) KEYIND(pp);
  keycld = (off_t *) KEYCLD(pp);

  dummy = keyind;
  for(i=0;i<keycnt;i++) {
    *dummy = ntohl(*dummy);
    dummy++;
  }

  dummyo = keycld;
  for(i=0;i<keycnt;i++) {
    *dummyo = ntohl(*dummyo);
    dummyo++;
  }
}

void
tonet_super(sb)
     struct bt_super *sb;
{
  sb->magic = htonl(sb->magic);
  sb->psiz  = htonl(sb->psiz);
  sb->levs  = htonl(sb->levs);
  sb->dtyp  = htonl(sb->dtyp);
  sb->root  = htonl(sb->root);
  sb->free  = htonl(sb->free);
  sb->high  = htonl(sb->high);
  return;
}

void
fromnet_super(sb)
     struct bt_super *sb;
{
  sb->magic = ntohl(sb->magic);
  sb->psiz  = ntohl(sb->psiz);
  sb->levs  = ntohl(sb->levs);
  sb->dtyp  = ntohl(sb->dtyp);
  sb->root  = ntohl(sb->root);
  sb->free  = ntohl(sb->free);
  sb->high  = ntohl(sb->high);
  return;
}
