#include "ipxtund.h"

boolean test_and_increment_ipx_ctl(char *ipx_packet)
{
  if (ipx_packet[4] > 15) {
    return FALSE;
  }
  ipx_packet[4]++;
  return TRUE;
}


void get_ipx_dest_node(char *node, const char *ipx_packet)
{
  memcpy(node, &ipx_packet[10], 6);
  return;
}


void get_ipx_dest_net(char *net, const char *ipx_packet)
{
  memcpy(net, &ipx_packet[6], 4);
  return;
}


void get_ipx_source_node(char *node, const char *ipx_packet)
{
  memcpy(node, &ipx_packet[22], 6);
  return;
}


void get_ipx_source_net(char *net, const char *ipx_packet)
{
  memcpy(net, &ipx_packet[18], 4);
  return;
}


u_char get_ipx_type(const char *ipx_packet)
{
  return ipx_packet[5];
}


size_t get_ipx_length(const char *ipx_packet)
{
  return (size_t)str_to_hs(&ipx_packet[2]);
/*
  return 256 * (u_char)ipx_packet[2] + (u_char)ipx_packet[3];
*/
}


void hs_to_str(char *str, const u_short n)
{
  u_short *usp;
  
  usp = (u_short *)str;
  *usp = htons(n);
}


u_short str_to_hs(const char *str)
{
  u_short *usp;
  
  usp = (u_short *)str;
  return htons(*usp);
}
