/*
** CBLM v3
** $Id: util.h,v 1.8 2007/12/11 06:59:52 sella Exp $
** Copyright (c) 2004-2007 James M. Sella. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
** 
** Cheap Bastard Latency Monitor v3
*/

#ifndef __DGS_UTIL_H
#define __DGS_UTIL_H

#include "common.h"

#include <net/if.h> 
#include <sys/ioctl.h>

#include <asm/byteorder.h>
#if defined(__BIG_ENDIAN)
	#define ntohll(x) (x)
	#define htonll(x) (x)
#elif defined(__LITTLE_ENDIAN)
#if 0
	#define ntohll(x)  be64_to_cpu(x)
	#define htonll(x)  cpu_to_be64(x)
#else
	#define ntohll(x)  bswap_64(x)
	#define htonll(x)  bswap_64(x) 
#endif
	#warn "ntohll(x) and htonll(x) on LITTLE_ENDIAN systems was never tested"
#else
	#error "Could not determine byte order"
#endif

#define inaddrr(x) (*(struct in_addr *) &ifr->x[sizeof sa.sin_port])
#define IFRSIZE   ((int)(size * sizeof (struct ifreq)))

void source_ip(char *interface, struct in_addr *ip);
unsigned short csum(unsigned short *buf, int nwords);

int subtract_timeval(struct timeval *dst, struct timeval *src);
void display_packet(struct packet_t* packet, size_t len);
void display_data(struct data_t *data);
struct timeval htontv(const struct timeval src);
struct timeval ntohtv(const struct timeval src);
uint64_t tvtousec(const struct timeval src);
struct timeval usectotv(const uint64_t src);

#endif

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim: noet ts=3 sw=3
*/
