mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
reply with alert to any connection attempt when in maint mode
This commit is contained in:
parent
f06d129c24
commit
9023440a88
2 changed files with 13 additions and 11 deletions
|
@ -1421,6 +1421,10 @@ maint_str_loop( int udpsock, const char* str )
|
||||||
{
|
{
|
||||||
assert( -1 != udpsock );
|
assert( -1 != udpsock );
|
||||||
int len = 1 + strlen(str);
|
int len = 1 + strlen(str);
|
||||||
|
unsigned char outbuf[len + 2];
|
||||||
|
outbuf[0] = XWPDEV_PROTO_VERSION;
|
||||||
|
outbuf[1] = XWPDEV_ALERT;
|
||||||
|
memcpy( &outbuf[2], str, len );
|
||||||
|
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
|
@ -1441,18 +1445,11 @@ maint_str_loop( int udpsock, const char* str )
|
||||||
ssize_t nRead = recvfrom( udpsock, buf, sizeof(buf), 0 /*flags*/,
|
ssize_t nRead = recvfrom( udpsock, buf, sizeof(buf), 0 /*flags*/,
|
||||||
&saddr.addr, &fromlen );
|
&saddr.addr, &fromlen );
|
||||||
|
|
||||||
if ( 2 <= nRead ) {
|
if ( 2 <= nRead && buf[0] == XWPDEV_PROTO_VERSION ) {
|
||||||
if ( buf[0] == XWPDEV_PROTO_VERSION && buf[1] == XWPDEV_REG ) {
|
send_via_udp( udpsock, &saddr.addr, outbuf, sizeof(outbuf) );
|
||||||
// reply, reusing buffer
|
|
||||||
buf[1] = XWPDEV_MSGRSP;
|
|
||||||
memcpy( &buf[2], str, len );
|
|
||||||
send_via_udp( udpsock, &saddr.addr, buf, 2 + len );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // for
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1662,7 +1659,7 @@ main( int argc, char** argv )
|
||||||
|
|
||||||
if ( !!maint_str ) {
|
if ( !!maint_str ) {
|
||||||
maint_str_loop( g_udpsock, maint_str );
|
maint_str_loop( g_udpsock, maint_str );
|
||||||
exit( 0 );
|
exit( 1 ); // should never exit
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Needs to be reset after a crash/respawn */
|
/* Needs to be reset after a crash/respawn */
|
||||||
|
|
|
@ -33,6 +33,11 @@
|
||||||
typedef
|
typedef
|
||||||
#endif
|
#endif
|
||||||
enum { XWPDEV_NONE /* 0 is an illegal value */
|
enum { XWPDEV_NONE /* 0 is an illegal value */
|
||||||
|
,XWPDEV_ALERT /* relay->device: provides a string message to
|
||||||
|
present to the user (with device allowed not
|
||||||
|
to present the same string more than once)
|
||||||
|
format: proto: 1, this enum: 1,
|
||||||
|
null-terminnated string: varies */
|
||||||
,XWPDEV_REG /* dev->relay: device registers self and
|
,XWPDEV_REG /* dev->relay: device registers self and
|
||||||
self-selected (e.g. gcm) or assigned devid
|
self-selected (e.g. gcm) or assigned devid
|
||||||
format: proto: 1; this enum: 1; idType: 1,
|
format: proto: 1; this enum: 1; idType: 1,
|
||||||
|
|
Loading…
Reference in a new issue