{"id":21962181,"url":"https://github.com/gdelugre/literal_ipaddr","last_synced_at":"2025-09-10T07:46:52.087Z","repository":{"id":73785534,"uuid":"189268533","full_name":"gdelugre/literal_ipaddr","owner":"gdelugre","description":"C++17 constexpr implementation of inet_addr / inet_aton / inet_pton","archived":false,"fork":false,"pushed_at":"2019-05-29T19:32:55.000Z","size":8,"stargazers_count":27,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T21:11:24.455Z","etag":null,"topics":["constexpr","cxx17","ipaddress"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gdelugre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-29T17:18:53.000Z","updated_at":"2025-03-10T22:13:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ac908c8-b966-47cc-a38e-7ba78ab27c01","html_url":"https://github.com/gdelugre/literal_ipaddr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gdelugre/literal_ipaddr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdelugre%2Fliteral_ipaddr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdelugre%2Fliteral_ipaddr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdelugre%2Fliteral_ipaddr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdelugre%2Fliteral_ipaddr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gdelugre","download_url":"https://codeload.github.com/gdelugre/literal_ipaddr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gdelugre%2Fliteral_ipaddr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274427591,"owners_count":25283225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["constexpr","cxx17","ipaddress"],"created_at":"2024-11-29T10:34:28.076Z","updated_at":"2025-09-10T07:46:52.064Z","avatar_url":"https://github.com/gdelugre.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parsing IP addresses at compile-time in C++\n\nThis repository contains a C++17 constexpr implementation of the IP address parsing functions ``inet_addr``, ``inet_aton`` and ``inet_pton``. It supports both v4 and v6 address families.\n\nWhen passed a literal IP address string, the compiler will parse the string and generate automatically the ``in_addr`` or ``in6_addr`` structure.\n\nThe address format is compatible with standard representations:\n- ``inet_addr`` and ``inet_aton`` accept IPv4 addresses in format ``a.b.c.d``, ``a.b.c``, ``a.b``, or ``a``, with address components expressed in decimal, octal or hexadecimal.\n\n```c++\n// Alternative syntaxes producing the same result:\n//   IPAddr::inet_addr(\"127.0.1\")\n//   IPAddr::inet_addr(\"127.1\")\n//   IPAddr::inet_addr(\"0x7f.1\")\n//   IPAddr::inet_addr(\"2130706433\")\n//\nconstexpr in_addr_t addr = IPAddr::inet_addr(\"127.0.0.1\");\n```\n\n- ``inet_pton`` supports IPv4 addresses in canonical form (4 decimal components with no leading zeros) and IPv6 addresses represented according to RFC 2373, including with embedded IPv4 addresses.\n\n```c++\nconstexpr auto in_addr1 = IPAddr::inet_pton\u003cAF_INET\u003e(\"127.0.0.1\");\nconstexpr auto in_addr2 = IPAddr::inet_pton\u003cAF_INET6\u003e(\"::1\");\nconstexpr auto in_addr3 = IPAddr::inet_pton\u003cAF_INET6\u003e(\"fe80::127.0.0.1\"); // IPv4-in-IPv6 syntax\n```\n\nThe ``ipaddr.h`` header also defines ``_ipaddr`` and ``_ipport`` literals. The ``_ipaddr`` suffix will automatically detect the format of the IP address and return the according ``in[6]_addr`` structure, or raise a static assertion if the format is incorrect.\n\n## Example\n\n```c++\nint s = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);\n\nconst struct sockaddr_in dst {\n    .sin_family = AF_INET,\n    .sin_port   = 1234_ipport,\n    .sin_addr   = \"127.0.0.1\"_ipaddr\n};\n\nconnect(s, (struct sockaddr *)\u0026dst, sizeof(dst));\n```\n\nThe above example, with clang 8.0.0 on Linux x86_64, generates:\n\n```objdump\n        mov    $0x2,%edi\n        mov    $0x1,%esi\n        xor    %edx,%edx\n        callq  \u003csocket@plt\u003e\n\n        movups 0xe7e(%rip),%xmm0            # sockaddr in rodata section\n        mov    %rsp,%rsi\n        movaps %xmm0,(%rsi)\n\n        mov    %eax,%edi\n        mov    $0x10,%edx\n        callq  \u003cconnect@plt\u003e\n```\n\nWith gcc 8.3.0:\n\n```objdump\n        xor    %edx,%edx\n        mov    $0x1,%esi\n        mov    $0x2,%edi\n        callq  \u003csocket@plt\u003e\n\n        mov    $0x10,%edx\n        lea    0x8(%rsp),%rsi\n        movabs $0x100007fd2040002,%rcx      # sockaddr as an immediate operand\n\n        mov    %eax,%edi\n        mov    %rcx,0x8(%rsp)\n        movq   $0x0,0x10(%rsp)\n        callq  \u003cconnect@plt\u003e\n```\n\n## License\n\nDistributed under the MIT license, see LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdelugre%2Fliteral_ipaddr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgdelugre%2Fliteral_ipaddr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdelugre%2Fliteral_ipaddr/lists"}