Skip to content

Commit 534bb33

Browse files
Synced Linux build with Windows build
1 parent 8c56506 commit 534bb33

File tree

9 files changed

+59
-57
lines changed

9 files changed

+59
-57
lines changed

src/vscp/common/vscpmulticast.cpp

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
#include <wx/socket.h>
3838
#include <wx/listimpl.cpp>
3939

40+
#ifdef WIN32
41+
#else
42+
43+
#include <sys/types.h>
44+
#include <sys/socket.h>
45+
#include <netinet/in.h>
46+
#include <arpa/inet.h>
47+
#include <stdio.h>
48+
#include <stdlib.h>
49+
#include <string.h>
50+
#include <unistd.h>
51+
52+
#endif
4053

4154

4255
#include <crc.h>
@@ -78,7 +91,6 @@ void *worksMulticastThread::Entry()
7891
//*************************************************************************
7992

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

89101
WSADATA wsaData; // Windows socket DLL structure
102+
struct ip_mreq mc_req; // multicast request structure
90103

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

143156
// create a socket for sending to the multicast address
144-
if ( ( sock_mc = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) {
157+
if ( ( sock = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 ) {
145158
perror( "socket() failed" );
146159
return NULL;
147160
}
148161

149162
// set the TTL (time to live/hop count) for the send
150-
if ( ( setsockopt( sock_mc, IPPROTO_IP, IP_MULTICAST_TTL,
151-
( void* )&mc_ttl, sizeof( mc_ttl ) ) ) < 0 ) {
163+
if ( ( setsockopt( sock, IPPROTO_IP, IP_MULTICAST_TTL,
164+
( void* )&ttl, sizeof( ttl ) ) ) < 0 ) {
152165
perror( "setsockopt() failed" );
153166
return NULL;
154167
}
155168

156169
// construct a multicast address structure
157170
memset( &mc_addr, 0, sizeof( mc_addr ) );
158171
mc_addr.sin_family = AF_INET;
159-
mc_addr.sin_addr.s_addr = inet_addr( "224.0.23.158" );
160-
mc_addr.sin_port = htons( mc_port );
172+
mc_addr.sin_addr.s_addr = inet_addr( VSCP_MULTICAST_IPV4_ADDRESS_STR);
173+
mc_addr.sin_port = htons( port );
161174

162175
#endif
163176

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

175188
while ( !m_bQuit && !TestDestroy() ) {
@@ -190,7 +203,9 @@ void *worksMulticastThread::Entry()
190203
}
191204
else if ( nRcv == -1 ) {
192205
// Error
193-
nRcv = WSAGetLastError();
206+
#ifdef WIN32
207+
//nRcv = WSAGetLastError();
208+
#endif
194209
wxSleep( 1 ); // Protects from exhausing system if error takes over
195210
continue;
196211
}
@@ -205,11 +220,14 @@ void *worksMulticastThread::Entry()
205220
if ( ( recv_len = recvfrom( sock,
206221
buf, sizeof( buf ), 0,
207222
( struct sockaddr* )&from_addr, &from_len ) ) < 0 ) {
208-
nRcv = WSAGetLastError();
223+
#ifdef WIN32
224+
//nRcv = WSAGetLastError();
225+
#endif
209226
}
210227

211228
#else
212-
if ( ( recv_len = recvfrom( m_sock_mc, recv_str, 1024, MSG_DONTWAIT,
229+
if ( ( recv_len = recvfrom( sock,
230+
buf, sizeof( buf ), MSG_DONTWAIT,
213231
( struct sockaddr* )&from_addr, &from_len ) ) < 0 ) {
214232

215233
}
@@ -245,13 +263,13 @@ void *worksMulticastThread::Entry()
245263
switch ( from_addr.sin_family ) {
246264
case AF_INET: {
247265
struct sockaddr_in *addr_in = ( struct sockaddr_in * )&from_addr;
248-
s = malloc( INET_ADDRSTRLEN );
266+
s = (char *)malloc( INET_ADDRSTRLEN );
249267
inet_ntop( AF_INET, &( addr_in->sin_addr ), s, INET_ADDRSTRLEN );
250268
break;
251269
}
252270
case AF_INET6: {
253271
struct sockaddr_in6 *addr_in6 = ( struct sockaddr_in6 * )&from_addr;
254-
s = malloc( INET6_ADDRSTRLEN );
272+
s = (char *)malloc( INET6_ADDRSTRLEN );
255273
inet_ntop( AF_INET6, &( addr_in6->sin6_addr ), s, INET6_ADDRSTRLEN );
256274
break;
257275
}
@@ -396,6 +414,7 @@ void *worksMulticastThread::Entry()
396414
}
397415

398416

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

405424
// Close the multicast socket
406425
closesocket( sock );
407-
408-
#ifdef WIN32
426+
409427
// Cleanup Winsock
410428
WSACleanup();
429+
#else
430+
close( sock );
411431
#endif
412432

413433
return NULL;

src/vscp/daemon/linux/nbproject/private/configurations.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@
135135
<gdb_interceptlist>
136136
<gdbinterceptoptions gdb_all="false" gdb_unhandled="true" gdb_unexpected="true"/>
137137
</gdb_interceptlist>
138-
<gdb_signals>
139-
</gdb_signals>
140138
<gdb_options>
141139
<DebugOptions>
142140
<option name="debug_command" value="vscpd -s"/>

src/vscp/daemon/linux/nbproject/private/private.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
</file>
3939
</editor-bookmarks>
4040
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
41-
<group>
42-
<file>file:/home/akhe/vscp_software/src/vscp/common/controlobject.cpp</file>
43-
<file>file:/home/akhe/vscp_software/src/vscp/daemon/linux/vscpd.cpp</file>
44-
</group>
41+
<group/>
4542
</open-files>
4643
</project-private>

src/vscp/drivers/level1/can4vscp/linux/nbproject/private/private.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
</data>
1010
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
1111
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
12-
<group>
13-
<file>file:/home/akhe/vscp_software/src/vscp/drivers/level1/can4vscp/common/can4vscpobj.cpp</file>
14-
</group>
12+
<group/>
1513
</open-files>
1614
</project-private>

src/vscp/vscpworks/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ VSCPWORKS_OBJECTS = vscpworks.o dlgvscpmsg.o \
7777
../common/register.o \
7878
../common/canalconfobj.o \
7979
../common/vscpmulticast.o \
80+
../common/knownnodes.o \
8081
$(RESOURCEOBJECT)
8182

8283
ALWAYS_BUILD = ../../common/crc.o \

src/vscp/vscpworks/nbproject/configurations.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<logicalFolder name="vscp" displayName="vscp" projectFiles="true">
1717
<logicalFolder name="common" displayName="common" projectFiles="true">
1818
<itemPath>../common/canal.h</itemPath>
19+
<itemPath>../common/canal_macro.h</itemPath>
1920
<itemPath>../common/canalconfobj.cpp</itemPath>
2021
<itemPath>../common/canalconfobj.h</itemPath>
2122
<itemPath>../common/canaldlldef.h</itemPath>
@@ -26,6 +27,7 @@
2627
<itemPath>../common/dllwrapper.h</itemPath>
2728
<itemPath>../common/guid.cpp</itemPath>
2829
<itemPath>../common/guid.h</itemPath>
30+
<itemPath>../common/knownnodes.h</itemPath>
2931
<itemPath>../common/mdf.cpp</itemPath>
3032
<itemPath>../common/mdf.h</itemPath>
3133
<itemPath>../common/register.cpp</itemPath>
@@ -38,6 +40,8 @@
3840
<itemPath>../common/vscpeventhelper.h</itemPath>
3941
<itemPath>../common/vscphelper.cpp</itemPath>
4042
<itemPath>../common/vscphelper.h</itemPath>
43+
<itemPath>../common/vscpmulticast.cpp</itemPath>
44+
<itemPath>../common/vscpmulticast.h</itemPath>
4145
<itemPath>../common/vscpremotetcpif.cpp</itemPath>
4246
<itemPath>../common/vscpremotetcpif.h</itemPath>
4347
</logicalFolder>
@@ -220,18 +224,18 @@
220224
<item path="../common/mdf.cpp" ex="false" tool="1" flavor2="4">
221225
<ccTool flags="0">
222226
<incDir>
227+
<pElem>.</pElem>
223228
<pElem>../common</pElem>
224229
<pElem>../../common</pElem>
225-
<pElem>.</pElem>
226230
</incDir>
227231
</ccTool>
228232
</item>
229233
<item path="../common/register.cpp" ex="false" tool="1" flavor2="4">
230234
<ccTool flags="0">
231235
<incDir>
236+
<pElem>.</pElem>
232237
<pElem>../common</pElem>
233238
<pElem>../../common</pElem>
234-
<pElem>.</pElem>
235239
</incDir>
236240
</ccTool>
237241
</item>
@@ -253,6 +257,15 @@
253257
</incDir>
254258
</ccTool>
255259
</item>
260+
<item path="../common/vscpmulticast.cpp" ex="false" tool="1" flavor2="0">
261+
<ccTool flags="0">
262+
<incDir>
263+
<pElem>.</pElem>
264+
<pElem>../common</pElem>
265+
<pElem>../../common</pElem>
266+
</incDir>
267+
</ccTool>
268+
</item>
256269
<item path="../common/vscpremotetcpif.cpp" ex="false" tool="1" flavor2="4">
257270
<ccTool flags="0">
258271
<incDir>

0 commit comments

Comments
 (0)