2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
9 #include "wvfdstream.h"
11 #include <netinet/in.h>
14 * WvIPRawStream can send and receive packets on a connectionless IP socket.
16 * In the constructor, the socket is attached using bind() to the given
17 * _local address. If the address is 0.0.0.0, all addresses on the local
18 * host are used; if the port is 0, an available port number is chosen
21 * If the _rem address is 0.0.0.0, the port is not connect()ed. That means
22 * it can receive packets from anywhere and send them to anywhere. The
23 * src() and setdest() functions are useful for this. If _rem is not 0.0.0.0,
24 * connect() is called and the socket will only accept data to/from the
25 * specified remote UDP address.
27 * Buffering: all the usual WvStream-style input buffering is available,
28 * including getline(), but because input packets may get lost it is of
29 * limited usefulness. Buffering will cause particular confusion if the
30 * socket is not connect()ed.
32 class WvIPRawStream
: public WvFDStream
35 /** connect a new socket */
36 WvIPRawStream(const WvIPAddr
&_local
, const WvIPAddr
&_rem
,
37 int ip_protocol
= IPPROTO_RAW
);
38 virtual ~WvIPRawStream();
40 const WvAddr
*local() const;
43 * return the remote address (source of incoming packets, target of
44 * outgoing packets). This is the last host sent to or received from,
45 * whichever was more recent.
47 virtual const WvAddr
*src() const;
48 void setdest(const WvIPAddr
&_remaddr
)
49 { remaddr
= _remaddr
; }
51 void enable_broadcasts();
54 WvIPAddr localaddr
, remaddr
;
56 virtual size_t uread(void *buf
, size_t count
);
57 virtual size_t uwrite(const void *buf
, size_t count
);
60 const char *wstype() const { return "WvIPRawStream"; }