0

I have a network address eg - 192.168.74.0/24. Trying to get the network address translation using getaddrinfo, doesnt seem to work. name here is 192.168.74.0/24. return value from getaddrindo is -2. Works well for ipv4 address without prefix.

static const struct addrinfo hint = {
            .ai_family = AF_UNSPEC,
            .ai_flags = AI_NUMERICHOST
    };
    struct addrinfo *ai;
    int ret;

    ret = getaddrinfo(name, NULL, &hint, &ai);
    if (ret) {
            printf("cannot parse '%s'", name);
            return false;
    }
user1060517
  • 355
  • 1
  • 5
  • 17
  • 7
    192.168.74.0/24 isn't an address: it specifies a network, or a range of addresses. What do you expect `getaddrinfo` to return? – Thanatos Oct 21 '13 at 20:05

1 Answers1

2

On my version of the headers at least, -2 is EAI_NONAME, "name or service unknown". It's not clear from your code what is in the variable name? The string "192.168.74.0/24"?

Anyway, from the documentation of getaddrinfo:

Given node and service, which identify an Internet host and a service [...]

Your input does not identify an internet host, but an entire network. What are you trying to accomplish?

carlpett
  • 12,203
  • 5
  • 48
  • 82