netjunk.h #1

  • //
  • guest/
  • sandy_currier/
  • p4filter/
  • netjunk.h
  • View
  • Commits
  • Open Download .zip Download (1 KB)
/*
 * netjunk.h: Useful functions for dealing with the outside world
 * $Header$
 */

/* Prevent multiple inclusion. */
#ifndef __NETJUNK_H
#define __NETJUNK_H

/* Header files we need. */
#include <sys/types.h>

/* Like read() and write(), but are a little more persistent about doing
 * their thing.  Return the number of bytes read/written, or -1 on error.
 * Returns 0 on EOF.  Tries to read/write until count bytes have been
 * read/written; a return value less than count indicates EOF or error,
 * but you never need to repeat doread/dowrite the way you would
 * read/write. */
ssize_t doread(int fd, void *buf, size_t count);
ssize_t dowrite(int fd, const void *buf, size_t count);

/* Perforce, in its infinite brilliance, uses little-endian byte order
 * in its network stream.  Since there aren't library functions to deal
 * with these, write our own.  Pull a four-byte unsigned value out of
 * a data stream, or write into one. */
unsigned read_p4_long(const void *buf);
void write_p4_long(void *buf, unsigned val);

/* Packets begin with a five-byte header.  This consists of a one-byte
 * checksum, followed by a four-byte length.  The checksum appears to be
 * the bitwise XOR of the four length bytes.  Generate that. */
char p4_checksum(const void *buf);

#endif /* __NETJUNK_H */
# Change User Description Committed
#1 450 sandy_currier Initial import of p4filter code.
 This contains a solaris2.6 binary but
no others.