Problem parsing IPv4/IPv6 addresses with std.socket.parseAddress

Dsciple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 27 02:04:53 PDT 2016


Hi there!

I wrote a small utility library to read configuration parameters 
from both command-line arguments (using std.getopt) and SDLang 
files (using sdlang-d package).
The main library defines a struct ConfigParams whose fields are 
themselves structs defined in sub-libraries (set as 
dependencies), each responsible for reading one kind of parameter 
(BindAddress, BindPort, etc) from both command-line and SDL 
files. Each sub-library has its own unit tests which run 
successfully in isolation.
Then, when putting everything together in the main struct 
CofigParams I get the compile-time error:

/usr/include/dlang/dmd/std/socket.d(1195,9): Error: static 
variable getaddrinfoPointer cannot be read at compile time
called from here: parseAddress(addressString, null)

while using std.socket.parseAddress to validate IPv4/IPv6 bind 
addresses.
I'm using dmd v2.071.2 and dub v1.0.0.
The relevant piece of code where this happens is the following:

struct BindAddress {

   import std.socket: parseAddress, SocketException;

   // Private members
   private string addressString = "0.0.0.0";

   // Construct from address string
   this(string addressString) {
     try {
       auto address = parseAddress(addressString);
     } catch(SocketException ex) {
       throw new BindAddressException("Invalid bind address " ~ 
addressString);
     }
     this.addressString = addressString;
   }

}

As said, this works fine when tested in isolation, and the 
compiler only complains when using BindAddress as a member of 
ConfigParams.
Any idea what the problem may be?
Or is there maybe a ready to use, high-level library for parsing 
parameters from command-line arguments and config files of some 
kind?




More information about the Digitalmars-d-learn mailing list