Skip to content

Commit

Permalink
Synced Linux build with Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Oct 29, 2015
1 parent 8c56506 commit 534bb33
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 57 deletions.
48 changes: 34 additions & 14 deletions src/vscp/common/vscpmulticast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
#include <wx/socket.h>
#include <wx/listimpl.cpp>

#ifdef WIN32
#else

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#endif


#include <crc.h>
Expand Down Expand Up @@ -78,7 +91,6 @@ void *worksMulticastThread::Entry()
//*************************************************************************

int sock; // socket descriptor
struct ip_mreq mc_req; // multicast request structure
struct sockaddr_in mc_addr; // socket address structure
unsigned short port = VSCP_MULTICAST_ANNNOUNCE_PORT; // multicast port
unsigned char ttl = 1; // time to live (hop count)
Expand All @@ -87,6 +99,7 @@ void *worksMulticastThread::Entry()
#ifdef WIN32

WSADATA wsaData; // Windows socket DLL structure
struct ip_mreq mc_req; // multicast request structure

// Load Winsock 2.0 DLL
if ( WSAStartup( MAKEWORD( 2, 0 ), &wsaData ) != 0 ) {
Expand Down Expand Up @@ -141,23 +154,23 @@ void *worksMulticastThread::Entry()
#else

// create a socket for sending to the multicast address
if ( ( sock_mc = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) {
if ( ( sock = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) {
perror( "socket() failed" );
return NULL;
}

// set the TTL (time to live/hop count) for the send
if ( ( setsockopt( sock_mc, IPPROTO_IP, IP_MULTICAST_TTL,
( void* )&mc_ttl, sizeof( mc_ttl ) ) ) < 0 ) {
if ( ( setsockopt( sock, IPPROTO_IP, IP_MULTICAST_TTL,
( void* )&ttl, sizeof( ttl ) ) ) < 0 ) {
perror( "setsockopt() failed" );
return NULL;
}

// construct a multicast address structure
memset( &mc_addr, 0, sizeof( mc_addr ) );
mc_addr.sin_family = AF_INET;
mc_addr.sin_addr.s_addr = inet_addr( "224.0.23.158" );
mc_addr.sin_port = htons( mc_port );
mc_addr.sin_addr.s_addr = inet_addr( VSCP_MULTICAST_IPV4_ADDRESS_STR);
mc_addr.sin_port = htons( port );

#endif

Expand All @@ -169,7 +182,7 @@ void *worksMulticastThread::Entry()
char buf[ 1024 ]; // buffer to receive string
int recv_len; // length of string received
struct sockaddr_in from_addr; // packet source
int from_len; // source addr length
socklen_t from_len; // source addr length
int nRcv;

while ( !m_bQuit && !TestDestroy() ) {
Expand All @@ -190,7 +203,9 @@ void *worksMulticastThread::Entry()
}
else if ( nRcv == -1 ) {
// Error
nRcv = WSAGetLastError();
#ifdef WIN32
//nRcv = WSAGetLastError();
#endif
wxSleep( 1 ); // Protects from exhausing system if error takes over
continue;
}
Expand All @@ -205,11 +220,14 @@ void *worksMulticastThread::Entry()
if ( ( recv_len = recvfrom( sock,
buf, sizeof( buf ), 0,
( struct sockaddr* )&from_addr, &from_len ) ) < 0 ) {
nRcv = WSAGetLastError();
#ifdef WIN32
//nRcv = WSAGetLastError();
#endif
}

#else
if ( ( recv_len = recvfrom( m_sock_mc, recv_str, 1024, MSG_DONTWAIT,
if ( ( recv_len = recvfrom( sock,
buf, sizeof( buf ), MSG_DONTWAIT,
( struct sockaddr* )&from_addr, &from_len ) ) < 0 ) {

}
Expand Down Expand Up @@ -245,13 +263,13 @@ void *worksMulticastThread::Entry()
switch ( from_addr.sin_family ) {
case AF_INET: {
struct sockaddr_in *addr_in = ( struct sockaddr_in * )&from_addr;
s = malloc( INET_ADDRSTRLEN );
s = (char *)malloc( INET_ADDRSTRLEN );
inet_ntop( AF_INET, &( addr_in->sin_addr ), s, INET_ADDRSTRLEN );
break;
}
case AF_INET6: {
struct sockaddr_in6 *addr_in6 = ( struct sockaddr_in6 * )&from_addr;
s = malloc( INET6_ADDRSTRLEN );
s = (char *)malloc( INET6_ADDRSTRLEN );
inet_ntop( AF_INET6, &( addr_in6->sin6_addr ), s, INET6_ADDRSTRLEN );
break;
}
Expand Down Expand Up @@ -396,6 +414,7 @@ void *worksMulticastThread::Entry()
}


#ifdef WIN32
// send a DROP MEMBERSHIP message via setsockopt
if ( ( setsockopt( sock, IPPROTO_IP, IP_DROP_MEMBERSHIP,
( const char * )&mc_req, sizeof( mc_req ) ) ) < 0 ) {
Expand All @@ -404,10 +423,11 @@ void *worksMulticastThread::Entry()

// Close the multicast socket
closesocket( sock );

#ifdef WIN32

// Cleanup Winsock
WSACleanup();
#else
close( sock );
#endif

return NULL;
Expand Down
2 changes: 0 additions & 2 deletions src/vscp/daemon/linux/nbproject/private/configurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
<gdb_interceptlist>
<gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
</gdb_interceptlist>
<gdb_signals>
</gdb_signals>
<gdb_options>
<DebugOptions>
<option name="debug_command" value="vscpd -s"/>
Expand Down
5 changes: 1 addition & 4 deletions src/vscp/daemon/linux/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
</file>
</editor-bookmarks>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/akhe/vscp_software/src/vscp/common/controlobject.cpp</file>
<file>file:/home/akhe/vscp_software/src/vscp/daemon/linux/vscpd.cpp</file>
</group>
<group/>
</open-files>
</project-private>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
</data>
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/akhe/vscp_software/src/vscp/drivers/level1/can4vscp/common/can4vscpobj.cpp</file>
</group>
<group/>
</open-files>
</project-private>
1 change: 1 addition & 0 deletions src/vscp/vscpworks/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ VSCPWORKS_OBJECTS = vscpworks.o dlgvscpmsg.o \
../common/register.o \
../common/canalconfobj.o \
../common/vscpmulticast.o \
../common/knownnodes.o \
$(RESOURCEOBJECT)

ALWAYS_BUILD = ../../common/crc.o \
Expand Down
17 changes: 15 additions & 2 deletions src/vscp/vscpworks/nbproject/configurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<logicalFolder name="vscp" displayName="vscp" projectFiles="true">
<logicalFolder name="common" displayName="common" projectFiles="true">
<itemPath>../common/canal.h</itemPath>
<itemPath>../common/canal_macro.h</itemPath>
<itemPath>../common/canalconfobj.cpp</itemPath>
<itemPath>../common/canalconfobj.h</itemPath>
<itemPath>../common/canaldlldef.h</itemPath>
Expand All @@ -26,6 +27,7 @@
<itemPath>../common/dllwrapper.h</itemPath>
<itemPath>../common/guid.cpp</itemPath>
<itemPath>../common/guid.h</itemPath>
<itemPath>../common/knownnodes.h</itemPath>
<itemPath>../common/mdf.cpp</itemPath>
<itemPath>../common/mdf.h</itemPath>
<itemPath>../common/register.cpp</itemPath>
Expand All @@ -38,6 +40,8 @@
<itemPath>../common/vscpeventhelper.h</itemPath>
<itemPath>../common/vscphelper.cpp</itemPath>
<itemPath>../common/vscphelper.h</itemPath>
<itemPath>../common/vscpmulticast.cpp</itemPath>
<itemPath>../common/vscpmulticast.h</itemPath>
<itemPath>../common/vscpremotetcpif.cpp</itemPath>
<itemPath>../common/vscpremotetcpif.h</itemPath>
</logicalFolder>
Expand Down Expand Up @@ -220,18 +224,18 @@
<item path="../common/mdf.cpp" ex="false" tool="1" flavor2="4">
<ccTool flags="0">
<incDir>
<pElem>.</pElem>
<pElem>../common</pElem>
<pElem>../../common</pElem>
<pElem>.</pElem>
</incDir>
</ccTool>
</item>
<item path="../common/register.cpp" ex="false" tool="1" flavor2="4">
<ccTool flags="0">
<incDir>
<pElem>.</pElem>
<pElem>../common</pElem>
<pElem>../../common</pElem>
<pElem>.</pElem>
</incDir>
</ccTool>
</item>
Expand All @@ -253,6 +257,15 @@
</incDir>
</ccTool>
</item>
<item path="../common/vscpmulticast.cpp" ex="false" tool="1" flavor2="0">
<ccTool flags="0">
<incDir>
<pElem>.</pElem>
<pElem>../common</pElem>
<pElem>../../common</pElem>
</incDir>
</ccTool>
</item>
<item path="../common/vscpremotetcpif.cpp" ex="false" tool="1" flavor2="4">
<ccTool flags="0">
<incDir>
Expand Down
Loading

0 comments on commit 534bb33

Please sign in to comment.