@@ -133,7 +133,8 @@ int main ( int argc, char** argv )
133133 QString strServerListFileName = " " ;
134134 QString strServerInfo = " " ;
135135 QString strServerPublicIP = " " ;
136- QString strServerBindIP = " " ;
136+ QString strServerBindIP4 = " " ;
137+ QString strServerBindIP6 = " " ;
137138 QString strServerListFilter = " " ;
138139 QString strWelcomeMessage = " " ;
139140 QString strClientName = " " ;
@@ -444,14 +445,29 @@ int main ( int argc, char** argv )
444445 if ( GetStringArgument ( argc,
445446 argv,
446447 i,
447- " --serverbindip" , // no short form
448- " --serverbindip " ,
448+ " --serverbindip" , // use short form for compatibility alias
449+ " --serverbindip4 " ,
449450 strArgument ) )
450451 {
451- strServerBindIP = strArgument;
452- qInfo () << qUtf8Printable ( QString ( " - server bind IP: %1" ).arg ( strServerBindIP ) );
453- CommandLineOptions << " --serverbindip" ;
454- ServerOnlyOptions << " --serverbindip" ;
452+ strServerBindIP4 = strArgument;
453+ qInfo () << qUtf8Printable ( QString ( " - server bind IPv4: %1" ).arg ( strServerBindIP4 ) );
454+ CommandLineOptions << " --serverbindip4" ;
455+ ServerOnlyOptions << " --serverbindip4" ;
456+ continue ;
457+ }
458+
459+ // Server Bind IPv6 --------------------------------------------------
460+ if ( GetStringArgument ( argc,
461+ argv,
462+ i,
463+ " --serverbindip6" , // no short form
464+ " --serverbindip6" ,
465+ strArgument ) )
466+ {
467+ strServerBindIP6 = strArgument;
468+ qInfo () << qUtf8Printable ( QString ( " - server bind IPv6: %1" ).arg ( strServerBindIP6 ) );
469+ CommandLineOptions << " --serverbindip6" ;
470+ ServerOnlyOptions << " --serverbindip6" ;
455471 continue ;
456472 }
457473
@@ -787,20 +803,17 @@ int main ( int argc, char** argv )
787803 }
788804 }
789805
790- if ( strDirectoryAddress .isEmpty () )
806+ if ( !strServerPublicIP .isEmpty () )
791807 {
792- if ( !strServerPublicIP .isEmpty () )
808+ if ( strDirectoryAddress .isEmpty () )
793809 {
794810 qWarning () << " Server Public IP will only take effect when registering a server with a directory." ;
795811 strServerPublicIP = " " ;
796812 }
797- }
798- else
799- {
800- if ( !strServerPublicIP.isEmpty () )
813+ else
801814 {
802- QHostAddress InetAddr;
803- if ( ! InetAddr.setAddress ( strServerPublicIP ) )
815+ QHostAddress InetAddr ( strServerPublicIP ) ;
816+ if ( InetAddr.protocol () != QAbstractSocket::IPv4Protocol )
804817 {
805818 qWarning () << " Server Public IP is invalid. Only plain IP addresses are supported." ;
806819 strServerPublicIP = " " ;
@@ -809,13 +822,29 @@ int main ( int argc, char** argv )
809822 }
810823 }
811824
812- if ( !strServerBindIP .isEmpty () )
825+ if ( !strServerBindIP4 .isEmpty () )
813826 {
814- QHostAddress InetAddr;
815- if ( ! InetAddr.setAddress ( strServerBindIP ) )
827+ QHostAddress InetAddr ( strServerBindIP4 ) ;
828+ if ( InetAddr.protocol () != QAbstractSocket::IPv4Protocol )
816829 {
817- qWarning () << " Server Bind IP is invalid. Only plain IP addresses are supported." ;
818- strServerBindIP = " " ;
830+ qCritical () << " Server Bind IPv4 is invalid. Only plain IP addresses are supported." ;
831+ exit ( 1 );
832+ }
833+ }
834+
835+ if ( !strServerBindIP6.isEmpty () )
836+ {
837+ if ( bDisableIPv6 )
838+ {
839+ qCritical () << " IPv6 is disabled; --serverbindip6 not allowed." ;
840+ exit ( 1 );
841+ }
842+
843+ QHostAddress InetAddr ( strServerBindIP6 );
844+ if ( InetAddr.protocol () != QAbstractSocket::IPv6Protocol )
845+ {
846+ qCritical () << " Server Bind IPv6 is invalid. Only plain IPv6 addresses are supported." ;
847+ exit ( 1 );
819848 }
820849 }
821850#ifndef NO_JSON_RPC
@@ -832,8 +861,8 @@ int main ( int argc, char** argv )
832861 // we do it here as an upfront check. The downstream network calls will error
833862 // out on malformed addresses not caught here.
834863 {
835- QHostAddress InetAddr;
836- if ( ! InetAddr.setAddress ( strJsonRpcBindIP ) )
864+ QHostAddress InetAddr ( strJsonRpcBindIP ) ;
865+ if ( InetAddr.protocol () != QAbstractSocket::IPv4Protocol )
837866 {
838867 qCritical () << qUtf8Printable ( QString ( " The JSON-RPC address specified is not valid, exiting. " ) );
839868 exit ( 1 );
@@ -1006,7 +1035,8 @@ int main ( int argc, char** argv )
10061035 // actual server object
10071036 CServer Server ( iNumServerChannels,
10081037 strLoggingFileName,
1009- strServerBindIP,
1038+ strServerBindIP4,
1039+ strServerBindIP6,
10101040 iPortNumber,
10111041 iQosNumber,
10121042 strDirectoryAddress,
@@ -1147,8 +1177,8 @@ QString UsageArguments ( char** argv )
11471177 " --norecord set server not to record by default when recording is configured\n "
11481178 " --noraw disable raw audio\n "
11491179 " -s, --server start Server\n "
1150- " --serverbindip IPv4 address the Server will bind to (rather than all)\n "
1151- " (only works if IPv6 is unavailable or disabled with --noipv6 )\n "
1180+ " --serverbindip4 IPv4 address the Server will bind to (rather than all)\n "
1181+ " --serverbindip6 IPv6 address the Server will bind to (rather than all )\n "
11521182 " -T, --multithreading use multithreading to make better use of\n "
11531183 " multi-core CPUs and support more Clients\n "
11541184 " -u, --numchannels maximum number of channels\n "
0 commit comments