/usr/include/skstream-0.3/skstream/skstream.h is in libskstream-0.3-dev 0.3.6-5build1.
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | /**************************************************************************
FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3)
Copyright (C) 2000-2001 Rafael Guterres Jeffman
(C) 2002-2006 Alistair Riddoch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
**************************************************************************/
/**
* This software package has been extensively modified by members of the
* Worldforge Project. See the file ChangeLog for details.
*
* $Id: skstream.h,v 1.52 2006/10/12 01:10:12 alriddoch Exp $
*
*/
#ifndef RGJ_FREE_STREAM_H_
#define RGJ_FREE_STREAM_H_
#include <cstdio>
#include <iostream>
#include <skstream/sksocket.h>
/////////////////////////////////////////////////////////////////////////////
// class socketbuf
/////////////////////////////////////////////////////////////////////////////
class socketbuf : public std::streambuf {
private:
char *_buffer;
protected:
SOCKET_TYPE _socket;
timeval _timeout;
private:
/// Not implemented. Copying a socket buffer is not permited.
socketbuf(const socketbuf&);
/// Not implemented. Copying a socket buffer is not permited.
socketbuf& operator=(const socketbuf&);
protected:
bool Timeout;
public:
/** Make a new socket buffer from an existing socket, with optional
* buffer sizes.
*/
explicit socketbuf(SOCKET_TYPE sock, unsigned insize=0x8000,
unsigned outsize=0x8000);
/** Make a new socket buffer from an existing socket, with an existing
* buffer.
*/
socketbuf(SOCKET_TYPE sock, char* buf, int length);
/// Destroy the socket buffer.
virtual ~socketbuf();
/// Set the existing socket that this buffer should use.
void setSocket(SOCKET_TYPE sock);
/// Get the socket that this buffer uses.
SOCKET_TYPE getSocket() const {
return _socket;
}
/** Set up a timeout value after which an error flag is set if the socket
* is not ready for a read or write.
*/
void setTimeout(unsigned sec, unsigned usec=0) {
_timeout.tv_sec = sec;
_timeout.tv_usec = usec;
}
/// Return the flag indicating whether a timeout has occured.
bool timeout() const {
return Timeout;
}
protected:
/// Handle writing data from the buffer to the socket.
virtual int overflow(int nCh=EOF) = 0;
/// Handle reading data from the socket to the buffer.
virtual int underflow() = 0;
/// Flush the output buffer.
int sync();
/** Set the buffer area this stream buffer uses. Only works if not already
* set.
*/
std::streambuf * setbuf(std::streambuf::char_type * buf, std::streamsize len);
};
class stream_socketbuf : public socketbuf {
public:
/** Make a new socket buffer from an existing socket, with optional
* buffer sizes.
*/
explicit stream_socketbuf(SOCKET_TYPE sock, unsigned insize=0x8000,
unsigned outsize=0x8000);
/** Make a new socket buffer from an existing socket, with an existing
* buffer.
*/
stream_socketbuf(SOCKET_TYPE sock, char* buf, int length);
/// Destroy the socket buffer.
virtual ~stream_socketbuf();
protected:
/// Handle writing data from the buffer to the socket.
virtual int overflow(int nCh=EOF);
/// Handle reading data from the socket to the buffer.
virtual int underflow();
};
class dgram_socketbuf : public socketbuf {
public:
/** Make a new socket buffer from an existing socket, with optional
* buffer sizes.
*/
explicit dgram_socketbuf(SOCKET_TYPE sock, unsigned insize=0x8000,
unsigned outsize=0x8000);
/** Make a new socket buffer from an existing socket, with an existing
* buffer.
*/
dgram_socketbuf(SOCKET_TYPE sock, char* buf, int length);
/// Destroy the socket buffer.
virtual ~dgram_socketbuf();
bool setTarget(const std::string& address, unsigned port, int proto);
void setOutpeer(const sockaddr_storage & peer) {
out_peer = peer;
}
const sockaddr_storage & getOutpeer() const {
return out_peer;
}
const sockaddr_storage & getInpeer() const {
return in_peer;
}
SOCKLEN getOutpeerSize() const {
return out_p_size;
}
SOCKLEN getInpeerSize() const {
return in_p_size;
}
protected:
/// Target address of datagrams sent via this stream
sockaddr_storage out_peer;
/// Source address of last datagram received by this stream
sockaddr_storage in_peer;
/// Size of target address
SOCKLEN out_p_size;
/// Size of source address
SOCKLEN in_p_size;
/// Handle writing data from the buffer to the socket.
virtual int overflow(int nCh=EOF);
/// Handle reading data from the socket to the buffer.
virtual int underflow();
};
/////////////////////////////////////////////////////////////////////////////
// Enumerations
/////////////////////////////////////////////////////////////////////////////
// Supported Protocols
namespace FreeSockets {
enum IP_Protocol {
proto_IP = IPPROTO_IP,
proto_ICMP = IPPROTO_ICMP,
#ifndef _WIN32
proto_IGMP = IPPROTO_IGMP,
#else
proto_IGMP = IPPROTO_GGP,
#endif
proto_TCP = IPPROTO_TCP,
proto_PUP = IPPROTO_PUP,
proto_UDP = IPPROTO_UDP,
proto_IDP = IPPROTO_IDP,
proto_RAW = IPPROTO_RAW
};
// Well known ports
enum IP_Service {
echo = 7, //
daytime = 13, //
ftp = 21, //
ssh = 22, //
telnet = 23, //
smtp = 25, // mail
time = 37, // timserver
name = 42, // nameserver
nameserver = 53, // domain # name-domain server
finger = 79, //
http = 80, //
pop = 109, // postoffice
pop2 = 109, // # Post Office
pop3 = 110, // postoffice
nntp = 119 // usenet # Network News Transfer
};
};
/////////////////////////////////////////////////////////////////////////////
// class socket_stream
/////////////////////////////////////////////////////////////////////////////
class basic_socket_stream : public basic_socket, public std::iostream {
protected:
socketbuf & _sockbuf;
int m_protocol;
public:
/// Make a socket stream.
basic_socket_stream(socketbuf & buffer, int proto = FreeSockets::proto_IP);
// Destructor
virtual ~basic_socket_stream();
bool fail();
bool operator!() {
return fail();
}
bool timeout() const {
return _sockbuf.timeout();
}
virtual SOCKET_TYPE getSocket() const;
// Needs to be virtual to handle in-progress connect()'s for
// tcp sockets
virtual void close();
void shutdown();
void setSocket(SOCKET_TYPE sock) {
_sockbuf.setSocket(sock);
}
void setTimeout(unsigned sec, unsigned usec=0) {
_sockbuf.setTimeout(sec,usec);
}
int getProtocol() const {
return m_protocol;
}
};
/////////////////////////////////////////////////////////////////////////////
// class tcp_socket_stream
/////////////////////////////////////////////////////////////////////////////
struct addrinfo;
class tcp_socket_stream : public basic_socket_stream {
private:
tcp_socket_stream(const tcp_socket_stream&);
tcp_socket_stream& operator=(const tcp_socket_stream& socket);
SOCKET_TYPE _connecting_socket;
struct addrinfo * _connecting_address;
struct addrinfo * _connecting_addrlist;
stream_socketbuf & stream_sockbuf;
public:
tcp_socket_stream();
tcp_socket_stream(SOCKET_TYPE socket);
tcp_socket_stream(const std::string& address, int service,
bool nonblock = false);
tcp_socket_stream(const std::string& address, int service,
unsigned int milliseconds);
virtual ~tcp_socket_stream();
void open(const std::string& address, int service, bool nonblock = false);
void open(const std::string& address, int service, unsigned int milliseconds);
virtual void close();
virtual SOCKET_TYPE getSocket() const;
const std::string getRemoteHost(bool lookup = false) const;
const std::string getRemoteService(bool lookup = false) const;
bool isReady(unsigned int milliseconds = 0);
};
class dgram_socket_stream : public basic_socket_stream {
private:
dgram_socket_stream(const dgram_socket_stream&);
dgram_socket_stream& operator=(const dgram_socket_stream& socket);
protected:
dgram_socketbuf & dgram_sockbuf;
int bindToIpService(int service, int type, int protocol);
public:
dgram_socket_stream();
virtual ~dgram_socket_stream();
bool setTarget(const std::string& address, unsigned port) {
return dgram_sockbuf.setTarget(address, port, m_protocol);
}
void setOutpeer(const sockaddr_storage& peer) {
return dgram_sockbuf.setOutpeer(peer);
}
const sockaddr_storage & getOutpeer() const {
return dgram_sockbuf.getOutpeer();
}
const sockaddr_storage & getInpeer() const {
return dgram_sockbuf.getInpeer();
}
SOCKLEN getOutpeerSize() const {
return dgram_sockbuf.getOutpeerSize();
}
SOCKLEN getInpeerSize() const {
return dgram_sockbuf.getInpeerSize();
}
};
/////////////////////////////////////////////////////////////////////////////
// class udp_socket_stream
/////////////////////////////////////////////////////////////////////////////
class udp_socket_stream : public dgram_socket_stream {
private:
udp_socket_stream(const udp_socket_stream&);
udp_socket_stream& operator=(const udp_socket_stream& socket);
public:
udp_socket_stream();
virtual ~udp_socket_stream();
int open(int service);
};
/////////////////////////////////////////////////////////////////////////////
// class raw_socket_stream
/////////////////////////////////////////////////////////////////////////////
#ifdef SOCK_RAW
class raw_socket_stream : public dgram_socket_stream {
private:
raw_socket_stream(const raw_socket_stream&);
raw_socket_stream& operator=(const raw_socket_stream& socket);
public:
raw_socket_stream(FreeSockets::IP_Protocol proto=FreeSockets::proto_RAW);
virtual ~raw_socket_stream();
void setProtocol(FreeSockets::IP_Protocol proto);
bool setTarget(const std::string& address, unsigned port) {
return dgram_sockbuf.setTarget(address, port, m_protocol);
}
bool setBroadcast(bool opt=false);
};
#endif // SOCK_RAW
#endif // RGJ_FREE_STREAM_H_
|