[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4432 - gnuradio/branches/developers/trondeau/udp/gnur
From: |
trondeau |
Subject: |
[Commit-gnuradio] r4432 - gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io |
Date: |
Thu, 8 Feb 2007 09:50:50 -0700 (MST) |
Author: trondeau
Date: 2007-02-08 09:50:50 -0700 (Thu, 08 Feb 2007)
New Revision: 4432
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i
Log:
host info can now be addressed using either the host name or the ip address
(apparently, not everyone knows every IP address of the internet...) and
improved documentation
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc
2007-02-08 15:26:45 UTC (rev 4431)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc
2007-02-08 16:50:50 UTC (rev 4432)
@@ -23,31 +23,56 @@
#include <gr_udp_sink.h>
#include <gr_io_signature.h>
#include <stdexcept>
+#include <netdb.h>
#define SNK_VERBOSE 0
gr_udp_sink::gr_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
int payload_size)
: gr_sync_block ("udp_sink",
gr_make_io_signature (1, 1, itemsize),
gr_make_io_signature (0, 0, 0)),
d_itemsize (itemsize), d_updated(false), d_payload_size(payload_size)
{
+ int ret = 0;
+
// Set up the address stucture for the local address and port numbers
- inet_aton(ipaddrl, &d_ipaddr_local); // format IP address
- inet_aton(ipaddrr, &d_ipaddr_remote); // format IP address
- d_port_local = htons(portl); // format port number
- d_port_remote = htons(portr); // format port number
+ // Get the source IP address from the host name
+ struct hostent *hsrc = gethostbyname(src);
+ if(hsrc) { // if the source was provided as a host namex
+ d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0];
+ }
+ else { // assume it was specified as an IP address
+ if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address
+ perror("Not a valid source IP address or host name");
+ throw std::runtime_error("can't initialize source socket");
+ }
+ }
- d_sockaddr_local.sin_family = AF_INET;
- d_sockaddr_local.sin_addr = d_ipaddr_local;
- d_sockaddr_local.sin_port = d_port_local;
+ // Get the destination IP address from the host name
+ struct hostent *hdst = gethostbyname(dst);
+ if(hdst) { // if the source was provided as a host namex
+ d_ip_dst = *(struct in_addr*)hdst->h_addr_list[0];
+ }
+ else { // assume it was specified as an IP address
+ if((ret=inet_aton(dst, &d_ip_dst)) == 0) { // format IP address
+ perror("Not a valid destination IP address or host name");
+ throw std::runtime_error("can't initialize destination socket");
+ }
+ }
- d_sockaddr_remote.sin_family = AF_INET;
- d_sockaddr_remote.sin_addr = d_ipaddr_remote;
- d_sockaddr_remote.sin_port = d_port_remote;
+ d_port_src = htons(port_src); // format port number
+ d_port_dst = htons(port_dst); // format port number
+
+ d_sockaddr_src.sin_family = AF_INET;
+ d_sockaddr_src.sin_addr = d_ip_src;
+ d_sockaddr_src.sin_port = d_port_src;
+
+ d_sockaddr_dst.sin_family = AF_INET;
+ d_sockaddr_dst.sin_addr = d_ip_dst;
+ d_sockaddr_dst.sin_port = d_port_dst;
open();
}
@@ -56,13 +81,13 @@
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
int payload_size)
{
return gr_udp_sink_sptr (new gr_udp_sink (itemsize,
- ipaddrl, portl,
- ipaddrr, portr,
+ src, port_src,
+ dst, port_dst,
payload_size));
}
@@ -99,13 +124,13 @@
}
// bind socket to an address and port number to listen on
- if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) ==
-1) {
+ if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) ==
-1) {
perror("socket bind");
throw std::runtime_error("can't bind socket");
}
// Not sure if we should throw here or allow retries
- if(connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct sockaddr))
== -1) {
+ if(connect(d_socket, (sockaddr*)&d_sockaddr_dst, sizeof(struct sockaddr)) ==
-1) {
perror("socket connect");
throw std::runtime_error("can't connect to socket");
}
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h
2007-02-08 15:26:45 UTC (rev 4431)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h
2007-02-08 16:50:50 UTC (rev 4432)
@@ -35,39 +35,43 @@
* \brief Write stream to an UDP port (over UDP).
* \ingroup sink
*
- * source
+ * \param itemsize The size (in bytes) of the item datatype
+ * \param src The source address as either the host name or the
'numbers-and-dots'
+ * IP address
* \param port_src Destination port to bind to (0 allows socket to choose
an appropriate port)
+ * \param dst The destination address as either the host name or the
'numbers-and-dots'
+ * IP address
* \param port_dst Destination port to connect to
* \param payload_size UDP payload size by default set to
- 1472 = (1500 PAYLOAD_SIZE - (8 byte UDP header) -
(20 byte IP header))
+ * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP
header))
*/
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short port_src,
- const char *ipaddrr, unsigned short port_dst,
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
int payload_size=1472);
class gr_udp_sink : public gr_sync_block
{
friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short
portl,
- const char *ipaddrr, unsigned short
portr,
+ const char *src, unsigned short
port_src,
+ const char *dst, unsigned short
port_dst,
int payload_size);
private:
size_t d_itemsize;
bool d_updated;
omni_mutex d_mutex;
- int d_payload_size; // maximum transmission unit
(packet length)
+ int d_payload_size; // maximum transmission unit (packet
length)
int d_socket; // handle to socket
int d_socket_rcv; // handle to socket retuned in the accept
call
- struct in_addr d_ipaddr_local; // store the local IP address to use
- struct in_addr d_ipaddr_remote; // store the remote IP address that
connected to us
- unsigned short d_port_local; // the port number to open for connections
to this service
- unsigned short d_port_remote; // port number of the remove system
- sockaddr_in d_sockaddr_local; // store the local sockaddr data
(formatted IP address and port number)
- sockaddr_in d_sockaddr_remote; // store the remote sockaddr data
(formatted IP address and port number)
+ struct in_addr d_ip_src; // store the source ip info
+ struct in_addr d_ip_dst; // store the destination ip info
+ unsigned short d_port_src; // the port number to open for connections
to this service
+ unsigned short d_port_dst; // port number of the remove system
+ sockaddr_in d_sockaddr_src; // store the source sockaddr data
(formatted IP address and port number)
+ sockaddr_in d_sockaddr_dst; // store the destination sockaddr data
(formatted IP address and port number)
protected:
gr_udp_sink (size_t itemsize,
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i
2007-02-08 15:26:45 UTC (rev 4431)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i
2007-02-08 16:50:50 UTC (rev 4432)
@@ -25,16 +25,16 @@
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
int payload_size=1472);
class gr_udp_sink : public gr_sync_block
{
protected:
gr_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
int payload_size);
bool open();
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
2007-02-08 15:26:45 UTC (rev 4431)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
2007-02-08 16:50:50 UTC (rev 4432)
@@ -24,23 +24,37 @@
#include <gr_io_signature.h>
#include <stdexcept>
#include <errno.h>
+#include <netdb.h>
#define SRC_VERBOSE 0
-gr_udp_source::gr_udp_source(size_t itemsize, const char *ipaddr,
- unsigned short port, int payload_size)
+gr_udp_source::gr_udp_source(size_t itemsize, const char *src,
+ unsigned short port_src, int payload_size)
: gr_sync_block ("udp_source",
gr_make_io_signature(0, 0, 0),
gr_make_io_signature(1, 1, itemsize)),
d_itemsize(itemsize), d_updated(false), d_payload_size(payload_size),
d_residual(0), d_temp_offset(0)
{
+ int ret = 0;
+
// Set up the address stucture for the local address and port numbers
- inet_aton(ipaddr, &d_ipaddr_local); // format IP address
- d_port_local = htons(port); // format port number
+ // Get the source IP address from the host name
+ struct hostent *hsrc = gethostbyname(src);
+ if(hsrc) { // if the source was provided as a host namex
+ d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0];
+ }
+ else { // assume it was specified as an IP address
+ if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address
+ perror("Not a valid source IP address or host name");
+ throw std::runtime_error("can't initialize source socket");
+ }
+ }
+
+ d_port_src = htons(port_src); // format port number
- d_sockaddr_local.sin_family = AF_INET;
- d_sockaddr_local.sin_addr = d_ipaddr_local;
- d_sockaddr_local.sin_port = d_port_local;
+ d_sockaddr_src.sin_family = AF_INET;
+ d_sockaddr_src.sin_addr = d_ip_src;
+ d_sockaddr_src.sin_port = d_port_src;
d_temp_buff = new char[d_payload_size]; // allow it to hold up to
payload_size bytes
@@ -99,7 +113,7 @@
}
// bind socket to an address and port number to listen on
- if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) ==
-1) {
+ if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) ==
-1) {
perror("socket bind");
throw std::runtime_error("can't bind socket");
}
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h
2007-02-08 15:26:45 UTC (rev 4431)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h
2007-02-08 16:50:50 UTC (rev 4432)
@@ -35,40 +35,39 @@
* \brief Write stream to an UDP port (over UDP).
* \ingroup sink
*
- * \param port The port number on which the socket listens for data
- * \param payload_size Slight misnomer; this is not the ethernet PAYLOAD_SIZE
but the UDP payload size;
- * by default it is set to 1472 (1500 PAYLOAD_SIZE - (8 byte UDP
header) - (20 byte IP header))
+ * \param src The source address as either the host name or the
'numbers-and-dots'
+ * IP address
+ * \param port_src The port number on which the socket listens for data
+ * \param payload_size UDP payload size by default set to
+ * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP
header))
*/
-gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *ipaddr,
- unsigned short port, int
payload_size=1472);
+gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src,
+ unsigned short port_src, int
payload_size=1472);
class gr_udp_source : public gr_sync_block
{
- friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char
*ipaddr,
- unsigned short port, int
payload_size);
+ friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char
*src,
+ unsigned short port_src, int
payload_size);
private:
size_t d_itemsize;
bool d_updated;
omni_mutex d_mutex;
- int d_payload_size; // maximum transmission unit
(packet length)
+ int d_payload_size; // maximum transmission unit (packet length)
int d_socket; // handle to socket
int d_socket_rcv; // handle to socket retuned in the accept
call
- struct in_addr d_ipaddr_local; // store the local IP address to use
- struct in_addr d_ipaddr_remote; // store the remote IP address that
connected to us
- unsigned short d_port_local; // the port number to open for connections
to this service
- unsigned short d_port_remote; // port number of the remove system
- sockaddr_in d_sockaddr_local; // store the local sockaddr data
(formatted IP address and port number)
- sockaddr_in d_sockaddr_remote; // store the remote sockaddr data
(formatted IP address and port number)
+ struct in_addr d_ip_src; // store the local IP address to use
+ unsigned short d_port_src; // the port number to open for connections
to this service
+ sockaddr_in d_sockaddr_src; // store the local sockaddr data (formatted
IP address and port number)
char *d_temp_buff; // hold buffer between calls
ssize_t d_residual; // hold information about number of bytes stored in
the temp buffer
size_t d_temp_offset; // point to temp buffer location offset
protected:
- gr_udp_source(size_t itemsize, const char *ipaddr, unsigned short port, int
payload_size);
+ gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, int
payload_size);
public:
~gr_udp_source();
Modified:
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i
===================================================================
---
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i
2007-02-08 15:26:45 UTC (rev 4431)
+++
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i
2007-02-08 16:50:50 UTC (rev 4432)
@@ -23,14 +23,14 @@
GR_SWIG_BLOCK_MAGIC(gr,udp_source)
gr_udp_source_sptr
-gr_make_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, int payload_size=1472);
+gr_make_udp_source (size_t itemsize, const char *src,
+ unsigned short port_src, int payload_size=1472);
class gr_udp_source : public gr_sync_block
{
protected:
- gr_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, int payload_size);
+ gr_udp_source (size_t itemsize, const char *src,
+ unsigned short port_src, int payload_size);
public:
~gr_udp_source ();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4432 - gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io,
trondeau <=