[Spread-cvs] commit: r446 - trunk/daemon
jonathan at spread.org
jonathan at spread.org
Fri Jan 6 22:19:54 EST 2012
Author: jonathan
Date: 2012-01-06 22:19:54 -0500 (Fri, 06 Jan 2012)
New Revision: 446
Modified:
trunk/daemon/Changelog
trunk/daemon/alarm.h
trunk/daemon/data_link.c
trunk/daemon/data_link.h
Log:
Add IS_MCAST_ADDR(), IS_MCAST_ADDR_NET() and IP_NET() macros for printing an testing IP addresses. Use them in data_link functions.
Modified: trunk/daemon/Changelog
===================================================================
--- trunk/daemon/Changelog 2012-01-07 01:28:25 UTC (rev 445)
+++ trunk/daemon/Changelog 2012-01-07 03:19:54 UTC (rev 446)
@@ -1,3 +1,11 @@
+Fri Jan 6 22:15:45 2012 John Schultz <jschultz at spreadconcepts.com>
+
+ * alarm.h, data_link.h, data_link.c (DL_init_channel,DL_send):
+ Add IS_MCAST_ADDR() and IS_MCAST_ADDR_NET() macros. Add IP_NET()
+ macros to print IP addresses in network byte order. Use new
+ macros in data_link functions that print IPs.
+ Patch provided by Juan Pizzorno.
+
Fri Jan 6 20:26:56 2012 John Schultz <jschultz at spreadconcepts.com>
* sp.c (recv_nointr_timeout): Remove printf calls from libary.
Modified: trunk/daemon/alarm.h
===================================================================
--- trunk/daemon/alarm.h 2012-01-07 01:28:25 UTC (rev 445)
+++ trunk/daemon/alarm.h 2012-01-07 03:19:54 UTC (rev 446)
@@ -113,9 +113,20 @@
void Alarm_set_interactive(void);
int Alarm_get_interactive(void);
-#define IP1( address ) ( ( 0xFF000000 & (address) ) >> 24 )
-#define IP2( address ) ( ( 0x00FF0000 & (address) ) >> 16 )
-#define IP3( address ) ( ( 0x0000FF00 & (address) ) >> 8 )
-#define IP4( address ) ( ( 0x000000FF & (address) ) )
+#define IPF "%d.%d.%d.%d"
+#define IP1(address) ( (int) ( ( (address) >> 24 ) & 0xFF ) )
+#define IP2(address) ( (int) ( ( (address) >> 16 ) & 0xFF ) )
+#define IP3(address) ( (int) ( ( (address) >> 8 ) & 0xFF ) )
+#define IP4(address) ( (int) ( ( (address) >> 0 ) & 0xFF ) )
+
+#define IP(address) IP1(address), IP2(address), IP3(address), IP4(address)
+
+#define IP1_NET(address) ( (int) ( (unsigned char*) &(address) )[0] )
+#define IP2_NET(address) ( (int) ( (unsigned char*) &(address) )[1] )
+#define IP3_NET(address) ( (int) ( (unsigned char*) &(address) )[2] )
+#define IP4_NET(address) ( (int) ( (unsigned char*) &(address) )[3] )
+
+#define IP_NET(address) IP1_NET(address), IP2_NET(address), IP3_NET(address), IP4_NET(address)
+
#endif /* INC_ALARM */
Modified: trunk/daemon/data_link.c
===================================================================
--- trunk/daemon/data_link.c 2012-01-07 01:28:25 UTC (rev 445)
+++ trunk/daemon/data_link.c 2012-01-07 03:19:54 UTC (rev 446)
@@ -66,7 +66,6 @@
channel chan;
struct sockaddr_in soc_addr;
int on=1;
- int i1,i2,i3,i4;
#ifdef IP_MULTICAST_TTL
unsigned char ttl_val;
#endif
@@ -119,16 +118,12 @@
if(bind( chan, (struct sockaddr *) &soc_addr,
sizeof(soc_addr)) == -1)
{
- Alarm( EXIT, "DL_init_channel: bind error (%d): %s for port %d, with sockaddr (%d.%d.%d.%d: %d) probably already running \n", sock_errno, sock_strerror(sock_errno), port, IP1(soc_addr.sin_addr.s_addr),IP2(soc_addr.sin_addr.s_addr),IP3(soc_addr.sin_addr.s_addr),IP4(soc_addr.sin_addr.s_addr), soc_addr.sin_port );
+ Alarm( EXIT, "DL_init_channel: bind error (%d): %s for port %d, with sockaddr (" IPF ": %d) probably already running\n", sock_errno, sock_strerror(sock_errno), port, IP_NET(soc_addr.sin_addr.s_addr), ntohs(soc_addr.sin_port));
}
- Alarm( DATA_LINK, "DL_init_channel: bind for recv_channel for port %d with chan %d ok\n",
- port, chan);
+ Alarm( DATA_LINK, "DL_init_channel: bind for recv_channel for " IPF " port %d with chan %d ok\n",
+ IP_NET(soc_addr.sin_addr.s_addr), port, chan);
- i1 = (mcast_address >> 24) & 0x000000ff;
- i2 = (mcast_address >> 16) & 0x000000ff;
- i3 = (mcast_address >> 8) & 0x000000ff;
- i4 = mcast_address & 0x000000ff;
- if( i1 >=224 && i1 < 240 )
+ if( IS_MCAST_ADDR(mcast_address) )
{
#ifdef IP_MULTICAST_TTL
struct ip_mreq mreq;
@@ -141,12 +136,12 @@
if (setsockopt(chan, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq,
sizeof(mreq)) < 0)
{
- Alarm( EXIT, "DL_init_channel: problem in setsockopt to multicast address %d\n", mcast_address );
+ Alarm( EXIT, "DL_init_channel: problem in setsockopt to multicast address " IPF "\n", IP(mcast_address) );
}
- Alarm( DATA_LINK, "DL_init_channel: Joining multicast address %d.%d.%d.%d went ok\n",i1,i2,i3,i4);
+ Alarm( DATA_LINK, "DL_init_channel: Joining multicast address " IPF " went ok\n", IP(mcast_address) );
#else /* no multicast support */
- Alarm( EXIT, "DL_init_channel: Old SunOS architecture does not support IP multicast: %d.%d.%d.%d\n",i1,i2,i3,i4);
+ Alarm( EXIT, "DL_init_channel: Old SunOS architecture does not support IP multicast: " IPF "\n", IP(mcast_address));
#endif
} else {
if (setsockopt(chan, SOL_SOCKET, SO_BROADCAST, (char *)&on,
@@ -244,8 +239,7 @@
if(ret < 0) {
/* delay for a short while */
send_errormsg = sock_strerror(sock_errno);
- Alarm( DATA_LINK, "DL_send: delaying after failure in send to %d.%d.%d.%d, ret is %d\n",
- IP1(address), IP2(address), IP3(address), IP4(address), ret);
+ Alarm( DATA_LINK, "DL_send: delaying after failure in send to " IPF ", ret is %d\n", IP(address), ret);
select( 0, 0, 0, 0, &select_delay );
select_delay.tv_sec = 0;
select_delay.tv_usec = 10000;
@@ -256,14 +250,14 @@
for( i=0; i < scat->num_elements; i++)
Alarm( DATA_LINK, "DL_send: element[%d]: %d bytes\n",
i,scat->elements[i].len);
- Alarm( DATA_LINK, "DL_send: error: %s\n sending %d bytes on channel %d to address %d.%d.%d.%d\n",
- send_errormsg, total_len,chan,IP1(address), IP2(address), IP3(address), IP4(address) );
+ Alarm( DATA_LINK, "DL_send: error: %s\n sending %d bytes on channel %d to address " IPF "\n",
+ send_errormsg, total_len,chan,IP(address) );
}else if(ret < total_len){
Alarm( DATA_LINK, "DL_send: partial sending %d out of %d\n",
ret,total_len);
}
- Alarm( DATA_LINK, "DL_send: sent a message of %d bytes to (%d.%d.%d.%d,%d) on channel %d\n",
- ret,IP1(address), IP2(address),IP3(address), IP4(address),port,chan);
+ Alarm( DATA_LINK, "DL_send: sent a message of %d bytes to (" IPF ":%d) on channel %d\n",
+ ret,IP(address),port,chan);
return(ret);
}
@@ -384,7 +378,7 @@
sport = Flip_int16(source_address.sin_port);
if (src_port != NULL)
*src_port = sport;
- Alarm( DATA_LINK, "\tfrom (%d.%d.%d.%d) with family %d port %d\n", IP1(sip), IP2(sip), IP3(sip), IP4(sip), source_address.sin_family, sport );
+ Alarm( DATA_LINK, "\tfrom (" IPF ") with family %d port %d\n", IP(sip), source_address.sin_family, sport );
}
Alarm( DATA_LINK, "DL_recv: received %d bytes on channel %d\n",
ret, chan );
Modified: trunk/daemon/data_link.h
===================================================================
--- trunk/daemon/data_link.h 2012-01-07 01:28:25 UTC (rev 445)
+++ trunk/daemon/data_link.h 2012-01-07 03:19:54 UTC (rev 446)
@@ -46,6 +46,9 @@
#define RESERVED 0x00000004
#define REUSE_ADDR 0x00000008
+#define IS_MCAST_ADDR(addr) ( ( (addr) & 0xF0000000 ) == 0xE0000000 )
+#define IS_MCAST_ADDR_NET(addr) ( ( (unsigned char*) &(addr) )[0] == 0xE0 )
+
channel DL_init_channel( int32 channel_type, int16 port, int32 mcast_address, int32 interface_address );
void DL_close_channel(channel chan);
int DL_send( channel chan, int32 address, int16 port, sys_scatter *scat );
More information about the Spread-cvs
mailing list