CINXE.COM
Socket - networking constants and support functions - metacpan.org
<!DOCTYPE html> <html lang="en-US"> <head> <title>Socket - networking constants and support functions - metacpan.org</title> <link rel="preload" as="fetch" href="/account/login_status" crossorigin="anonymous" /> <link href="/assets/style-XFEQ536G.css" rel="stylesheet" type="text/css"> <script src="/assets/main-WXBSEDQJ.js" type="module"></script> <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Socket - MetaCPAN" href="/dist/Socket/releases.rss" /> <link rel="canonical" href="https://metacpan.org/pod/Socket" /> <meta name="description" content="networking constants and support functions" /> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5"> <link rel="shortcut icon" href="/static/icons/favicon.ico"> <link rel="apple-touch-icon" sizes="152x152" href="/static/icons/apple-touch-icon.png"> <link rel="search" href="/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN"> <script async src="https://perl-ads.perlhacks.com/perl-ads.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-E82Q2V8LVD"></script> <meta property="og:site_name" content="MetaCPAN" /> <meta name="twitter:site" content="@metacpan" /> <meta property="og:type" content="article" /> <meta name="twitter:card" content="summary" /> <meta property="og:url" content="https://metacpan.org/pod/Socket" /> <meta property="og:title" content="Socket" /> <meta property="og:description" content="networking constants and support functions" /> <meta property="og:image" content="https://metacpan.org/static/images/dots.png" /> </head> <body> <nav class="navbar navbar-default" role="navigation"> <div class="header-logo-large hidden-xs"> <a href="/" tabindex="0"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#logo" /> </svg> </a> </div> <div class="header-logo-icon visible-xs"> <a href="/"> <svg class="logo" aria-label="MetaCPAN"> <use class="logo" href="/static/images/metacpan-logo.svg#dots" /> </svg> </a> </div> <ul class="nav navbar-nav menu-items hidden-xs hidden-sm"> <li><a href="/about">About</a></li> <li><a href="/about/sponsors">Sponsor</a></li> <li><a href="https://grep.metacpan.org/">grep::cpan</a></li> <li><a href="/recent">Recent</a></li> <li><a href="/about/faq">FAQ</a></li> <li><a href="/tools">Tools</a></li> <li><a href="https://fastapi.metacpan.org/">API</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <button type="button" class="searchbar-btn visible-xs visible-sm"> <i class="fa fa-search button-fa-icon"></i> </button> <form action="/search" class="searchbar-form visible-md visible-lg search-form form-horizontal"> <input type="hidden" name="size" id="metacpan_search-size" value="20"> <div class="form-group"> <div class="search-group"> <i class="fa fa-search"></i> <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value=""> </div> </div> </form> <li class="icon-slidepanel visible-xs visible-sm"> <button data-toggle="slidepanel" data-target=".slidepanel"> <span class="button-fa-icon"> <i class="fa fa-bars slidepanel-open"></i> <i class="fa fa-times slidepanel-close"></i> </span> </button> </li> <li class="dropdown login-dropdown show-logged-in"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li><a href="/account/identities">Identities</a></li> <li><a href="/account/profile">Profile</a></li> <li><a href="/account/favorite/list">Favorites</a></li> <li> <a href="#" type="button" class="logout-button"> Logout </a> </li> </ul> </li> <li class="dropdown login-dropdown show-logged-out"> <button type="button" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-user button-fa-icon avatar-placeholder" aria-hidden="true"></i> <i class="fas fa-chevron-down"></i> </button> <ul class="dropdown-menu"> <li> <a href="/login/github"> <i class="fab fa-github fa-fw"></i> GitHub </a> </li> <li> <a href="/login/twitter"> <i class="fab fa-twitter fa-fw"></i> Twitter </a> </li> <li> <a href="/login/google"> <i class="fab fa-google fa-fw"></i> Google </a> </li> </ul> </li> <li class="dropdown login-dropdown hide-logged-in hide-logged-out"> <button> <i class="fa fa-user button-fa-icon" aria-hidden="true"></i> </button> </li> </ul> </nav> <div class="page-content "> <div id="perl-ad-target" class="top-notify-banner perl-ad-target"> </div> <nav class="sidebar"> <div class="slidepanel"> <ul class="nav-list "> <li class="nav-header no-margin-top"> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Socket was released."> <span class="relatize">15 Apr 2024 20:15:41 UTC</span> </div> </li> <li> Distribution: <a href="/dist/Socket">Socket</a> </li> <li> Module version: 2.038 </li> <li> <a data-keyboard-shortcut="g s" href="/dist/Socket/source/Socket.pm">Source</a> (<a href="/dist/Socket/source/Socket.pm?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g b" href="/dist/Socket/source">Browse</a> (<a href="/dist/Socket/source?raw=1">raw</a>) </li> <li> <a data-keyboard-shortcut="g c" href="/dist/Socket/changes">Changes</a> </li> <li> <a class="nopopup" href="/dist/Socket/contribute">How to Contribute</a> </li> <li> <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Socket">Issues</a> (21) </li> <li> <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Socket+2.038" title="Matrix">Testers</a> <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/S/Socket.html?oncpan=1&distmat=1&version=2.038&grade=2" style="color: #090">1146</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/S/Socket.html?oncpan=1&distmat=1&version=2.038&grade=3" style="color: #900">20</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/S/Socket.html?oncpan=1&distmat=1&version=2.038&grade=4">0</a>)</span> </li> <li> <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/PEVANS/Socket-2.038">Kwalitee</a> </li> <li> <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Socket who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)"> Bus factor: 5 </div> </li> <li> License: perl_5 </li> <li> Perl: v5.6.1 </li> <li class="nav-header">Activity</li> <li> <div class="activity-graph"> <img src="/dist/Socket/activity.svg?res=month" /> <div class="comment">24 month</div> </div> </li> <li class="nav-header">Tools</li> <li> <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/P/PE/PEVANS/Socket-2.038.tar.gz"> Download (<span itemprop="fileSize">44.99KB</span>)</a> </li> <li> <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FPEVANS%2FSocket-2.038%2FSocket.pm"> MetaCPAN Explorer </a> </li> <li> <a href="/dist/Socket/permissions"> Permissions </a> </li> <li> <a href="/dist/Socket/releases.rss"> Subscribe to distribution </a> </li> <li> <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog"> Install Instructions </button> </li> <li> <form action="/search"> <input type="hidden" name="q" value="dist:Socket"> <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li> <form action="https://grep.metacpan.org/search"> <input type="hidden" name="qd" value="Socket"> <input type="hidden" name="source" value="metacpan"> <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form"> <input type="submit" style="display: none"> </form> </li> <li class="version-jump"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Jump to version</option> <option disabled value="/release/PEVANS/Socket-2.038/view/Socket.pm" >2.038 (PEVANS on 2024-04-15)</option> <option value="/release/PEVANS/Socket-2.037/view/Socket.pm" >2.037 (PEVANS on 2023-06-06)</option> <option value="/release/PEVANS/Socket-2.036/view/Socket.pm" >2.036 (PEVANS on 2022-08-19)</option> <option value="/release/RURBAN/Socket-2.029_05/view/Socket.pm" >2.029_05 DEV (RURBAN on 2019-06-15)</option> <option value="/release/RURBAN/Socket-2.027_05/view/Socket.pm" >2.027_05 DEV (RURBAN on 2019-04-14)</option> <option value="/release/RURBAN/Socket-2.027_04/view/Socket.pm" >2.027_04 DEV (RURBAN on 2018-09-05)</option> <option value="/release/RURBAN/Socket-2.024_03/view/Socket.pm" >2.024_03 DEV (RURBAN on 2016-10-04)</option> <option value="/release/RURBAN/Socket-2.024_02/view/Socket.pm" >2.024_02 DEV (RURBAN on 2016-08-26)</option> <option value="/release/RURBAN/Socket-2.024_01/view/Socket.pm" >2.024_01 DEV (RURBAN on 2016-08-26)</option> <option value="/release/RURBAN/Socket-2.021_02/view/Socket.pm" >2.021_02 DEV (RURBAN on 2016-06-06)</option> <option value="/release/RURBAN/Socket-2.021_01/view/Socket.pm" >2.021_01 DEV (RURBAN on 2016-04-16)</option> <option value="/release/TOMC/Socket-1.5/view/Socket.pm" >1.5 (TOMC on 1996-06-09)</option> <optgroup label="BackPAN">' <option value="/release/PEVANS/Socket-2.035/view/Socket.pm" >2.035 (PEVANS on 2022-07-01)</option> <option value="/release/PEVANS/Socket-2.034/view/Socket.pm" >2.034 (PEVANS on 2022-06-27)</option> <option value="/release/PEVANS/Socket-2.033/view/Socket.pm" >2.033 (PEVANS on 2022-04-29)</option> <option value="/release/PEVANS/Socket-2.032/view/Socket.pm" >2.032 (PEVANS on 2021-06-02)</option> <option value="/release/PEVANS/Socket-2.031/view/Socket.pm" >2.031 (PEVANS on 2021-01-05)</option> <option value="/release/PEVANS/Socket-2.030/view/Socket.pm" >2.030 (PEVANS on 2020-07-06)</option> <option value="/release/PEVANS/Socket-2.029/view/Socket.pm" >2.029 (PEVANS on 2019-02-21)</option> <option value="/release/PEVANS/Socket-2.029-TRIAL/view/Socket.pm" >2.029-TRIAL DEV (PEVANS on 2019-02-20)</option> <option value="/release/PEVANS/Socket-2.028-TRIAL/view/Socket.pm" >2.028-TRIAL DEV (PEVANS on 2019-02-20)</option> <option value="/release/PEVANS/Socket-2.027/view/Socket.pm" >2.027 (PEVANS on 2018-01-12)</option> <option value="/release/PEVANS/Socket-2.026/view/Socket.pm" >2.026 (PEVANS on 2018-01-11)</option> <option value="/release/PEVANS/Socket-2.025/view/Socket.pm" >2.025 (PEVANS on 2018-01-09)</option> <option value="/release/PEVANS/Socket-2.024/view/Socket.pm" >2.024 (PEVANS on 2016-08-11)</option> <option value="/release/PEVANS/Socket-2.023/view/Socket.pm" >2.023 (PEVANS on 2016-08-02)</option> <option value="/release/PEVANS/Socket-2.022/view/Socket.pm" >2.022 (PEVANS on 2016-08-01)</option> <option value="/release/PEVANS/Socket-2.021/view/Socket.pm" >2.021 (PEVANS on 2015-11-18)</option> <option value="/release/PEVANS/Socket-2.020/view/Socket.pm" >2.020 (PEVANS on 2015-06-24)</option> <option value="/release/PEVANS/Socket-2.019/view/Socket.pm" >2.019 (PEVANS on 2015-04-29)</option> <option value="/release/PEVANS/Socket-2.018_001/view/Socket.pm" >2.018_001 DEV (PEVANS on 2015-04-27)</option> <option value="/release/PEVANS/Socket-2.018/view/Socket.pm" >2.018 (PEVANS on 2015-02-12)</option> <option value="/release/PEVANS/Socket-2.017/view/Socket.pm" >2.017 (PEVANS on 2015-02-10)</option> <option value="/release/PEVANS/Socket-2.016/view/Socket.pm" >2.016 (PEVANS on 2014-10-08)</option> <option value="/release/PEVANS/Socket-2.015/view/Socket.pm" >2.015 (PEVANS on 2014-08-15)</option> <option value="/release/PEVANS/Socket-2.014/view/Socket.pm" >2.014 (PEVANS on 2014-05-31)</option> <option value="/release/PEVANS/Socket-2.013/view/Socket.pm" >2.013 (PEVANS on 2013-10-28)</option> <option value="/release/PEVANS/Socket-2.012/view/Socket.pm" >2.012 (PEVANS on 2013-09-03)</option> <option value="/release/PEVANS/Socket-2.011/view/Socket.pm" >2.011 (PEVANS on 2013-07-28)</option> <option value="/release/PEVANS/Socket-2.010/view/Socket.pm" >2.010 (PEVANS on 2013-06-24)</option> <option value="/release/PEVANS/Socket-2.009/view/Socket.pm" >2.009 (PEVANS on 2013-01-18)</option> <option value="/release/PEVANS/Socket-2.008/view/Socket.pm" >2.008 (PEVANS on 2012-12-27)</option> <option value="/release/PEVANS/Socket-2.007/view/Socket.pm" >2.007 (PEVANS on 2012-12-16)</option> <option value="/release/PEVANS/Socket-2.006/view/Socket.pm" >2.006 (PEVANS on 2012-08-19)</option> <option value="/release/PEVANS/Socket-2.005/view/Socket.pm" >2.005 (PEVANS on 2012-08-16)</option> <option value="/release/PEVANS/Socket-2.004/view/Socket.pm" >2.004 (PEVANS on 2012-08-15)</option> <option value="/release/PEVANS/Socket-2.003/view/Socket.pm" >2.003 (PEVANS on 2012-08-15)</option> <option value="/release/PEVANS/Socket-2.002/view/Socket.pm" >2.002 (PEVANS on 2012-06-06)</option> <option value="/release/PEVANS/Socket-2.001_003/view/Socket.pm" >2.001_003 DEV (PEVANS on 2012-05-31)</option> <option value="/release/PEVANS/Socket-2.001_002/view/Socket.pm" >2.001_002 DEV (PEVANS on 2012-05-22)</option> <option value="/release/PEVANS/Socket-2.001_001/view/Socket.pm" >2.001_001 DEV (PEVANS on 2012-05-18)</option> <option value="/release/PEVANS/Socket-2.001/view/Socket.pm" >2.001 (PEVANS on 2012-03-27)</option> <option value="/release/PEVANS/Socket-2.000/view/Socket.pm" >2.000 (PEVANS on 2012-03-10)</option> <option value="/release/PEVANS/Socket-1.99/view/Socket.pm" >1.99 (PEVANS on 2012-02-21)</option> <option value="/release/PEVANS/Socket-1.98_001/view/Socket.pm" >1.98_001 DEV (PEVANS on 2012-02-17)</option> <option value="/release/PEVANS/Socket-1.98/view/Socket.pm" >1.98 (PEVANS on 2012-02-16)</option> <option value="/release/PEVANS/Socket-1.97_002/view/Socket.pm" >1.97_002 DEV (PEVANS on 2012-02-12)</option> <option value="/release/PEVANS/Socket-1.97_001/view/Socket.pm" >1.97_001 DEV (PEVANS on 2012-02-07)</option> <option value="/release/PEVANS/Socket-1.97/view/Socket.pm" >1.97 (PEVANS on 2011-12-16)</option> <option value="/release/PEVANS/Socket-1.96/view/Socket.pm" >1.96 (PEVANS on 2011-12-11)</option> <option value="/release/PEVANS/Socket-1.95_004/view/Socket.pm" >1.95_004 DEV (PEVANS on 2011-12-07)</option> <option value="/release/PEVANS/Socket-1.95_003/view/Socket.pm" >1.95_003 DEV (PEVANS on 2011-12-06)</option> <option value="/release/PEVANS/Socket-1.95_002/view/Socket.pm" >1.95_002 DEV (PEVANS on 2011-12-05)</option> <option value="/release/PEVANS/Socket-1.95_001/view/Socket.pm" >1.95_001 DEV (PEVANS on 2011-12-02)</option> <option value="/release/PEVANS/Socket-1.95/view/Socket.pm" >1.95 (PEVANS on 2011-12-01)</option> <option value="/release/PEVANS/Socket-1.94_07/view/Socket.pm" >1.94_07 DEV (PEVANS on 2011-11-22)</option> <option value="/release/PEVANS/Socket-1.94_06/view/Socket.pm" >1.94_06 DEV (PEVANS on 2011-10-30)</option> <option value="/release/PEVANS/Socket-1.94_05/view/Socket.pm" >1.94_05 DEV (PEVANS on 2011-10-27)</option> <option value="/release/PEVANS/Socket-1.94_04/view/Socket.pm" >1.94_04 DEV (PEVANS on 2011-10-26)</option> <option value="/release/PEVANS/Socket-1.94_03/view/Socket.pm" >1.94_03 DEV (PEVANS on 2011-10-25)</option> <option value="/release/TOMC/Socket-1.3/view/Socket.pm" >1.3 (TOMC on 1995-11-09)</option> </optgroup> </select> </li> <li class="version-diff"> <select class="select-navigator form-control tool-bar-form"> <option disabled selected>Diff with version</option> <option disabled value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.038/Socket.pm" >2.038 (PEVANS on 2024-04-15)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.037/Socket.pm" >2.037 (PEVANS on 2023-06-06)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.036/Socket.pm" >2.036 (PEVANS on 2022-08-19)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.029_05/Socket.pm" >2.029_05 DEV (RURBAN on 2019-06-15)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.027_05/Socket.pm" >2.027_05 DEV (RURBAN on 2019-04-14)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.027_04/Socket.pm" >2.027_04 DEV (RURBAN on 2018-09-05)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.024_03/Socket.pm" >2.024_03 DEV (RURBAN on 2016-10-04)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.024_02/Socket.pm" >2.024_02 DEV (RURBAN on 2016-08-26)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.024_01/Socket.pm" >2.024_01 DEV (RURBAN on 2016-08-26)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.021_02/Socket.pm" >2.021_02 DEV (RURBAN on 2016-06-06)</option> <option value="/release/PEVANS/Socket-2.038/diff/RURBAN/Socket-2.021_01/Socket.pm" >2.021_01 DEV (RURBAN on 2016-04-16)</option> <option value="/release/PEVANS/Socket-2.038/diff/TOMC/Socket-1.5/Socket.pm" >1.5 (TOMC on 1996-06-09)</option> <optgroup label="BackPAN">' <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.035/Socket.pm" >2.035 (PEVANS on 2022-07-01)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.034/Socket.pm" >2.034 (PEVANS on 2022-06-27)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.033/Socket.pm" >2.033 (PEVANS on 2022-04-29)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.032/Socket.pm" >2.032 (PEVANS on 2021-06-02)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.031/Socket.pm" >2.031 (PEVANS on 2021-01-05)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.030/Socket.pm" >2.030 (PEVANS on 2020-07-06)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.029/Socket.pm" >2.029 (PEVANS on 2019-02-21)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.029-TRIAL/Socket.pm" >2.029-TRIAL DEV (PEVANS on 2019-02-20)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.028-TRIAL/Socket.pm" >2.028-TRIAL DEV (PEVANS on 2019-02-20)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.027/Socket.pm" >2.027 (PEVANS on 2018-01-12)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.026/Socket.pm" >2.026 (PEVANS on 2018-01-11)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.025/Socket.pm" >2.025 (PEVANS on 2018-01-09)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.024/Socket.pm" >2.024 (PEVANS on 2016-08-11)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.023/Socket.pm" >2.023 (PEVANS on 2016-08-02)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.022/Socket.pm" >2.022 (PEVANS on 2016-08-01)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.021/Socket.pm" >2.021 (PEVANS on 2015-11-18)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.020/Socket.pm" >2.020 (PEVANS on 2015-06-24)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.019/Socket.pm" >2.019 (PEVANS on 2015-04-29)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.018_001/Socket.pm" >2.018_001 DEV (PEVANS on 2015-04-27)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.018/Socket.pm" >2.018 (PEVANS on 2015-02-12)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.017/Socket.pm" >2.017 (PEVANS on 2015-02-10)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.016/Socket.pm" >2.016 (PEVANS on 2014-10-08)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.015/Socket.pm" >2.015 (PEVANS on 2014-08-15)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.014/Socket.pm" >2.014 (PEVANS on 2014-05-31)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.013/Socket.pm" >2.013 (PEVANS on 2013-10-28)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.012/Socket.pm" >2.012 (PEVANS on 2013-09-03)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.011/Socket.pm" >2.011 (PEVANS on 2013-07-28)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.010/Socket.pm" >2.010 (PEVANS on 2013-06-24)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.009/Socket.pm" >2.009 (PEVANS on 2013-01-18)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.008/Socket.pm" >2.008 (PEVANS on 2012-12-27)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.007/Socket.pm" >2.007 (PEVANS on 2012-12-16)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.006/Socket.pm" >2.006 (PEVANS on 2012-08-19)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.005/Socket.pm" >2.005 (PEVANS on 2012-08-16)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.004/Socket.pm" >2.004 (PEVANS on 2012-08-15)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.003/Socket.pm" >2.003 (PEVANS on 2012-08-15)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.002/Socket.pm" >2.002 (PEVANS on 2012-06-06)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.001_003/Socket.pm" >2.001_003 DEV (PEVANS on 2012-05-31)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.001_002/Socket.pm" >2.001_002 DEV (PEVANS on 2012-05-22)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.001_001/Socket.pm" >2.001_001 DEV (PEVANS on 2012-05-18)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.001/Socket.pm" >2.001 (PEVANS on 2012-03-27)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-2.000/Socket.pm" >2.000 (PEVANS on 2012-03-10)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.99/Socket.pm" >1.99 (PEVANS on 2012-02-21)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.98_001/Socket.pm" >1.98_001 DEV (PEVANS on 2012-02-17)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.98/Socket.pm" >1.98 (PEVANS on 2012-02-16)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.97_002/Socket.pm" >1.97_002 DEV (PEVANS on 2012-02-12)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.97_001/Socket.pm" >1.97_001 DEV (PEVANS on 2012-02-07)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.97/Socket.pm" >1.97 (PEVANS on 2011-12-16)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.96/Socket.pm" >1.96 (PEVANS on 2011-12-11)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.95_004/Socket.pm" >1.95_004 DEV (PEVANS on 2011-12-07)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.95_003/Socket.pm" >1.95_003 DEV (PEVANS on 2011-12-06)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.95_002/Socket.pm" >1.95_002 DEV (PEVANS on 2011-12-05)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.95_001/Socket.pm" >1.95_001 DEV (PEVANS on 2011-12-02)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.95/Socket.pm" >1.95 (PEVANS on 2011-12-01)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.94_07/Socket.pm" >1.94_07 DEV (PEVANS on 2011-11-22)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.94_06/Socket.pm" >1.94_06 DEV (PEVANS on 2011-10-30)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.94_05/Socket.pm" >1.94_05 DEV (PEVANS on 2011-10-27)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.94_04/Socket.pm" >1.94_04 DEV (PEVANS on 2011-10-26)</option> <option value="/release/PEVANS/Socket-2.038/diff/PEVANS/Socket-1.94_03/Socket.pm" >1.94_03 DEV (PEVANS on 2011-10-25)</option> <option value="/release/PEVANS/Socket-2.038/diff/TOMC/Socket-1.3/Socket.pm" >1.3 (TOMC on 1995-11-09)</option> </optgroup> </select> </li> <li> <ul class="dependencies"> <li class="nav-header">Dependencies</li> <li><i class="ttip" title="dynamic_config enabled">unknown</i></li> <li> <hr> </li> <li> <a href="/module/Socket/requires">Reverse dependencies</a> </li> <li> <a href="http://deps.cpantesters.org/?module=Socket">CPAN Testers List</a> </li> <li> <a href="https://cpandeps.grinnz.com/?dist=Socket">Dependency graph</a> </li> </ul> </li> <li class="nav-header">Permalinks</li> <li> <a href="/release/PEVANS/Socket-2.038/view/Socket.pm">This version</a> </li> <li> <a href="/pod/Socket">Latest version</a> </li> <li> <div class="plussers"> <div class="nav-header">++ed by:</div> <div> <a class="display-all" href="/author/LUCAS"><img src="https://www.gravatar.com/avatar/289426c9d3c2ee28c2d157d4401e14db?d=identicon&s=20" title="LUCAS" alt="LUCAS"></a> <a class="display-all" href="/author/MARIOROY"><img src="https://www.gravatar.com/avatar/112c64e088284a78b9afbcb83c125613?d=identicon&s=20" title="MARIOROY" alt="MARIOROY"></a> <a class="display-all" href="/author/PINGAN"><img src="https://www.gravatar.com/avatar/a02222e5e0e4fd24d52fc29a08ac6bcb?d=identicon&s=20" title="PINGAN" alt="PINGAN"></a> <a class="display-all" href="/author/RWP"><img src="https://www.gravatar.com/avatar/7110eb2389e69a066d9d7cad7a1cc2bf?d=identicon&s=20" title="RWP" alt="RWP"></a> <a class="display-all" href="/author/YOUPONG"><img src="https://www.gravatar.com/avatar/45be30d66c5f5cb4d9ba25f35af52596?d=identicon&s=20" title="YOUPONG" alt="YOUPONG"></a> </div> <!-- Display counts of plussers--> <div> <a href="/dist/Socket/plussers">7 PAUSE users</a> </div> <div> 2 non-PAUSE users </div> </div> </li> <li> </li> </ul> </div> </nav> <div class="content-navigation"> <div class="breadcrumbs"> <span> <a data-keyboard-shortcut="g a" rel="author" href="/author/PEVANS" class="author-name">Paul Evans</a> </span> <span> / </span> <div class="release dist-release status-latest maturity-released"> <span class="dropdown"><b class="caret"></b></span> <select class="select-navigator "> <option selected value="/release/PEVANS/Socket-2.038/view/Socket.pm" >2.038 (PEVANS on 2024-04-15)</option> <option value="/release/PEVANS/Socket-2.037/view/Socket.pm" >2.037 (PEVANS on 2023-06-06)</option> <option value="/release/PEVANS/Socket-2.036/view/Socket.pm" >2.036 (PEVANS on 2022-08-19)</option> <option value="/release/RURBAN/Socket-2.029_05/view/Socket.pm" >2.029_05 DEV (RURBAN on 2019-06-15)</option> <option value="/release/RURBAN/Socket-2.027_05/view/Socket.pm" >2.027_05 DEV (RURBAN on 2019-04-14)</option> <option value="/release/RURBAN/Socket-2.027_04/view/Socket.pm" >2.027_04 DEV (RURBAN on 2018-09-05)</option> <option value="/release/RURBAN/Socket-2.024_03/view/Socket.pm" >2.024_03 DEV (RURBAN on 2016-10-04)</option> <option value="/release/RURBAN/Socket-2.024_02/view/Socket.pm" >2.024_02 DEV (RURBAN on 2016-08-26)</option> <option value="/release/RURBAN/Socket-2.024_01/view/Socket.pm" >2.024_01 DEV (RURBAN on 2016-08-26)</option> <option value="/release/RURBAN/Socket-2.021_02/view/Socket.pm" >2.021_02 DEV (RURBAN on 2016-06-06)</option> <option value="/release/RURBAN/Socket-2.021_01/view/Socket.pm" >2.021_01 DEV (RURBAN on 2016-04-16)</option> <option value="/release/TOMC/Socket-1.5/view/Socket.pm" >1.5 (TOMC on 1996-06-09)</option> <optgroup label="BackPAN">' <option value="/release/PEVANS/Socket-2.035/view/Socket.pm" >2.035 (PEVANS on 2022-07-01)</option> <option value="/release/PEVANS/Socket-2.034/view/Socket.pm" >2.034 (PEVANS on 2022-06-27)</option> <option value="/release/PEVANS/Socket-2.033/view/Socket.pm" >2.033 (PEVANS on 2022-04-29)</option> <option value="/release/PEVANS/Socket-2.032/view/Socket.pm" >2.032 (PEVANS on 2021-06-02)</option> <option value="/release/PEVANS/Socket-2.031/view/Socket.pm" >2.031 (PEVANS on 2021-01-05)</option> <option value="/release/PEVANS/Socket-2.030/view/Socket.pm" >2.030 (PEVANS on 2020-07-06)</option> <option value="/release/PEVANS/Socket-2.029/view/Socket.pm" >2.029 (PEVANS on 2019-02-21)</option> <option value="/release/PEVANS/Socket-2.029-TRIAL/view/Socket.pm" >2.029-TRIAL DEV (PEVANS on 2019-02-20)</option> <option value="/release/PEVANS/Socket-2.028-TRIAL/view/Socket.pm" >2.028-TRIAL DEV (PEVANS on 2019-02-20)</option> <option value="/release/PEVANS/Socket-2.027/view/Socket.pm" >2.027 (PEVANS on 2018-01-12)</option> <option value="/release/PEVANS/Socket-2.026/view/Socket.pm" >2.026 (PEVANS on 2018-01-11)</option> <option value="/release/PEVANS/Socket-2.025/view/Socket.pm" >2.025 (PEVANS on 2018-01-09)</option> <option value="/release/PEVANS/Socket-2.024/view/Socket.pm" >2.024 (PEVANS on 2016-08-11)</option> <option value="/release/PEVANS/Socket-2.023/view/Socket.pm" >2.023 (PEVANS on 2016-08-02)</option> <option value="/release/PEVANS/Socket-2.022/view/Socket.pm" >2.022 (PEVANS on 2016-08-01)</option> <option value="/release/PEVANS/Socket-2.021/view/Socket.pm" >2.021 (PEVANS on 2015-11-18)</option> <option value="/release/PEVANS/Socket-2.020/view/Socket.pm" >2.020 (PEVANS on 2015-06-24)</option> <option value="/release/PEVANS/Socket-2.019/view/Socket.pm" >2.019 (PEVANS on 2015-04-29)</option> <option value="/release/PEVANS/Socket-2.018_001/view/Socket.pm" >2.018_001 DEV (PEVANS on 2015-04-27)</option> <option value="/release/PEVANS/Socket-2.018/view/Socket.pm" >2.018 (PEVANS on 2015-02-12)</option> <option value="/release/PEVANS/Socket-2.017/view/Socket.pm" >2.017 (PEVANS on 2015-02-10)</option> <option value="/release/PEVANS/Socket-2.016/view/Socket.pm" >2.016 (PEVANS on 2014-10-08)</option> <option value="/release/PEVANS/Socket-2.015/view/Socket.pm" >2.015 (PEVANS on 2014-08-15)</option> <option value="/release/PEVANS/Socket-2.014/view/Socket.pm" >2.014 (PEVANS on 2014-05-31)</option> <option value="/release/PEVANS/Socket-2.013/view/Socket.pm" >2.013 (PEVANS on 2013-10-28)</option> <option value="/release/PEVANS/Socket-2.012/view/Socket.pm" >2.012 (PEVANS on 2013-09-03)</option> <option value="/release/PEVANS/Socket-2.011/view/Socket.pm" >2.011 (PEVANS on 2013-07-28)</option> <option value="/release/PEVANS/Socket-2.010/view/Socket.pm" >2.010 (PEVANS on 2013-06-24)</option> <option value="/release/PEVANS/Socket-2.009/view/Socket.pm" >2.009 (PEVANS on 2013-01-18)</option> <option value="/release/PEVANS/Socket-2.008/view/Socket.pm" >2.008 (PEVANS on 2012-12-27)</option> <option value="/release/PEVANS/Socket-2.007/view/Socket.pm" >2.007 (PEVANS on 2012-12-16)</option> <option value="/release/PEVANS/Socket-2.006/view/Socket.pm" >2.006 (PEVANS on 2012-08-19)</option> <option value="/release/PEVANS/Socket-2.005/view/Socket.pm" >2.005 (PEVANS on 2012-08-16)</option> <option value="/release/PEVANS/Socket-2.004/view/Socket.pm" >2.004 (PEVANS on 2012-08-15)</option> <option value="/release/PEVANS/Socket-2.003/view/Socket.pm" >2.003 (PEVANS on 2012-08-15)</option> <option value="/release/PEVANS/Socket-2.002/view/Socket.pm" >2.002 (PEVANS on 2012-06-06)</option> <option value="/release/PEVANS/Socket-2.001_003/view/Socket.pm" >2.001_003 DEV (PEVANS on 2012-05-31)</option> <option value="/release/PEVANS/Socket-2.001_002/view/Socket.pm" >2.001_002 DEV (PEVANS on 2012-05-22)</option> <option value="/release/PEVANS/Socket-2.001_001/view/Socket.pm" >2.001_001 DEV (PEVANS on 2012-05-18)</option> <option value="/release/PEVANS/Socket-2.001/view/Socket.pm" >2.001 (PEVANS on 2012-03-27)</option> <option value="/release/PEVANS/Socket-2.000/view/Socket.pm" >2.000 (PEVANS on 2012-03-10)</option> <option value="/release/PEVANS/Socket-1.99/view/Socket.pm" >1.99 (PEVANS on 2012-02-21)</option> <option value="/release/PEVANS/Socket-1.98_001/view/Socket.pm" >1.98_001 DEV (PEVANS on 2012-02-17)</option> <option value="/release/PEVANS/Socket-1.98/view/Socket.pm" >1.98 (PEVANS on 2012-02-16)</option> <option value="/release/PEVANS/Socket-1.97_002/view/Socket.pm" >1.97_002 DEV (PEVANS on 2012-02-12)</option> <option value="/release/PEVANS/Socket-1.97_001/view/Socket.pm" >1.97_001 DEV (PEVANS on 2012-02-07)</option> <option value="/release/PEVANS/Socket-1.97/view/Socket.pm" >1.97 (PEVANS on 2011-12-16)</option> <option value="/release/PEVANS/Socket-1.96/view/Socket.pm" >1.96 (PEVANS on 2011-12-11)</option> <option value="/release/PEVANS/Socket-1.95_004/view/Socket.pm" >1.95_004 DEV (PEVANS on 2011-12-07)</option> <option value="/release/PEVANS/Socket-1.95_003/view/Socket.pm" >1.95_003 DEV (PEVANS on 2011-12-06)</option> <option value="/release/PEVANS/Socket-1.95_002/view/Socket.pm" >1.95_002 DEV (PEVANS on 2011-12-05)</option> <option value="/release/PEVANS/Socket-1.95_001/view/Socket.pm" >1.95_001 DEV (PEVANS on 2011-12-02)</option> <option value="/release/PEVANS/Socket-1.95/view/Socket.pm" >1.95 (PEVANS on 2011-12-01)</option> <option value="/release/PEVANS/Socket-1.94_07/view/Socket.pm" >1.94_07 DEV (PEVANS on 2011-11-22)</option> <option value="/release/PEVANS/Socket-1.94_06/view/Socket.pm" >1.94_06 DEV (PEVANS on 2011-10-30)</option> <option value="/release/PEVANS/Socket-1.94_05/view/Socket.pm" >1.94_05 DEV (PEVANS on 2011-10-27)</option> <option value="/release/PEVANS/Socket-1.94_04/view/Socket.pm" >1.94_04 DEV (PEVANS on 2011-10-26)</option> <option value="/release/PEVANS/Socket-1.94_03/view/Socket.pm" >1.94_03 DEV (PEVANS on 2011-10-25)</option> <option value="/release/TOMC/Socket-1.3/view/Socket.pm" >1.3 (TOMC on 1995-11-09)</option> </optgroup> </select> <a data-keyboard-shortcut="g d" class="release-name" href="/dist/Socket">Socket-2.038</a> </div> <span class="river-gauge-gauge"> <svg width="24px" height="15px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g> <title> River stage five • 312 direct dependents • 12867 total dependents </title> <rect x="0" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="5" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="10" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="15" y="0" width="4" height="15" fill="#7ea3f2" /> <rect x="20" y="0" width="4" height="15" fill="#7ea3f2" /> </g> </svg> </span> <div id="Socket-fav" class="show-logged-in"> <form action="/account/favorite/add" style="display: inline" method="POST"> <input type="hidden" name="remove" value="0"> <input type="hidden" name="release" value="Socket-2.038"> <input type="hidden" name="author" value="PEVANS"> <input type="hidden" name="distribution" value="Socket"> <button type="submit" class="favorite highlight"><span>9</span> ++</button> </form> </div> <div class="show-logged-out"> <button class="fav-not-logged-in favorite highlight"><span>9</span> ++</button> </div> / <span>Socket</span> </div> </div> <main class="content"> <nav class="toc"> <div class="toc-header"><strong>Contents</strong></div> <ul> <li><a href="#NAME">NAME</a></li> <li><a href="#SYNOPSIS">SYNOPSIS</a></li> <li><a href="#DESCRIPTION">DESCRIPTION</a></li> <li><a href="#CONSTANTS">CONSTANTS</a> <ul> <li><a href="#PF_INET%2C-PF_INET6%2C-PF_UNIX%2C-...">PF_INET, PF_INET6, PF_UNIX, ...</a></li> <li><a href="#AF_INET%2C-AF_INET6%2C-AF_UNIX%2C-...">AF_INET, AF_INET6, AF_UNIX, ...</a></li> <li><a href="#SOCK_STREAM%2C-SOCK_DGRAM%2C-SOCK_RAW%2C-...">SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ...</a></li> <li><a href="#SOCK_NONBLOCK.-SOCK_CLOEXEC">SOCK_NONBLOCK. SOCK_CLOEXEC</a></li> <li><a href="#SOL_SOCKET">SOL_SOCKET</a></li> <li><a href="#SO_ACCEPTCONN%2C-SO_BROADCAST%2C-SO_ERROR%2C-...">SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, ...</a></li> <li><a href="#IP_OPTIONS%2C-IP_TOS%2C-IP_TTL%2C-...">IP_OPTIONS, IP_TOS, IP_TTL, ...</a></li> <li><a href="#IP_PMTUDISC_WANT%2C-IP_PMTUDISC_DONT%2C-...">IP_PMTUDISC_WANT, IP_PMTUDISC_DONT, ...</a></li> <li><a href="#IPTOS_LOWDELAY%2C-IPTOS_THROUGHPUT%2C-IPTOS_RELIABILITY%2C-...">IPTOS_LOWDELAY, IPTOS_THROUGHPUT, IPTOS_RELIABILITY, ...</a></li> <li><a href="#MSG_BCAST%2C-MSG_OOB%2C-MSG_TRUNC%2C-...">MSG_BCAST, MSG_OOB, MSG_TRUNC, ...</a></li> <li><a href="#SHUT_RD%2C-SHUT_RDWR%2C-SHUT_WR">SHUT_RD, SHUT_RDWR, SHUT_WR</a></li> <li><a href="#INADDR_ANY%2C-INADDR_BROADCAST%2C-INADDR_LOOPBACK%2C-INADDR_NONE">INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE</a></li> <li><a href="#IPPROTO_IP%2C-IPPROTO_IPV6%2C-IPPROTO_TCP%2C-...">IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, ...</a></li> <li><a href="#TCP_CORK%2C-TCP_KEEPALIVE%2C-TCP_NODELAY%2C-...">TCP_CORK, TCP_KEEPALIVE, TCP_NODELAY, ...</a></li> <li><a href="#IN6ADDR_ANY%2C-IN6ADDR_LOOPBACK">IN6ADDR_ANY, IN6ADDR_LOOPBACK</a></li> <li><a href="#IPV6_ADD_MEMBERSHIP%2C-IPV6_MTU%2C-IPV6_V6ONLY%2C-...">IPV6_ADD_MEMBERSHIP, IPV6_MTU, IPV6_V6ONLY, ...</a></li> </ul> </li> <li><a href="#STRUCTURE-MANIPULATORS">STRUCTURE MANIPULATORS</a> <ul> <li><a href="#%24family-%3D-sockaddr_family-%24sockaddr">$family = sockaddr_family $sockaddr</a></li> <li><a href="#%24sockaddr-%3D-pack_sockaddr_in-%24port%2C-%24ip_address">$sockaddr = pack_sockaddr_in $port, $ip_address</a></li> <li><a href="#(%24port%2C-%24ip_address)-%3D-unpack_sockaddr_in-%24sockaddr">($port, $ip_address) = unpack_sockaddr_in $sockaddr</a></li> <li><a href="#%24sockaddr-%3D-sockaddr_in-%24port%2C-%24ip_address">$sockaddr = sockaddr_in $port, $ip_address</a></li> <li><a href="#(%24port%2C-%24ip_address)-%3D-sockaddr_in-%24sockaddr">($port, $ip_address) = sockaddr_in $sockaddr</a></li> <li><a href="#%24sockaddr-%3D-pack_sockaddr_in6-%24port%2C-%24ip6_address%2C-%5B%24scope_id%2C-%5B%24flowinfo%5D%5D">$sockaddr = pack_sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]</a></li> <li><a href="#(%24port%2C-%24ip6_address%2C-%24scope_id%2C-%24flowinfo)-%3D-unpack_sockaddr_in6-%24sockaddr">($port, $ip6_address, $scope_id, $flowinfo) = unpack_sockaddr_in6 $sockaddr</a></li> <li><a href="#%24sockaddr-%3D-sockaddr_in6-%24port%2C-%24ip6_address%2C-%5B%24scope_id%2C-%5B%24flowinfo%5D%5D">$sockaddr = sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]</a></li> <li><a href="#(%24port%2C-%24ip6_address%2C-%24scope_id%2C-%24flowinfo)-%3D-sockaddr_in6-%24sockaddr">($port, $ip6_address, $scope_id, $flowinfo) = sockaddr_in6 $sockaddr</a></li> <li><a href="#%24sockaddr-%3D-pack_sockaddr_un-%24path">$sockaddr = pack_sockaddr_un $path</a></li> <li><a href="#(%24path)-%3D-unpack_sockaddr_un-%24sockaddr">($path) = unpack_sockaddr_un $sockaddr</a></li> <li><a href="#%24sockaddr-%3D-sockaddr_un-%24path">$sockaddr = sockaddr_un $path</a></li> <li><a href="#(%24path)-%3D-sockaddr_un-%24sockaddr">($path) = sockaddr_un $sockaddr</a></li> <li><a href="#%24ip_mreq-%3D-pack_ip_mreq-%24multiaddr%2C-%24interface">$ip_mreq = pack_ip_mreq $multiaddr, $interface</a></li> <li><a href="#(%24multiaddr%2C-%24interface)-%3D-unpack_ip_mreq-%24ip_mreq">($multiaddr, $interface) = unpack_ip_mreq $ip_mreq</a></li> <li><a href="#%24ip_mreq_source-%3D-pack_ip_mreq_source-%24multiaddr%2C-%24source%2C-%24interface">$ip_mreq_source = pack_ip_mreq_source $multiaddr, $source, $interface</a></li> <li><a href="#(%24multiaddr%2C-%24source%2C-%24interface)-%3D-unpack_ip_mreq_source-%24ip_mreq">($multiaddr, $source, $interface) = unpack_ip_mreq_source $ip_mreq</a></li> <li><a href="#%24ipv6_mreq-%3D-pack_ipv6_mreq-%24multiaddr6%2C-%24ifindex">$ipv6_mreq = pack_ipv6_mreq $multiaddr6, $ifindex</a></li> <li><a href="#(%24multiaddr6%2C-%24ifindex)-%3D-unpack_ipv6_mreq-%24ipv6_mreq">($multiaddr6, $ifindex) = unpack_ipv6_mreq $ipv6_mreq</a></li> </ul> </li> <li><a href="#FUNCTIONS">FUNCTIONS</a> <ul> <li><a href="#%24ip_address-%3D-inet_aton-%24string">$ip_address = inet_aton $string</a></li> <li><a href="#%24string-%3D-inet_ntoa-%24ip_address">$string = inet_ntoa $ip_address</a></li> <li><a href="#%24address-%3D-inet_pton-%24family%2C-%24string">$address = inet_pton $family, $string</a></li> <li><a href="#%24string-%3D-inet_ntop-%24family%2C-%24address">$string = inet_ntop $family, $address</a></li> <li><a href="#(%24err%2C-%40result)-%3D-getaddrinfo-%24host%2C-%24service%2C-%5B%24hints%5D">($err, @result) = getaddrinfo $host, $service, [$hints]</a></li> <li><a href="#(%24err%2C-%24hostname%2C-%24servicename)-%3D-getnameinfo-%24sockaddr%2C-%5B%24flags%2C-%5B%24xflags%5D%5D">($err, $hostname, $servicename) = getnameinfo $sockaddr, [$flags, [$xflags]]</a></li> </ul> </li> <li><a href="#getaddrinfo()-%2F-getnameinfo()-ERROR-CONSTANTS">getaddrinfo() / getnameinfo() ERROR CONSTANTS</a></li> <li><a href="#EXAMPLES">EXAMPLES</a> <ul> <li><a href="#Lookup-for-connect()">Lookup for connect()</a></li> <li><a href="#Making-a-human-readable-string-out-of-an-address">Making a human-readable string out of an address</a></li> <li><a href="#Resolving-hostnames-into-IP-addresses">Resolving hostnames into IP addresses</a></li> <li><a href="#Accessing-socket-options">Accessing socket options</a></li> </ul> </li> <li><a href="#AUTHOR">AUTHOR</a></li> </ul></nav> <div class="pod anchors"> <h1 id="NAME">NAME</h1> <p><code>Socket</code> - networking constants and support functions</p> <h1 id="SYNOPSIS">SYNOPSIS</h1> <p><code>Socket</code> a low-level module used by, among other things, the <a href="/pod/IO::Socket">IO::Socket</a> family of modules. The following examples demonstrate some low-level uses but a practical program would likely use the higher-level API provided by <code>IO::Socket</code> or similar instead.</p> <pre><code>use Socket qw(PF_INET SOCK_STREAM pack_sockaddr_in inet_aton); socket(my $socket, PF_INET, SOCK_STREAM, 0) or die "socket: $!"; my $port = getservbyname "echo", "tcp"; connect($socket, pack_sockaddr_in($port, inet_aton("localhost"))) or die "connect: $!"; print $socket "Hello, world!\n"; print <$socket>;</code></pre> <p>See also the <a href="#EXAMPLES">"EXAMPLES"</a> section.</p> <h1 id="DESCRIPTION">DESCRIPTION</h1> <p>This module provides a variety of constants, structure manipulators and other functions related to socket-based networking. The values and functions provided are useful when used in conjunction with Perl core functions such as socket(), setsockopt() and bind(). It also provides several other support functions, mostly for dealing with conversions of network addresses between human-readable and native binary forms, and for hostname resolver operations.</p> <p>Some constants and functions are exported by default by this module; but for backward-compatibility any recently-added symbols are not exported by default and must be requested explicitly. When an import list is provided to the <code>use Socket</code> line, the default exports are not automatically imported. It is therefore best practice to always to explicitly list all the symbols required.</p> <p>Also, some common socket "newline" constants are provided: the constants <code>CR</code>, <code>LF</code>, and <code>CRLF</code>, as well as <code>$CR</code>, <code>$LF</code>, and <code>$CRLF</code>, which map to <code>\015</code>, <code>\012</code>, and <code>\015\012</code>. If you do not want to use the literal characters in your programs, then use the constants provided here. They are not exported by default, but can be imported individually, and with the <code>:crlf</code> export tag:</p> <pre><code>use Socket qw(:DEFAULT :crlf); $sock->print("GET / HTTP/1.0$CRLF");</code></pre> <p>The entire getaddrinfo() subsystem can be exported using the tag <code>:addrinfo</code>; this exports the getaddrinfo() and getnameinfo() functions, and all the <code>AI_*</code>, <code>NI_*</code>, <code>NIx_*</code> and <code>EAI_*</code> constants.</p> <h1 id="CONSTANTS">CONSTANTS</h1> <p>In each of the following groups, there may be many more constants provided than just the ones given as examples in the section heading. If the heading ends <code>...</code> then this means there are likely more; the exact constants provided will depend on the OS and headers found at compile-time.</p> <h2 id="PF_INET,-PF_INET6,-PF_UNIX,-..."><a id="PF_INET"></a><a id="PF_INET-PF_INET6-PF_UNIX"></a>PF_INET, PF_INET6, PF_UNIX, ...</h2> <p>Protocol family constants to use as the first argument to socket() or the value of the <code>SO_DOMAIN</code> or <code>SO_FAMILY</code> socket option.</p> <h2 id="AF_INET,-AF_INET6,-AF_UNIX,-..."><a id="AF_INET"></a><a id="AF_INET-AF_INET6-AF_UNIX"></a>AF_INET, AF_INET6, AF_UNIX, ...</h2> <p>Address family constants used by the socket address structures, to pass to such functions as inet_pton() or getaddrinfo(), or are returned by such functions as sockaddr_family().</p> <h2 id="SOCK_STREAM,-SOCK_DGRAM,-SOCK_RAW,-..."><a id="SOCK_STREAM"></a><a id="SOCK_STREAM-SOCK_DGRAM-SOCK_RAW"></a>SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ...</h2> <p>Socket type constants to use as the second argument to socket(), or the value of the <code>SO_TYPE</code> socket option.</p> <h2 id="SOCK_NONBLOCK.-SOCK_CLOEXEC"><a id="SOCK_NONBLOCK"></a>SOCK_NONBLOCK. SOCK_CLOEXEC</h2> <p>Linux-specific shortcuts to specify the <code>O_NONBLOCK</code> and <code>FD_CLOEXEC</code> flags during a <code>socket(2)</code> call.</p> <pre><code>socket( my $sockh, PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, 0 )</code></pre> <h2 id="SOL_SOCKET">SOL_SOCKET</h2> <p>Socket option level constant for setsockopt() and getsockopt().</p> <h2 id="SO_ACCEPTCONN,-SO_BROADCAST,-SO_ERROR,-..."><a id="SO_ACCEPTCONN"></a><a id="SO_ACCEPTCONN-SO_BROADCAST-SO_ERROR"></a>SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, ...</h2> <p>Socket option name constants for setsockopt() and getsockopt() at the <code>SOL_SOCKET</code> level.</p> <h2 id="IP_OPTIONS,-IP_TOS,-IP_TTL,-..."><a id="IP_OPTIONS"></a><a id="IP_OPTIONS-IP_TOS-IP_TTL"></a>IP_OPTIONS, IP_TOS, IP_TTL, ...</h2> <p>Socket option name constants for IPv4 socket options at the <code>IPPROTO_IP</code> level.</p> <h2 id="IP_PMTUDISC_WANT,-IP_PMTUDISC_DONT,-..."><a id="IP_PMTUDISC_WANT"></a><a id="IP_PMTUDISC_WANT-IP_PMTUDISC_DONT"></a>IP_PMTUDISC_WANT, IP_PMTUDISC_DONT, ...</h2> <p>Socket option value constants for <code>IP_MTU_DISCOVER</code> socket option.</p> <h2 id="IPTOS_LOWDELAY,-IPTOS_THROUGHPUT,-IPTOS_RELIABILITY,-..."><a id="IPTOS_LOWDELAY"></a><a id="IPTOS_LOWDELAY-IPTOS_THROUGHPUT-IPTOS_RELIABILITY"></a>IPTOS_LOWDELAY, IPTOS_THROUGHPUT, IPTOS_RELIABILITY, ...</h2> <p>Socket option value constants for <code>IP_TOS</code> socket option.</p> <h2 id="MSG_BCAST,-MSG_OOB,-MSG_TRUNC,-..."><a id="MSG_BCAST"></a><a id="MSG_BCAST-MSG_OOB-MSG_TRUNC"></a>MSG_BCAST, MSG_OOB, MSG_TRUNC, ...</h2> <p>Message flag constants for send() and recv().</p> <h2 id="SHUT_RD,-SHUT_RDWR,-SHUT_WR"><a id="SHUT_RD"></a><a id="SHUT_RD-SHUT_RDWR-SHUT_WR"></a>SHUT_RD, SHUT_RDWR, SHUT_WR</h2> <p>Direction constants for shutdown().</p> <h2 id="INADDR_ANY,-INADDR_BROADCAST,-INADDR_LOOPBACK,-INADDR_NONE"><a id="INADDR_ANY"></a><a id="INADDR_ANY-INADDR_BROADCAST-INADDR_LOOPBACK-INADDR_NONE"></a>INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE</h2> <p>Constants giving the special <code>AF_INET</code> addresses for wildcard, broadcast, local loopback, and invalid addresses.</p> <p>Normally equivalent to inet_aton('0.0.0.0'), inet_aton('255.255.255.255'), inet_aton('localhost') and inet_aton('255.255.255.255') respectively.</p> <h2 id="IPPROTO_IP,-IPPROTO_IPV6,-IPPROTO_TCP,-..."><a id="IPPROTO_IP"></a><a id="IPPROTO_IP-IPPROTO_IPV6-IPPROTO_TCP"></a>IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, ...</h2> <p>IP protocol constants to use as the third argument to socket(), the level argument to getsockopt() or setsockopt(), or the value of the <code>SO_PROTOCOL</code> socket option.</p> <h2 id="TCP_CORK,-TCP_KEEPALIVE,-TCP_NODELAY,-..."><a id="TCP_CORK"></a><a id="TCP_CORK-TCP_KEEPALIVE-TCP_NODELAY"></a>TCP_CORK, TCP_KEEPALIVE, TCP_NODELAY, ...</h2> <p>Socket option name constants for TCP socket options at the <code>IPPROTO_TCP</code> level.</p> <h2 id="IN6ADDR_ANY,-IN6ADDR_LOOPBACK"><a id="IN6ADDR_ANY"></a><a id="IN6ADDR_ANY-IN6ADDR_LOOPBACK"></a>IN6ADDR_ANY, IN6ADDR_LOOPBACK</h2> <p>Constants giving the special <code>AF_INET6</code> addresses for wildcard and local loopback.</p> <p>Normally equivalent to inet_pton(AF_INET6, "::") and inet_pton(AF_INET6, "::1") respectively.</p> <h2 id="IPV6_ADD_MEMBERSHIP,-IPV6_MTU,-IPV6_V6ONLY,-..."><a id="IPV6_ADD_MEMBERSHIP"></a><a id="IPV6_ADD_MEMBERSHIP-IPV6_MTU-IPV6_V6ONLY"></a>IPV6_ADD_MEMBERSHIP, IPV6_MTU, IPV6_V6ONLY, ...</h2> <p>Socket option name constants for IPv6 socket options at the <code>IPPROTO_IPV6</code> level.</p> <h1 id="STRUCTURE-MANIPULATORS"><a id="STRUCTURE"></a>STRUCTURE MANIPULATORS</h1> <p>The following functions convert between lists of Perl values and packed binary strings representing structures.</p> <h2 id="$family-=-sockaddr_family-$sockaddr"><a id="family-sockaddr_family-sockaddr"></a>$family = sockaddr_family $sockaddr</h2> <p>Takes a packed socket address (as returned by pack_sockaddr_in(), pack_sockaddr_un() or the perl builtin functions getsockname() and getpeername()). Returns the address family tag. This will be one of the <code>AF_*</code> constants, such as <code>AF_INET</code> for a <code>sockaddr_in</code> addresses or <code>AF_UNIX</code> for a <code>sockaddr_un</code>. It can be used to figure out what unpack to use for a sockaddr of unknown type.</p> <h2 id="$sockaddr-=-pack_sockaddr_in-$port,-$ip_address"><a id="sockaddr-pack_sockaddr_in-port-ip_address"></a>$sockaddr = pack_sockaddr_in $port, $ip_address</h2> <p>Takes two arguments, a port number and an opaque string (as returned by inet_aton(), or a v-string). Returns the <code>sockaddr_in</code> structure with those arguments packed in and <code>AF_INET</code> filled in. For Internet domain sockets, this structure is normally what you need for the arguments in bind(), connect(), and send().</p> <p>An undefined $port argument is taken as zero; an undefined $ip_address is considered a fatal error.</p> <h2 id="($port,-$ip_address)-=-unpack_sockaddr_in-$sockaddr"><a id="port-ip_address-unpack_sockaddr_in-sockaddr"></a>($port, $ip_address) = unpack_sockaddr_in $sockaddr</h2> <p>Takes a <code>sockaddr_in</code> structure (as returned by pack_sockaddr_in(), getpeername() or recv()). Returns a list of two elements: the port and an opaque string representing the IP address (you can use inet_ntoa() to convert the address to the four-dotted numeric format). Will croak if the structure does not represent an <code>AF_INET</code> address.</p> <p>In scalar context will return just the IP address.</p> <h2 id="$sockaddr-=-sockaddr_in-$port,-$ip_address"><a id="sockaddr-sockaddr_in-port-ip_address"></a>$sockaddr = sockaddr_in $port, $ip_address</h2> <h2 id="($port,-$ip_address)-=-sockaddr_in-$sockaddr"><a id="port-ip_address-sockaddr_in-sockaddr"></a>($port, $ip_address) = sockaddr_in $sockaddr</h2> <p>A wrapper of pack_sockaddr_in() or unpack_sockaddr_in(). In list context, unpacks its argument and returns a list consisting of the port and IP address. In scalar context, packs its port and IP address arguments as a <code>sockaddr_in</code> and returns it.</p> <p>Provided largely for legacy compatibility; it is better to use pack_sockaddr_in() or unpack_sockaddr_in() explicitly.</p> <h2 id="$sockaddr-=-pack_sockaddr_in6-$port,-$ip6_address,-[$scope_id,-[$flowinfo]]"><a id="sockaddr-pack_sockaddr_in6-port-ip6_address-scope_id-flowinfo"></a>$sockaddr = pack_sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]</h2> <p>Takes two to four arguments, a port number, an opaque string (as returned by inet_pton()), optionally a scope ID number, and optionally a flow label number. Returns the <code>sockaddr_in6</code> structure with those arguments packed in and <code>AF_INET6</code> filled in. IPv6 equivalent of pack_sockaddr_in().</p> <p>An undefined $port argument is taken as zero; an undefined $ip6_address is considered a fatal error.</p> <h2 id="($port,-$ip6_address,-$scope_id,-$flowinfo)-=-unpack_sockaddr_in6-$sockaddr"><a id="port-ip6_address-scope_id-flowinfo-unpack_sockaddr_in6-sockaddr"></a>($port, $ip6_address, $scope_id, $flowinfo) = unpack_sockaddr_in6 $sockaddr</h2> <p>Takes a <code>sockaddr_in6</code> structure. Returns a list of four elements: the port number, an opaque string representing the IPv6 address, the scope ID, and the flow label. (You can use inet_ntop() to convert the address to the usual string format). Will croak if the structure does not represent an <code>AF_INET6</code> address.</p> <p>In scalar context will return just the IP address.</p> <h2 id="$sockaddr-=-sockaddr_in6-$port,-$ip6_address,-[$scope_id,-[$flowinfo]]"><a id="sockaddr-sockaddr_in6-port-ip6_address-scope_id-flowinfo"></a>$sockaddr = sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]</h2> <h2 id="($port,-$ip6_address,-$scope_id,-$flowinfo)-=-sockaddr_in6-$sockaddr"><a id="port-ip6_address-scope_id-flowinfo-sockaddr_in6-sockaddr"></a>($port, $ip6_address, $scope_id, $flowinfo) = sockaddr_in6 $sockaddr</h2> <p>A wrapper of pack_sockaddr_in6() or unpack_sockaddr_in6(). In list context, unpacks its argument according to unpack_sockaddr_in6(). In scalar context, packs its arguments according to pack_sockaddr_in6().</p> <p>Provided largely for legacy compatibility; it is better to use pack_sockaddr_in6() or unpack_sockaddr_in6() explicitly.</p> <h2 id="$sockaddr-=-pack_sockaddr_un-$path"><a id="sockaddr-pack_sockaddr_un-path"></a>$sockaddr = pack_sockaddr_un $path</h2> <p>Takes one argument, a pathname. Returns the <code>sockaddr_un</code> structure with that path packed in with <code>AF_UNIX</code> filled in. For <code>PF_UNIX</code> sockets, this structure is normally what you need for the arguments in bind(), connect(), and send().</p> <h2 id="($path)-=-unpack_sockaddr_un-$sockaddr"><a id="path-unpack_sockaddr_un-sockaddr"></a>($path) = unpack_sockaddr_un $sockaddr</h2> <p>Takes a <code>sockaddr_un</code> structure (as returned by pack_sockaddr_un(), getpeername() or recv()). Returns a list of one element: the pathname. Will croak if the structure does not represent an <code>AF_UNIX</code> address.</p> <h2 id="$sockaddr-=-sockaddr_un-$path"><a id="sockaddr-sockaddr_un-path"></a>$sockaddr = sockaddr_un $path</h2> <h2 id="($path)-=-sockaddr_un-$sockaddr"><a id="path-sockaddr_un-sockaddr"></a>($path) = sockaddr_un $sockaddr</h2> <p>A wrapper of pack_sockaddr_un() or unpack_sockaddr_un(). In a list context, unpacks its argument and returns a list consisting of the pathname. In a scalar context, packs its pathname as a <code>sockaddr_un</code> and returns it.</p> <p>Provided largely for legacy compatibility; it is better to use pack_sockaddr_un() or unpack_sockaddr_un() explicitly.</p> <p>These are only supported if your system has <<i>sys/un.h</i>>.</p> <h2 id="$ip_mreq-=-pack_ip_mreq-$multiaddr,-$interface"><a id="ip_mreq-pack_ip_mreq-multiaddr-interface"></a>$ip_mreq = pack_ip_mreq $multiaddr, $interface</h2> <p>Takes an IPv4 multicast address and optionally an interface address (or <code>INADDR_ANY</code>). Returns the <code>ip_mreq</code> structure with those arguments packed in. Suitable for use with the <code>IP_ADD_MEMBERSHIP</code> and <code>IP_DROP_MEMBERSHIP</code> sockopts.</p> <h2 id="($multiaddr,-$interface)-=-unpack_ip_mreq-$ip_mreq"><a id="multiaddr-interface-unpack_ip_mreq-ip_mreq"></a>($multiaddr, $interface) = unpack_ip_mreq $ip_mreq</h2> <p>Takes an <code>ip_mreq</code> structure. Returns a list of two elements; the IPv4 multicast address and interface address.</p> <h2 id="$ip_mreq_source-=-pack_ip_mreq_source-$multiaddr,-$source,-$interface"><a id="ip_mreq_source-pack_ip_mreq_source-multiaddr-source-interface"></a>$ip_mreq_source = pack_ip_mreq_source $multiaddr, $source, $interface</h2> <p>Takes an IPv4 multicast address, source address, and optionally an interface address (or <code>INADDR_ANY</code>). Returns the <code>ip_mreq_source</code> structure with those arguments packed in. Suitable for use with the <code>IP_ADD_SOURCE_MEMBERSHIP</code> and <code>IP_DROP_SOURCE_MEMBERSHIP</code> sockopts.</p> <h2 id="($multiaddr,-$source,-$interface)-=-unpack_ip_mreq_source-$ip_mreq"><a id="multiaddr-source-interface-unpack_ip_mreq_source-ip_mreq"></a>($multiaddr, $source, $interface) = unpack_ip_mreq_source $ip_mreq</h2> <p>Takes an <code>ip_mreq_source</code> structure. Returns a list of three elements; the IPv4 multicast address, source address and interface address.</p> <h2 id="$ipv6_mreq-=-pack_ipv6_mreq-$multiaddr6,-$ifindex"><a id="ipv6_mreq-pack_ipv6_mreq-multiaddr6-ifindex"></a>$ipv6_mreq = pack_ipv6_mreq $multiaddr6, $ifindex</h2> <p>Takes an IPv6 multicast address and an interface number. Returns the <code>ipv6_mreq</code> structure with those arguments packed in. Suitable for use with the <code>IPV6_ADD_MEMBERSHIP</code> and <code>IPV6_DROP_MEMBERSHIP</code> sockopts.</p> <h2 id="($multiaddr6,-$ifindex)-=-unpack_ipv6_mreq-$ipv6_mreq"><a id="multiaddr6-ifindex-unpack_ipv6_mreq-ipv6_mreq"></a>($multiaddr6, $ifindex) = unpack_ipv6_mreq $ipv6_mreq</h2> <p>Takes an <code>ipv6_mreq</code> structure. Returns a list of two elements; the IPv6 address and an interface number.</p> <h1 id="FUNCTIONS">FUNCTIONS</h1> <h2 id="$ip_address-=-inet_aton-$string"><a id="ip_address-inet_aton-string"></a>$ip_address = inet_aton $string</h2> <p>Takes a string giving the name of a host, or a textual representation of an IP address and translates that to an packed binary address structure suitable to pass to pack_sockaddr_in(). If passed a hostname that cannot be resolved, returns <code>undef</code>. For multi-homed hosts (hosts with more than one address), the first address found is returned.</p> <p>For portability do not assume that the result of inet_aton() is 32 bits wide, in other words, that it would contain only the IPv4 address in network order.</p> <p>This IPv4-only function is provided largely for legacy reasons. Newly-written code should use getaddrinfo() or inet_pton() instead for IPv6 support.</p> <h2 id="$string-=-inet_ntoa-$ip_address"><a id="string-inet_ntoa-ip_address"></a>$string = inet_ntoa $ip_address</h2> <p>Takes a packed binary address structure such as returned by unpack_sockaddr_in() (or a v-string representing the four octets of the IPv4 address in network order) and translates it into a string of the form <code>d.d.d.d</code> where the <code>d</code>s are numbers less than 256 (the normal human-readable four dotted number notation for Internet addresses).</p> <p>This IPv4-only function is provided largely for legacy reasons. Newly-written code should use getnameinfo() or inet_ntop() instead for IPv6 support.</p> <h2 id="$address-=-inet_pton-$family,-$string"><a id="address-inet_pton-family-string"></a>$address = inet_pton $family, $string</h2> <p>Takes an address family (such as <code>AF_INET</code> or <code>AF_INET6</code>) and a string containing a textual representation of an address in that family and translates that to an packed binary address structure.</p> <p>See also getaddrinfo() for a more powerful and flexible function to look up socket addresses given hostnames or textual addresses.</p> <h2 id="$string-=-inet_ntop-$family,-$address"><a id="string-inet_ntop-family-address"></a>$string = inet_ntop $family, $address</h2> <p>Takes an address family and a packed binary address structure and translates it into a human-readable textual representation of the address; typically in <code>d.d.d.d</code> form for <code>AF_INET</code> or <code>hhhh:hhhh::hhhh</code> form for <code>AF_INET6</code>.</p> <p>See also getnameinfo() for a more powerful and flexible function to turn socket addresses into human-readable textual representations.</p> <h2 id="($err,-@result)-=-getaddrinfo-$host,-$service,-[$hints]"><a id="err-result-getaddrinfo-host-service-hints"></a>($err, @result) = getaddrinfo $host, $service, [$hints]</h2> <p>Given both a hostname and service name, this function attempts to resolve the host name into a list of network addresses, and the service name into a protocol and port number, and then returns a list of address structures suitable to connect() to it.</p> <p>Given just a host name, this function attempts to resolve it to a list of network addresses, and then returns a list of address structures giving these addresses.</p> <p>Given just a service name, this function attempts to resolve it to a protocol and port number, and then returns a list of address structures that represent it suitable to bind() to. This use should be combined with the <code>AI_PASSIVE</code> flag; see below.</p> <p>Given neither name, it generates an error.</p> <p>If present, $hints should be a reference to a hash, where the following keys are recognised:</p> <dl> <dt id="flags-=>-INT"><a id="flags"></a><a id="flags-INT"></a>flags => INT</dt> <dd> <p>A bitfield containing <code>AI_*</code> constants; see below.</p> </dd> <dt id="family-=>-INT"><a id="family"></a><a id="family-INT"></a>family => INT</dt> <dd> <p>Restrict to only generating addresses in this address family</p> </dd> <dt id="socktype-=>-INT"><a id="socktype"></a><a id="socktype-INT"></a>socktype => INT</dt> <dd> <p>Restrict to only generating addresses of this socket type</p> </dd> <dt id="protocol-=>-INT"><a id="protocol"></a><a id="protocol-INT"></a>protocol => INT</dt> <dd> <p>Restrict to only generating addresses for this protocol</p> </dd> </dl> <p>The return value will be a list; the first value being an error indication, followed by a list of address structures (if no error occurred).</p> <p>The error value will be a dualvar; comparable to the <code>EAI_*</code> error constants, or printable as a human-readable error message string. If no error occurred it will be zero numerically and an empty string.</p> <p>Each value in the results list will be a hash reference containing the following fields:</p> <dl> <dt id="family-=>-INT1"><a id="family1"></a><a id="family-INT1"></a>family => INT</dt> <dd> <p>The address family (e.g. <code>AF_INET</code>)</p> </dd> <dt id="socktype-=>-INT1"><a id="socktype1"></a><a id="socktype-INT1"></a>socktype => INT</dt> <dd> <p>The socket type (e.g. <code>SOCK_STREAM</code>)</p> </dd> <dt id="protocol-=>-INT1"><a id="protocol1"></a><a id="protocol-INT1"></a>protocol => INT</dt> <dd> <p>The protocol (e.g. <code>IPPROTO_TCP</code>)</p> </dd> <dt id="addr-=>-STRING"><a id="addr"></a><a id="addr-STRING"></a>addr => STRING</dt> <dd> <p>The address in a packed string (such as would be returned by pack_sockaddr_in())</p> </dd> <dt id="canonname-=>-STRING"><a id="canonname"></a><a id="canonname-STRING"></a>canonname => STRING</dt> <dd> <p>The canonical name for the host if the <code>AI_CANONNAME</code> flag was provided, or <code>undef</code> otherwise. This field will only be present on the first returned address.</p> </dd> </dl> <p>The following flag constants are recognised in the $hints hash. Other flag constants may exist as provided by the OS.</p> <dl> <dt id="AI_PASSIVE">AI_PASSIVE</dt> <dd> <p>Indicates that this resolution is for a local bind() for a passive (i.e. listening) socket, rather than an active (i.e. connecting) socket.</p> </dd> <dt id="AI_CANONNAME">AI_CANONNAME</dt> <dd> <p>Indicates that the caller wishes the canonical hostname (<code>canonname</code>) field of the result to be filled in.</p> </dd> <dt id="AI_NUMERICHOST">AI_NUMERICHOST</dt> <dd> <p>Indicates that the caller will pass a numeric address, rather than a hostname, and that getaddrinfo() must not perform a resolve operation on this name. This flag will prevent a possibly-slow network lookup operation, and instead return an error if a hostname is passed.</p> </dd> </dl> <h2 id="($err,-$hostname,-$servicename)-=-getnameinfo-$sockaddr,-[$flags,-[$xflags]]"><a id="err-hostname-servicename-getnameinfo-sockaddr-flags-xflags"></a>($err, $hostname, $servicename) = getnameinfo $sockaddr, [$flags, [$xflags]]</h2> <p>Given a packed socket address (such as from getsockname(), getpeername(), or returned by getaddrinfo() in a <code>addr</code> field), returns the hostname and symbolic service name it represents. $flags may be a bitmask of <code>NI_*</code> constants, or defaults to 0 if unspecified.</p> <p>The return value will be a list; the first value being an error condition, followed by the hostname and service name.</p> <p>The error value will be a dualvar; comparable to the <code>EAI_*</code> error constants, or printable as a human-readable error message string. The host and service names will be plain strings.</p> <p>The following flag constants are recognised as $flags. Other flag constants may exist as provided by the OS.</p> <dl> <dt id="NI_NUMERICHOST">NI_NUMERICHOST</dt> <dd> <p>Requests that a human-readable string representation of the numeric address be returned directly, rather than performing a name resolve operation that may convert it into a hostname. This will also avoid potentially-blocking network IO.</p> </dd> <dt id="NI_NUMERICSERV">NI_NUMERICSERV</dt> <dd> <p>Requests that the port number be returned directly as a number representation rather than performing a name resolve operation that may convert it into a service name.</p> </dd> <dt id="NI_NAMEREQD">NI_NAMEREQD</dt> <dd> <p>If a name resolve operation fails to provide a name, then this flag will cause getnameinfo() to indicate an error, rather than returning the numeric representation as a human-readable string.</p> </dd> <dt id="NI_DGRAM">NI_DGRAM</dt> <dd> <p>Indicates that the socket address relates to a <code>SOCK_DGRAM</code> socket, for the services whose name differs between TCP and UDP protocols.</p> </dd> </dl> <p>The following constants may be supplied as $xflags.</p> <dl> <dt id="NIx_NOHOST">NIx_NOHOST</dt> <dd> <p>Indicates that the caller is not interested in the hostname of the result, so it does not have to be converted. <code>undef</code> will be returned as the hostname.</p> </dd> <dt id="NIx_NOSERV">NIx_NOSERV</dt> <dd> <p>Indicates that the caller is not interested in the service name of the result, so it does not have to be converted. <code>undef</code> will be returned as the service name.</p> </dd> </dl> <h1 id="getaddrinfo()-/-getnameinfo()-ERROR-CONSTANTS"><a id="getaddrinfo"></a><a id="getaddrinfo-getnameinfo-ERROR-CONSTANTS"></a>getaddrinfo() / getnameinfo() ERROR CONSTANTS</h1> <p>The following constants may be returned by getaddrinfo() or getnameinfo(). Others may be provided by the OS.</p> <dl> <dt id="EAI_AGAIN">EAI_AGAIN</dt> <dd> <p>A temporary failure occurred during name resolution. The operation may be successful if it is retried later.</p> </dd> <dt id="EAI_BADFLAGS">EAI_BADFLAGS</dt> <dd> <p>The value of the <code>flags</code> hint to getaddrinfo(), or the $flags parameter to getnameinfo() contains unrecognised flags.</p> </dd> <dt id="EAI_FAMILY">EAI_FAMILY</dt> <dd> <p>The <code>family</code> hint to getaddrinfo(), or the family of the socket address passed to getnameinfo() is not supported.</p> </dd> <dt id="EAI_NODATA">EAI_NODATA</dt> <dd> <p>The host name supplied to getaddrinfo() did not provide any usable address data.</p> </dd> <dt id="EAI_NONAME">EAI_NONAME</dt> <dd> <p>The host name supplied to getaddrinfo() does not exist, or the address supplied to getnameinfo() is not associated with a host name and the <code>NI_NAMEREQD</code> flag was supplied.</p> </dd> <dt id="EAI_SERVICE">EAI_SERVICE</dt> <dd> <p>The service name supplied to getaddrinfo() is not available for the socket type given in the $hints.</p> </dd> </dl> <h1 id="EXAMPLES">EXAMPLES</h1> <h2 id="Lookup-for-connect()"><a id="Lookup"></a><a id="Lookup-for-connect"></a>Lookup for connect()</h2> <p>The getaddrinfo() function converts a hostname and a service name into a list of structures, each containing a potential way to connect() to the named service on the named host.</p> <pre><code>use IO::Socket; use Socket qw(SOCK_STREAM getaddrinfo); my %hints = (socktype => SOCK_STREAM); my ($err, @res) = getaddrinfo("localhost", "echo", \%hints); die "Cannot getaddrinfo - $err" if $err; my $sock; foreach my $ai (@res) { my $candidate = IO::Socket->new(); $candidate->socket($ai->{family}, $ai->{socktype}, $ai->{protocol}) or next; $candidate->connect($ai->{addr}) or next; $sock = $candidate; last; } die "Cannot connect to localhost:echo" unless $sock; $sock->print("Hello, world!\n"); print <$sock>;</code></pre> <p>Because a list of potential candidates is returned, the <code>while</code> loop tries each in turn until it finds one that succeeds both the socket() and connect() calls.</p> <p>This function performs the work of the legacy functions gethostbyname(), getservbyname(), inet_aton() and pack_sockaddr_in().</p> <p>In practice this logic is better performed by <a href="/pod/IO::Socket::IP">IO::Socket::IP</a>.</p> <h2 id="Making-a-human-readable-string-out-of-an-address"><a id="Making"></a>Making a human-readable string out of an address</h2> <p>The getnameinfo() function converts a socket address, such as returned by getsockname() or getpeername(), into a pair of human-readable strings representing the address and service name.</p> <pre><code>use IO::Socket::IP; use Socket qw(getnameinfo); my $server = IO::Socket::IP->new(LocalPort => 12345, Listen => 1) or die "Cannot listen - $@"; my $socket = $server->accept or die "accept: $!"; my ($err, $hostname, $servicename) = getnameinfo($socket->peername); die "Cannot getnameinfo - $err" if $err; print "The peer is connected from $hostname\n";</code></pre> <p>Since in this example only the hostname was used, the redundant conversion of the port number into a service name may be omitted by passing the <code>NIx_NOSERV</code> flag.</p> <pre><code>use Socket qw(getnameinfo NIx_NOSERV); my ($err, $hostname) = getnameinfo($socket->peername, 0, NIx_NOSERV);</code></pre> <p>This function performs the work of the legacy functions unpack_sockaddr_in(), inet_ntoa(), gethostbyaddr() and getservbyport().</p> <p>In practice this logic is better performed by <a href="/pod/IO::Socket::IP">IO::Socket::IP</a>.</p> <h2 id="Resolving-hostnames-into-IP-addresses"><a id="Resolving"></a>Resolving hostnames into IP addresses</h2> <p>To turn a hostname into a human-readable plain IP address use getaddrinfo() to turn the hostname into a list of socket structures, then getnameinfo() on each one to make it a readable IP address again.</p> <pre><code>use Socket qw(:addrinfo SOCK_RAW); my ($err, @res) = getaddrinfo($hostname, "", {socktype => SOCK_RAW}); die "Cannot getaddrinfo - $err" if $err; while( my $ai = shift @res ) { my ($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx_NOSERV); die "Cannot getnameinfo - $err" if $err; print "$ipaddr\n"; }</code></pre> <p>The <code>socktype</code> hint to getaddrinfo() filters the results to only include one socket type and protocol. Without this most OSes return three combinations, for <code>SOCK_STREAM</code>, <code>SOCK_DGRAM</code> and <code>SOCK_RAW</code>, resulting in triplicate output of addresses. The <code>NI_NUMERICHOST</code> flag to getnameinfo() causes it to return a string-formatted plain IP address, rather than reverse resolving it back into a hostname.</p> <p>This combination performs the work of the legacy functions gethostbyname() and inet_ntoa().</p> <h2 id="Accessing-socket-options"><a id="Accessing"></a>Accessing socket options</h2> <p>The many <code>SO_*</code> and other constants provide the socket option names for getsockopt() and setsockopt().</p> <pre><code>use IO::Socket::INET; use Socket qw(SOL_SOCKET SO_RCVBUF IPPROTO_IP IP_TTL); my $socket = IO::Socket::INET->new(LocalPort => 0, Proto => 'udp') or die "Cannot create socket: $@"; $socket->setsockopt(SOL_SOCKET, SO_RCVBUF, 64*1024) or die "setsockopt: $!"; print "Receive buffer is ", $socket->getsockopt(SOL_SOCKET, SO_RCVBUF), " bytes\n"; print "IP TTL is ", $socket->getsockopt(IPPROTO_IP, IP_TTL), "\n";</code></pre> <p>As a convenience, <a href="/pod/IO::Socket">IO::Socket</a>'s setsockopt() method will convert a number into a packed byte buffer, and getsockopt() will unpack a byte buffer of the correct size back into a number.</p> <h1 id="AUTHOR">AUTHOR</h1> <p>This module was originally maintained in Perl core by the Perl 5 Porters.</p> <p>It was extracted to dual-life on CPAN at version 1.95 by Paul Evans <leonerd@leonerd.org.uk></p></div> <div id="metacpan_install-instructions-dialog" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Module Install Instructions</h4> </div> <div class="modal-body"> <p>To install Socket, copy and paste the appropriate command in to your terminal.</p> <p><a href="/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p> <pre><code>cpanm Socket</code></pre> <p><a href="/pod/CPAN">CPAN shell</a></p> <pre><code>perl -MCPAN -e shell install Socket</code></pre> <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p> </div> <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a> </div> </div> </div> </div> </main> <div class="content-pagination"> </div> </div> <footer class="footer"> <div class="footer-container"> <div class="footer-social"> <div class="footer-link footer-logo"> <a href="/"> <img src="/static/images/metacpan-logo.svg" alt="MetaCPAN" /> </a> </div> <a class="footer-social-link" href="https://github.com/metacpan"> <i class="fab fa-github-square"></i> </a> <a class="footer-social-link" href="https://fosstodon.org/@metacpan"> <i class="fab fa-mastodon"></i> </a> </div> <div class="footer-links"> <div class="footer-link"> <a href="/about">About</a> </div> <div class="footer-link"> <a href="/about/sponsors">Sponsor</a> </div> <div class="footer-link"> <a href="https://grep.metacpan.org">grep::cpan</a> </div> <div class="footer-link"> <a href="/recent">Recent</a> </div> <div class="footer-link"> <a href="/about/faq">FAQ</a> </div> <div class="footer-link"> <a href="/tools">Tools</a> </div> <div class="footer-link"> <a href="https://fastapi.metacpan.org/">API</a> </div> <div class="footer-link"> <a href="https://www.perl.org/">Perl.org</a> </div> </div> <div class="footer-sponsors"> <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener"> <img class="footer-sponsor-bytemark" src="/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener"> <img class="footer-sponsor-liquidweb" src="/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener"> <img class="footer-sponsor-deriv" src="/static/images/sponsors/deriv.svg" alt="Deriv logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener"> <img class="footer-sponsor-geocode" src="/static/images/sponsors/geocodelogo.svg" alt="Geocode logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener"> <img class="footer-sponsor-fastly" src="/static/images/sponsors/fastly_logo.svg" alt="Fastly logo"> </a> <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener"> <img class="footer-sponsor-opencage" src="/static/images/sponsors/open-cage.svg" alt="OpenCage logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://www.elastic.co/" rel="noopener"> <img class="footer-sponsor-elastic" src="/static/images/sponsors/elastic.svg" alt="Elastic logo"> </a> <!-- Added 2024-07-22 --> <a class="footer-sponsor-link" target="_blank" href="https://route4me.com/" rel="noopener"> <img class="footer-sponsor-route4me" src="/static/images/sponsors/route4me.png" alt="Route4Me logo"> </a> </div> </div> </footer> <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Keyboard Shortcuts</h4> </div> <div class="modal-body row"> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Global</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>s</kbd> </td> <td>Focus search bar</td> </tr> <tr> <td class="keys"> <kbd>?</kbd> </td> <td>Bring up this help dialog</td> </tr> </tbody> </table> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>GitHub</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>p</kbd> </td> <td>Go to pull requests</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>go to github issues (only if github is preferred repository)</td> </tr> </tbody> </table> </div> <div class="col-md-6"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>POD</th> </tr> </thead> <tbody> <tr> <td class="keys"> <kbd>g</kbd> <kbd>a</kbd> </td> <td>Go to author</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>c</kbd> </td> <td>Go to changes</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>i</kbd> </td> <td>Go to issues</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>d</kbd> </td> <td>Go to dist</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>r</kbd> </td> <td>Go to repository/SCM</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>s</kbd> </td> <td>Go to source</td> </tr> <tr> <td class="keys"> <kbd>g</kbd> <kbd>b</kbd> </td> <td>Go to file browse</td> </tr> </tbody> </table> </div> <div class="col-md-12"> <table class="table keyboard-shortcuts"> <thead> <tr> <th></th> <th>Search terms</th> </tr> </thead> <tbody> <tr> <td><em>module:</em> (e.g. <a href="/search?q=module%3APlugin">module:Plugin</a>)</td> </tr> <tr> <td><em>distribution:</em> (e.g. <a href="/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td> </tr> <tr> <td><em>author:</em> (e.g. <a href="/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td> </tr> <tr> <td><em>version:</em> (e.g. <a href="/search?q=version%3A1.00">version:1.00</a>)</td> </tr> </tbody> </table> </div> </div> <div class="modal-footer"></div> </div> </div> </div> </body> </html>