{
    "content": [
        {
            "type": "text",
            "text": "# Net::hostent (perldoc)\n\n## NAME\n\nNet::hostent - by-name interface to Perl's built-in gethost*() functions\n\n## SYNOPSIS\n\nuse Net::hostent;\n\n## DESCRIPTION\n\nThis module's default exports override the core gethostbyname() and gethostbyaddr() functions,\nreplacing them with versions that return \"Net::hostent\" objects. This object has methods that\nreturn the similarly named structure field name from the C's hostent structure from netdb.h;\nnamely name, aliases, addrtype, length, and addrlist. The aliases and addrlist methods return\narray reference, the rest scalars. The addr method is equivalent to the zeroth element in the\naddrlist array reference.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **EXAMPLES**\n- **NOTE**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Net::hostent",
        "section": "",
        "mode": "perldoc",
        "summary": "Net::hostent - by-name interface to Perl's built-in gethost*() functions",
        "synopsis": "use Net::hostent;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "use Net::hostent;",
            "use Socket;",
            "@ARGV = ('netscape.com') unless @ARGV;",
            "for $host ( @ARGV ) {",
            "unless ($h = gethost($host)) {",
            "warn \"$0: no such host: $host\\n\";",
            "next;",
            "printf \"\\n%s is %s%s\\n\",",
            "$host,",
            "lc($h->name) eq lc($host) ? \"\" : \"*really* \",",
            "$h->name;",
            "print \"\\taliases are \", join(\", \", @{$h->aliases}), \"\\n\"",
            "if @{$h->aliases};",
            "if ( @{$h->addrlist} > 1 ) {",
            "my $i;",
            "for $addr ( @{$h->addrlist} ) {",
            "printf \"\\taddr #%d is [%s]\\n\", $i++, inetntoa($addr);",
            "} else {",
            "printf \"\\taddress is [%s]\\n\", inetntoa($h->addr);",
            "if ($h = gethostbyaddr($h->addr)) {",
            "if (lc($h->name) ne lc($host)) {",
            "printf \"\\tThat addr reverses to host %s!\\n\", $h->name;",
            "$host = $h->name;",
            "redo;"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "NOTE",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Net::hostent - by-name interface to Perl's built-in gethost*() functions\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Net::hostent;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module's default exports override the core gethostbyname() and gethostbyaddr() functions,\nreplacing them with versions that return \"Net::hostent\" objects. This object has methods that\nreturn the similarly named structure field name from the C's hostent structure from netdb.h;\nnamely name, aliases, addrtype, length, and addrlist. The aliases and addrlist methods return\narray reference, the rest scalars. The addr method is equivalent to the zeroth element in the\naddrlist array reference.\n\nYou may also import all the structure fields directly into your namespace as regular variables\nusing the :FIELDS import tag. (Note that this still overrides your core functions.) Access these\nfields as variables named with a preceding \"h\". Thus, \"$hostobj->name()\" corresponds to\n$hname if you import the fields. Array references are available as regular array variables, so\nfor example \"@{ $hostobj->aliases() }\" would be simply @haliases.\n\nThe gethost() function is a simple front-end that forwards a numeric argument to gethostbyaddr()\nby way of Socket::inetaton, and the rest to gethostbyname().\n\nTo access this functionality without the core overrides, pass the \"use\" an empty import list,\nand then access function functions with their full qualified names. On the other hand, the\nbuilt-ins are still available via the \"CORE::\" pseudo-package.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "use Net::hostent;\nuse Socket;\n\n@ARGV = ('netscape.com') unless @ARGV;\n\nfor $host ( @ARGV ) {\n\nunless ($h = gethost($host)) {\nwarn \"$0: no such host: $host\\n\";\nnext;\n}\n\nprintf \"\\n%s is %s%s\\n\",\n$host,\nlc($h->name) eq lc($host) ? \"\" : \"*really* \",\n$h->name;\n\nprint \"\\taliases are \", join(\", \", @{$h->aliases}), \"\\n\"\nif @{$h->aliases};\n\nif ( @{$h->addrlist} > 1 ) {\nmy $i;\nfor $addr ( @{$h->addrlist} ) {\nprintf \"\\taddr #%d is [%s]\\n\", $i++, inetntoa($addr);\n}\n} else {\nprintf \"\\taddress is [%s]\\n\", inetntoa($h->addr);\n}\n\nif ($h = gethostbyaddr($h->addr)) {\nif (lc($h->name) ne lc($host)) {\nprintf \"\\tThat addr reverses to host %s!\\n\", $h->name;\n$host = $h->name;\nredo;\n}\n}\n}\n",
                "subsections": []
            },
            "NOTE": {
                "content": "While this class is currently implemented using the Class::Struct module to build a struct-like\nclass, you shouldn't rely upon this.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Tom Christiansen\n",
                "subsections": []
            }
        }
    }
}