示例#1
0
static void debug_dump_getaddrinfo_args (const char *name, const char *serv,
                                         const struct addrinfo *hint)
{
    const char *sep;
    fprintf(stderr,
            "getaddrinfo(hostname %s, service %s,\n"
            "            hints { ",
            name ? name : "(null)", serv ? serv : "(null)");
    if (hint) {
        char buf[30];
        sep = "";
#define Z(FLAG) if (hint->ai_flags & AI_##FLAG) fprintf(stderr, "%s%s", sep, #FLAG), sep = "|"
        Z(CANONNAME);
        Z(PASSIVE);
#ifdef AI_NUMERICHOST
        Z(NUMERICHOST);
#endif
        if (sep[0] == 0)
            fprintf(stderr, "no-flags");
        if (hint->ai_family)
            fprintf(stderr, " %s", familyname(hint->ai_family, buf,
                                              sizeof(buf)));
        if (hint->ai_socktype)
            fprintf(stderr, " SOCK_%s", socktypename(hint->ai_socktype, buf,
                                                     sizeof(buf)));
        if (hint->ai_protocol)
            fprintf(stderr, " IPPROTO_%s", protoname(hint->ai_protocol, buf,
                                                     sizeof(buf)));
    } else
        fprintf(stderr, "(null)");
    fprintf(stderr, " }):\n");
}
示例#2
0
void nuiFontRequest::AddGenericNameForFont(const nglString& rGenericName, const nglString& rFamilyName)
{
  nglString genericname(rGenericName);
  genericname.ToLower();
  nglString familyname(rFamilyName);
  familyname.ToLower();

  nuiFontRequest::gFontsForGenericNames.insert(std::pair<nglString, nglString>(genericname, familyname));
  nuiFontRequest::gGenericNamesForFonts[familyname] = genericname;
}
示例#3
0
static void debug_dump_addrinfos (const struct addrinfo *ai)
{
    int count = 0;
    char buf[10];
    fprintf(stderr, "addrinfos returned:\n");
    while (ai) {
        fprintf(stderr, "%p...", ai);
        fprintf(stderr, " socktype=%s", socktypename(ai->ai_socktype, buf,
                                                     sizeof(buf)));
        fprintf(stderr, " ai_family=%s", familyname(ai->ai_family, buf,
                                                    sizeof(buf)));
        if (ai->ai_family != ai->ai_addr->sa_family)
            fprintf(stderr, " sa_family=%s",
                    familyname(ai->ai_addr->sa_family, buf, sizeof(buf)));
        fprintf(stderr, "\n");
        ai = ai->ai_next;
        count++;
    }
    fprintf(stderr, "end addrinfos returned (%d)\n");
}
示例#4
0
int main (int argc, char *argv[])
{
    struct addrinfo *ap, *ap2;
    int err, numerichost = 0, numericserv = 0;
    char *hname, *port = 0, *sep;
    struct addrinfo hints;

    whoami = strrchr(argv[0], '/');
    if (whoami == 0)
        whoami = argv[0];
    else
        whoami = whoami+1;

    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = 0;
    hints.ai_socktype = 0;

    hname = 0;
    hints.ai_family = 0;

    if (argc == 1)
        usage ();

    while (++argv, --argc > 0) {
        char *arg;
        arg = *argv;

        if (*arg != '-')
            hname = arg;
        else if (arg[1] == 0 || arg[2] != 0)
            usage ();
        else
            switch (arg[1]) {
            case 'u':
                hints.ai_protocol = IPPROTO_UDP;
                break;
            case 't':
                hints.ai_protocol = IPPROTO_TCP;
                break;
            case 'R':
                hints.ai_protocol = IPPROTO_RAW;
                break;
            case 'I':
                hints.ai_protocol = IPPROTO_ICMP;
                break;
            case 'd':
                hints.ai_socktype = SOCK_DGRAM;
                break;
            case 's':
                hints.ai_socktype = SOCK_STREAM;
                break;
            case 'r':
                hints.ai_socktype = SOCK_RAW;
                break;
            case 'p':
                if (argv[1] == 0 || argv[1][0] == 0 || argv[1][0] == '-')
                    usage ();
                port = argv[1];
                argc--, argv++;
                break;
            case '4':
                hints.ai_family = AF_INET;
                break;
#ifdef AF_INET6
            case '6':
                hints.ai_family = AF_INET6;
                break;
#endif
            case 'N':
                numerichost = 1;
                break;
            case 'n':
                numericserv = 1;
                break;
            case 'P':
                hints.ai_flags |= AI_PASSIVE;
                break;
            default:
                usage ();
            }
    }

    if (hname && !numerichost)
        hints.ai_flags |= AI_CANONNAME;
    if (numerichost) {
#ifdef AI_NUMERICHOST
        hints.ai_flags |= AI_NUMERICHOST;
#else
        fprintf(stderr, "AI_NUMERICHOST not defined on this platform\n");
        exit(1);
#endif
    }
    if (numericserv) {
#ifdef AI_NUMERICSERV
        hints.ai_flags |= AI_NUMERICSERV;
#else
        fprintf(stderr, "AI_NUMERICSERV not defined on this platform\n");
        exit(1);
#endif
    }

    printf("getaddrinfo(hostname %s, service %s,\n"
           "            hints { ",
           hname ? hname : "(null)", port ? port : "(null)");
    sep = "";
#define Z(FLAG) if (hints.ai_flags & AI_##FLAG) printf("%s%s", sep, #FLAG), sep = "|"
    Z(CANONNAME);
    Z(PASSIVE);
#ifdef AI_NUMERICHOST
    Z(NUMERICHOST);
#endif
#ifdef AI_NUMERICSERV
    Z(NUMERICSERV);
#endif
    if (sep[0] == 0)
        printf ("no-flags");
    if (hints.ai_family)
        printf(" %s", familyname(hints.ai_family));
    if (hints.ai_socktype)
        printf(" SOCK_%s", socktypename(hints.ai_socktype));
    if (hints.ai_protocol)
        printf(" IPPROTO_%s", protoname(hints.ai_protocol));
    printf(" }):\n");

    err = getaddrinfo(hname, port, &hints, &ap);
    if (err) {
        printf("\terror => %s\n", eaistr(err));
        return 1;
    }

    for (ap2 = ap; ap2; ap2 = ap2->ai_next) {
        char hbuf[NI_MAXHOST], pbuf[NI_MAXSERV];
        /* If we don't do this, even AIX's own getnameinfo will reject
           the sockaddr structures.  The sa_len field doesn't get set
           either, on AIX, but getnameinfo won't complain.  */
        if (ap2->ai_addr->sa_family == 0) {
            printf("BAD: sa_family zero! fixing...\n");
            ap2->ai_addr->sa_family = ap2->ai_family;
        } else if (ap2->ai_addr->sa_family != ap2->ai_family) {
            printf("BAD: sa_family != ai_family! fixing...\n");
            ap2->ai_addr->sa_family = ap2->ai_family;
        }
        if (getnameinfo(ap2->ai_addr, ap2->ai_addrlen, hbuf, sizeof(hbuf),
                        pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV)) {
            strlcpy(hbuf, "...", sizeof(hbuf));
            strlcpy(pbuf, "...", sizeof(pbuf));
        }
        printf("%p:\n"
               "\tfamily = %s\tproto = %-4s\tsocktype = %s\n",
               (void *) ap2, familyname(ap2->ai_family),
               protoname (ap2->ai_protocol),
               socktypename (ap2->ai_socktype));
        if (ap2->ai_canonname) {
            if (ap2->ai_canonname[0])
                printf("\tcanonname = %s\n", ap2->ai_canonname);
            else
                printf("BAD: ai_canonname is set but empty!\n");
        } else if (ap2 == ap && (hints.ai_flags & AI_CANONNAME)) {
            printf("BAD: first ai_canonname is null!\n");
        }
        printf("\taddr = %-28s\tport = %s\n", hbuf, pbuf);

        err = getnameinfo(ap2->ai_addr, ap2->ai_addrlen, hbuf, sizeof (hbuf),
                          pbuf, sizeof(pbuf), NI_NAMEREQD);
        if (err)
            printf("\tgetnameinfo(NI_NAMEREQD): %s\n", eaistr(err));
        else
            printf("\tgetnameinfo => %s, %s\n", hbuf, pbuf);
    }
    freeaddrinfo(ap);
    return 0;
}