This file is indexed.

/usr/include/wibble/sys/netbuffer.h is in libwibble-dev 1.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef WIBBLE_SYS_NETBUFFER_H
#define WIBBLE_SYS_NETBUFFER_H

/*
 * Variable-size, reference-counted memory buffer used to access network
 * packets
 *
 * Copyright (C) 2003--2006 Enrico Zini <enrico@debian.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */

#include <wibble/sys/buffer.h>
#include <wibble/exception.h>

namespace wibble {
namespace sys {

/**
 * Buffer whose starting can be moved back and forth, useful to decapsulate
 * stacked network packets
 */
class NetBuffer : public Buffer
{
public:
	/**
	 * Offset in bytes of the NetBuffer start, from the beginning of the memory
	 * area we manage
	 */
	size_t cursor;
	
public:
	NetBuffer() throw () : Buffer(), cursor(0) {}
	NetBuffer(size_t size) : Buffer(size), cursor(0) {}
	NetBuffer(void* buf, size_t size, bool own = true)
		: Buffer(buf, size, own), cursor(0) {}
	NetBuffer(const void* buf, size_t size)
		: Buffer(buf, size), cursor(0) {}

	NetBuffer(const Buffer& buf) throw () : Buffer(buf), cursor(0) {}
	NetBuffer(const NetBuffer& buf) throw ()
		: Buffer(buf), cursor(buf.cursor) {}

	NetBuffer& operator=(const Buffer& buf)
	{
		Buffer::operator=(buf);
		cursor = 0;
		return *this;
	}

	NetBuffer& operator=(const NetBuffer& buf)
	{
		Buffer::operator=(buf);
		cursor = buf.cursor;
		return *this;
	}

	/// Return a pointer to the buffer
	const void* data(size_t ofs = 0) const throw () { return static_cast<const char*>(Buffer::data()) + cursor + ofs; }

	/// Return a pointer to the buffer
	void* data(size_t ofs = 0) throw () { return static_cast<char*>(Buffer::data()) + cursor + ofs; }

	/// Return the buffer size
	size_t size() const throw () { return Buffer::size() - cursor; }

	/**
	 * Check if the buffer is long enough to contain a structure T at the given
	 * offset
	 */
	template<class T>
	bool fits(size_t ofs = 0) const throw ()
	{
		return cursor + ofs + sizeof(T) < size();
	}
	
	/**
	 * Access the buffer contents as a structure T at the given offset
	 */
	template<class T>
	const T* cast(size_t ofs = 0) const throw (wibble::exception::Consistency)
	{
		if (cursor + ofs + sizeof(T) >= size())
			throw wibble::exception::Consistency("reading from buffer", "tried to read past the end of the buffer");
		return static_cast<const T*>(data(ofs));
	}

	/**
	 * Return another NetBuffer starting ofs bytes from the beginning of this one
	 */
	NetBuffer operator+(size_t ofs) throw (wibble::exception::Consistency)
	{
		return after(ofs);
	}
	
	/**
	 * Return another NetBuffer starting ofs bytes from the beginning of this one
	 */
	const NetBuffer after(size_t ofs) const throw (wibble::exception::Consistency)
	{
		NetBuffer res(*this);
		res.skip(ofs);
		return res;
	}
	
	/**
	 * Return another NetBuffer starting just after sizeof(T) from the
	 * beginning of this one
	 */
	template<class T>
	const NetBuffer after() const throw (wibble::exception::Consistency)
	{
		NetBuffer res(*this);
		res.skip(sizeof(T));
		return res;
	}

	/**
	 * Move the starting point of this buffer ofs bytes from the beginning
	 */
	NetBuffer& operator+=(size_t ofs) throw (wibble::exception::Consistency)
	{
		skip(ofs);
		return *this;
	}
	
	/**
	 * Move the starting point of this buffer sizeof(T) bytes from the
	 * beginning
	 */
	template<class T>
	void skip() throw (wibble::exception::Consistency)
	{
		skip(sizeof(T));
	}

	/**
	 * Move the starting point of this buffer ofs bytes from the beginning
	 */
	void skip(size_t t) throw (wibble::exception::Consistency)
	{
		if (cursor + t >= size())
			throw wibble::exception::Consistency("reading from buffer", "tried to skip past the end of the buffer");
		cursor += t;
	}
};

}
}

// vim:set ts=4 sw=4:
#endif