File: Socket.html

package info (click to toggle)
perl-doc-html 5.26.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,400 kB
  • sloc: xml: 36; makefile: 7
file content (968 lines) | stat: -rw-r--r-- 69,518 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Socket - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>Socket</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 26.0 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                  <a href="#" id="page_index_toggle">Show page index</a> &bull;
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-modules-S.html">Core modules (S)</a> &gt;
      
    
    Socket
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>Socket</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><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><a href="#AF_INET%2c-AF_INET6%2c-AF_UNIX%2c-...">AF_INET, AF_INET6, AF_UNIX, ...</a><li><a href="#SOCK_STREAM%2c-SOCK_DGRAM%2c-SOCK_RAW%2c-...">SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ...</a><li><a href="#SOCK_NONBLOCK.-SOCK_CLOEXEC">SOCK_NONBLOCK. SOCK_CLOEXEC</a><li><a href="#SOL_SOCKET">SOL_SOCKET</a><li><a href="#SO_ACCEPTCONN%2c-SO_BROADCAST%2c-SO_ERROR%2c-...">SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, ...</a><li><a href="#IP_OPTIONS%2c-IP_TOS%2c-IP_TTL%2c-...">IP_OPTIONS, IP_TOS, IP_TTL, ...</a><li><a href="#IPTOS_LOWDELAY%2c-IPTOS_THROUGHPUT%2c-IPTOS_RELIABILITY%2c-...">IPTOS_LOWDELAY, IPTOS_THROUGHPUT, IPTOS_RELIABILITY, ...</a><li><a href="#MSG_BCAST%2c-MSG_OOB%2c-MSG_TRUNC%2c-...">MSG_BCAST, MSG_OOB, MSG_TRUNC, ...</a><li><a href="#SHUT_RD%2c-SHUT_RDWR%2c-SHUT_WR">SHUT_RD, SHUT_RDWR, SHUT_WR</a><li><a href="#INADDR_ANY%2c-INADDR_BROADCAST%2c-INADDR_LOOPBACK%2c-INADDR_NONE">INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE</a><li><a href="#IPPROTO_IP%2c-IPPROTO_IPV6%2c-IPPROTO_TCP%2c-...">IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, ...</a><li><a href="#TCP_CORK%2c-TCP_KEEPALIVE%2c-TCP_NODELAY%2c-...">TCP_CORK, TCP_KEEPALIVE, TCP_NODELAY, ...</a><li><a href="#IN6ADDR_ANY%2c-IN6ADDR_LOOPBACK">IN6ADDR_ANY, IN6ADDR_LOOPBACK</a><li><a href="#IPV6_ADD_MEMBERSHIP%2c-IPV6_MTU%2c-IPV6_V6ONLY%2c-...">IPV6_ADD_MEMBERSHIP, IPV6_MTU, IPV6_V6ONLY, ...</a></ul><li><a href="#STRUCTURE-MANIPULATORS">STRUCTURE MANIPULATORS</a><ul><li><a href="#%24family-%3d-sockaddr_family-%24sockaddr">$family = sockaddr_family $sockaddr</a><li><a href="#%24sockaddr-%3d-pack_sockaddr_in-%24port%2c-%24ip_address">$sockaddr = pack_sockaddr_in $port, $ip_address</a><li><a href="#(%24port%2c-%24ip_address)-%3d-unpack_sockaddr_in-%24sockaddr">($port, $ip_address) = unpack_sockaddr_in $sockaddr</a><li><a href="#%24sockaddr-%3d-sockaddr_in-%24port%2c-%24ip_address">$sockaddr = sockaddr_in $port, $ip_address</a><li><a href="#(%24port%2c-%24ip_address)-%3d-sockaddr_in-%24sockaddr">($port, $ip_address) = sockaddr_in $sockaddr</a><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><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><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><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><a href="#%24sockaddr-%3d-pack_sockaddr_un-%24path">$sockaddr = pack_sockaddr_un $path</a><li><a href="#(%24path)-%3d-unpack_sockaddr_un-%24sockaddr">($path) = unpack_sockaddr_un $sockaddr</a><li><a href="#%24sockaddr-%3d-sockaddr_un-%24path">$sockaddr = sockaddr_un $path</a><li><a href="#(%24path)-%3d-sockaddr_un-%24sockaddr">($path) = sockaddr_un $sockaddr</a><li><a href="#%24ip_mreq-%3d-pack_ip_mreq-%24multiaddr%2c-%24interface">$ip_mreq = pack_ip_mreq $multiaddr, $interface</a><li><a href="#(%24multiaddr%2c-%24interface)-%3d-unpack_ip_mreq-%24ip_mreq">($multiaddr, $interface) = unpack_ip_mreq $ip_mreq</a><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><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><a href="#%24ipv6_mreq-%3d-pack_ipv6_mreq-%24multiaddr6%2c-%24ifindex">$ipv6_mreq = pack_ipv6_mreq $multiaddr6, $ifindex</a><li><a href="#(%24multiaddr6%2c-%24ifindex)-%3d-unpack_ipv6_mreq-%24ipv6_mreq">($multiaddr6, $ifindex) = unpack_ipv6_mreq $ipv6_mreq</a></ul><li><a href="#FUNCTIONS">FUNCTIONS</a><ul><li><a href="#%24ip_address-%3d-inet_aton-%24string">$ip_address = inet_aton $string</a><li><a href="#%24string-%3d-inet_ntoa-%24ip_address">$string = inet_ntoa $ip_address</a><li><a href="#%24address-%3d-inet_pton-%24family%2c-%24string">$address = inet_pton $family, $string</a><li><a href="#%24string-%3d-inet_ntop-%24family%2c-%24address">$string = inet_ntop $family, $address</a><li><a href="#(%24err%2c-%40result)-%3d-getaddrinfo-%24host%2c-%24service%2c-%5b%24hints%5d">($err, @result) = getaddrinfo $host, $service, [$hints]</a><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></ul><li><a href="#getaddrinfo()-%2f-getnameinfo()-ERROR-CONSTANTS">getaddrinfo() / getnameinfo() ERROR CONSTANTS</a><li><a href="#EXAMPLES">EXAMPLES</a><ul><li><a href="#Lookup-for-connect()">Lookup for connect()</a><li><a href="#Making-a-human-readable-string-out-of-an-address">Making a human-readable string out of an address</a><li><a href="#Resolving-hostnames-into-IP-addresses">Resolving hostnames into IP addresses</a><li><a href="#Accessing-socket-options">Accessing socket options</a></ul><li><a href="#AUTHOR">AUTHOR</a></ul><a name="NAME"></a><h1>NAME</h1>
<p><code class="inline"><span class="w">Socket</span></code>
 - networking constants and support functions</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<p><code class="inline"><span class="w">Socket</span></code>
 a low-level module used by, among other things, the <a href="IO/Socket.html">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 class="inline"><span class="w">IO::Socket</span></code>
 or similar instead.</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(PF_INET SOCK_STREAM pack_sockaddr_in inet_aton)</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/socket.html">socket</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$socket</span><span class="cm">,</span> <span class="w">PF_INET</span><span class="cm">,</span> <span class="w">SOCK_STREAM</span><span class="cm">,</span> <span class="n">0</span><span class="s">)</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;socket: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$port</span> = <a class="l_k" href="functions/getservbyname.html">getservbyname</a> <span class="q">&quot;echo&quot;</span><span class="cm">,</span> <span class="q">&quot;tcp&quot;</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/connect.html">connect</a><span class="s">(</span><span class="i">$socket</span><span class="cm">,</span> <span class="i">pack_sockaddr_in</span><span class="s">(</span><span class="i">$port</span><span class="cm">,</span> <span class="i">inet_aton</span><span class="s">(</span><span class="q">&quot;localhost&quot;</span><span class="s">)</span><span class="s">)</span><span class="s">)</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;connect: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="i">$socket</span> <span class="q">&quot;Hello, world!\n&quot;</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="q">&lt;$socket&gt;</span><span class="sc">;</span></li></ol></pre><p>See also the <a href="#EXAMPLES">EXAMPLES</a> section.</p>
<a name="DESCRIPTION"></a><h1>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 class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span></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 class="inline"><span class="w">CR</span></code>
, <code class="inline"><span class="w">LF</span></code>
, and <code class="inline"><span class="w">CRLF</span></code>
, as well as <code class="inline"><span class="i">$CR</span></code>
, <code class="inline"><span class="i">$LF</span></code>
, and <code class="inline"><span class="i">$CRLF</span></code>
, which map
to <code class="inline">\<span class="n">015</span></code>
, <code class="inline">\<span class="n">012</span></code>
, and <code class="inline">\<span class="n">015</span>\<span class="n">012</span></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 class="inline"><span class="j">:</span><span class="w">crlf</span></code>
 export tag:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(:DEFAULT :crlf)</span><span class="sc">;</span></li><li></li><li> <span class="i">$sock</span><span class="i">-&gt;print</span><span class="s">(</span><span class="q">&quot;GET / HTTP/1.0$CRLF&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The entire getaddrinfo() subsystem can be exported using the tag <code class="inline"><span class="j">:</span><span class="w">addrinfo</span></code>
;
this exports the getaddrinfo() and getnameinfo() functions, and all the
<code class="inline"><span class="w">AI_</span>*</code>
, <code class="inline"><span class="w">NI_</span>*</code>
, <code class="inline"><span class="w">NIx_</span>*</code>
 and <code class="inline"><span class="w">EAI_</span>*</code>
 constants.</p>
<a name="CONSTANTS"></a><h1>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 class="inline">...</code>
 then this means there are likely more; the exact constants
provided will depend on the OS and headers found at compile-time.</p>
<a name="PF_INET%2c-PF_INET6%2c-PF_UNIX%2c-..."></a><h2>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 class="inline"><span class="w">SO_DOMAIN</span></code>
 or <code class="inline"><span class="w">SO_FAMILY</span></code>
 socket option.</p>
<a name="AF_INET%2c-AF_INET6%2c-AF_UNIX%2c-..."></a><h2>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>
<a name="SOCK_STREAM%2c-SOCK_DGRAM%2c-SOCK_RAW%2c-..."></a><h2>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 class="inline"><span class="w">SO_TYPE</span></code>
 socket option.</p>
<a name="SOCK_NONBLOCK.-SOCK_CLOEXEC"></a><h2>SOCK_NONBLOCK. SOCK_CLOEXEC</h2>
<p>Linux-specific shortcuts to specify the <code class="inline"><span class="w">O_NONBLOCK</span></code>
 and <code class="inline"><span class="w">FD_CLOEXEC</span></code>
 flags
during a <code class="inline"><a class="l_k" href="functions/socket.html">socket(2)</a></code> call.</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/socket.html">socket</a><span class="s">(</span> <a class="l_k" href="functions/my.html">my</a> <span class="i">$sockh</span><span class="cm">,</span> <span class="w">PF_INET</span><span class="cm">,</span> <span class="w">SOCK_DGRAM</span>|<span class="w">SOCK_NONBLOCK</span><span class="cm">,</span> <span class="n">0</span> <span class="s">)</span></li></ol></pre><a name="SOL_SOCKET"></a><h2>SOL_SOCKET</h2>
<p>Socket option level constant for setsockopt() and getsockopt().</p>
<a name="SO_ACCEPTCONN%2c-SO_BROADCAST%2c-SO_ERROR%2c-..."></a><h2>SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, ...</h2>
<p>Socket option name constants for setsockopt() and getsockopt() at the
<code class="inline"><span class="w">SOL_SOCKET</span></code>
 level.</p>
<a name="IP_OPTIONS%2c-IP_TOS%2c-IP_TTL%2c-..."></a><h2>IP_OPTIONS, IP_TOS, IP_TTL, ...</h2>
<p>Socket option name constants for IPv4 socket options at the <code class="inline"><span class="w">IPPROTO_IP</span></code>

level.</p>
<a name="IPTOS_LOWDELAY%2c-IPTOS_THROUGHPUT%2c-IPTOS_RELIABILITY%2c-..."></a><h2>IPTOS_LOWDELAY, IPTOS_THROUGHPUT, IPTOS_RELIABILITY, ...</h2>
<p>Socket option value constants for <code class="inline"><span class="w">IP_TOS</span></code>
 socket option.</p>
<a name="MSG_BCAST%2c-MSG_OOB%2c-MSG_TRUNC%2c-..."></a><h2>MSG_BCAST, MSG_OOB, MSG_TRUNC, ...</h2>
<p>Message flag constants for send() and recv().</p>
<a name="SHUT_RD%2c-SHUT_RDWR%2c-SHUT_WR"></a><h2>SHUT_RD, SHUT_RDWR, SHUT_WR</h2>
<p>Direction constants for shutdown().</p>
<a name="INADDR_ANY%2c-INADDR_BROADCAST%2c-INADDR_LOOPBACK%2c-INADDR_NONE"></a><h2>INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE</h2>
<p>Constants giving the special <code class="inline"><span class="w">AF_INET</span></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>
<a name="IPPROTO_IP%2c-IPPROTO_IPV6%2c-IPPROTO_TCP%2c-..."></a><h2>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 class="inline"><span class="w">SO_PROTOCOL</span></code>

socket option.</p>
<a name="TCP_CORK%2c-TCP_KEEPALIVE%2c-TCP_NODELAY%2c-..."></a><h2>TCP_CORK, TCP_KEEPALIVE, TCP_NODELAY, ...</h2>
<p>Socket option name constants for TCP socket options at the <code class="inline"><span class="w">IPPROTO_TCP</span></code>

level.</p>
<a name="IN6ADDR_ANY%2c-IN6ADDR_LOOPBACK"></a><h2>IN6ADDR_ANY, IN6ADDR_LOOPBACK</h2>
<p>Constants giving the special <code class="inline"><span class="w">AF_INET6</span></code>
 addresses for wildcard and local
loopback.</p>
<p>Normally equivalent to inet_pton(AF_INET6, "::") and
inet_pton(AF_INET6, "::1") respectively.</p>
<a name="IPV6_ADD_MEMBERSHIP%2c-IPV6_MTU%2c-IPV6_V6ONLY%2c-..."></a><h2>IPV6_ADD_MEMBERSHIP, IPV6_MTU, IPV6_V6ONLY, ...</h2>
<p>Socket option name constants for IPv6 socket options at the <code class="inline"><span class="w">IPPROTO_IPV6</span></code>

level.</p>
<a name="STRUCTURE-MANIPULATORS"></a><h1>STRUCTURE MANIPULATORS</h1>
<p>The following functions convert between lists of Perl values and packed binary
strings representing structures.</p>
<a name="%24family-%3d-sockaddr_family-%24sockaddr"></a><h2>$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 class="inline"><span class="w">AF_</span>*</code>
 constants, such as <code class="inline"><span class="w">AF_INET</span></code>
 for a <code class="inline"><span class="w">sockaddr_in</span></code>
 addresses or
<code class="inline"><span class="w">AF_UNIX</span></code>
 for a <code class="inline"><span class="w">sockaddr_un</span></code>
. It can be used to figure out what unpack to
use for a sockaddr of unknown type.</p>
<a name="%24sockaddr-%3d-pack_sockaddr_in-%24port%2c-%24ip_address"></a><h2>$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 class="inline"><span class="w">sockaddr_in</span></code>
 structure with those
arguments packed in and <code class="inline"><span class="w">AF_INET</span></code>
 filled in. For Internet domain sockets,
this structure is normally what you need for the arguments in bind(),
connect(), and send().</p>
<a name="(%24port%2c-%24ip_address)-%3d-unpack_sockaddr_in-%24sockaddr"></a><h2>($port, $ip_address) = unpack_sockaddr_in $sockaddr</h2>
<p>Takes a <code class="inline"><span class="w">sockaddr_in</span></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 class="inline"><span class="w">AF_INET</span></code>
 address.</p>
<p>In scalar context will return just the IP address.</p>
<a name="%24sockaddr-%3d-sockaddr_in-%24port%2c-%24ip_address"></a><h2>$sockaddr = sockaddr_in $port, $ip_address</h2>
<a name="(%24port%2c-%24ip_address)-%3d-sockaddr_in-%24sockaddr"></a><h2>($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 class="inline"><span class="w">sockaddr_in</span></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>
<a name="%24sockaddr-%3d-pack_sockaddr_in6-%24port%2c-%24ip6_address%2c-%5b%24scope_id%2c-%5b%24flowinfo%5d%5d"></a><h2>$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 class="inline"><span class="w">sockaddr_in6</span></code>
 structure with those arguments packed in
and <code class="inline"><span class="w">AF_INET6</span></code>
 filled in. IPv6 equivalent of pack_sockaddr_in().</p>
<a name="(%24port%2c-%24ip6_address%2c-%24scope_id%2c-%24flowinfo)-%3d-unpack_sockaddr_in6-%24sockaddr"></a><h2>($port, $ip6_address, $scope_id, $flowinfo) = unpack_sockaddr_in6 $sockaddr</h2>
<p>Takes a <code class="inline"><span class="w">sockaddr_in6</span></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 class="inline"><span class="w">AF_INET6</span></code>

address.</p>
<p>In scalar context will return just the IP address.</p>
<a name="%24sockaddr-%3d-sockaddr_in6-%24port%2c-%24ip6_address%2c-%5b%24scope_id%2c-%5b%24flowinfo%5d%5d"></a><h2>$sockaddr = sockaddr_in6 $port, $ip6_address, [$scope_id, [$flowinfo]]</h2>
<a name="(%24port%2c-%24ip6_address%2c-%24scope_id%2c-%24flowinfo)-%3d-sockaddr_in6-%24sockaddr"></a><h2>($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>
<a name="%24sockaddr-%3d-pack_sockaddr_un-%24path"></a><h2>$sockaddr = pack_sockaddr_un $path</h2>
<p>Takes one argument, a pathname. Returns the <code class="inline"><span class="w">sockaddr_un</span></code>
 structure with that
path packed in with <code class="inline"><span class="w">AF_UNIX</span></code>
 filled in. For <code class="inline"><span class="w">PF_UNIX</span></code>
 sockets, this
structure is normally what you need for the arguments in bind(), connect(),
and send().</p>
<a name="(%24path)-%3d-unpack_sockaddr_un-%24sockaddr"></a><h2>($path) = unpack_sockaddr_un $sockaddr</h2>
<p>Takes a <code class="inline"><span class="w">sockaddr_un</span></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 class="inline"><span class="w">AF_UNIX</span></code>
 address.</p>
<a name="%24sockaddr-%3d-sockaddr_un-%24path"></a><h2>$sockaddr = sockaddr_un $path</h2>
<a name="(%24path)-%3d-sockaddr_un-%24sockaddr"></a><h2>($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 class="inline"><span class="w">sockaddr_un</span></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 &lt;<i>sys/un.h</i>&gt;.</p>
<a name="%24ip_mreq-%3d-pack_ip_mreq-%24multiaddr%2c-%24interface"></a><h2>$ip_mreq = pack_ip_mreq $multiaddr, $interface</h2>
<p>Takes an IPv4 multicast address and optionally an interface address (or
<code class="inline"><span class="w">INADDR_ANY</span></code>
). Returns the <code class="inline"><span class="w">ip_mreq</span></code>
 structure with those arguments packed
in. Suitable for use with the <code class="inline"><span class="w">IP_ADD_MEMBERSHIP</span></code>
 and <code class="inline"><span class="w">IP_DROP_MEMBERSHIP</span></code>

sockopts.</p>
<a name="(%24multiaddr%2c-%24interface)-%3d-unpack_ip_mreq-%24ip_mreq"></a><h2>($multiaddr, $interface) = unpack_ip_mreq $ip_mreq</h2>
<p>Takes an <code class="inline"><span class="w">ip_mreq</span></code>
 structure. Returns a list of two elements; the IPv4
multicast address and interface address.</p>
<a name="%24ip_mreq_source-%3d-pack_ip_mreq_source-%24multiaddr%2c-%24source%2c-%24interface"></a><h2>$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 class="inline"><span class="w">INADDR_ANY</span></code>
). Returns the <code class="inline"><span class="w">ip_mreq_source</span></code>
 structure with those
arguments packed in. Suitable for use with the <code class="inline"><span class="w">IP_ADD_SOURCE_MEMBERSHIP</span></code>

and <code class="inline"><span class="w">IP_DROP_SOURCE_MEMBERSHIP</span></code>
 sockopts.</p>
<a name="(%24multiaddr%2c-%24source%2c-%24interface)-%3d-unpack_ip_mreq_source-%24ip_mreq"></a><h2>($multiaddr, $source, $interface) = unpack_ip_mreq_source $ip_mreq</h2>
<p>Takes an <code class="inline"><span class="w">ip_mreq_source</span></code>
 structure. Returns a list of three elements; the
IPv4 multicast address, source address and interface address.</p>
<a name="%24ipv6_mreq-%3d-pack_ipv6_mreq-%24multiaddr6%2c-%24ifindex"></a><h2>$ipv6_mreq = pack_ipv6_mreq $multiaddr6, $ifindex</h2>
<p>Takes an IPv6 multicast address and an interface number. Returns the
<code class="inline"><span class="w">ipv6_mreq</span></code>
 structure with those arguments packed in. Suitable for use with
the <code class="inline"><span class="w">IPV6_ADD_MEMBERSHIP</span></code>
 and <code class="inline"><span class="w">IPV6_DROP_MEMBERSHIP</span></code>
 sockopts.</p>
<a name="(%24multiaddr6%2c-%24ifindex)-%3d-unpack_ipv6_mreq-%24ipv6_mreq"></a><h2>($multiaddr6, $ifindex) = unpack_ipv6_mreq $ipv6_mreq</h2>
<p>Takes an <code class="inline"><span class="w">ipv6_mreq</span></code>
 structure. Returns a list of two elements; the IPv6
address and an interface number.</p>
<a name="FUNCTIONS"></a><h1>FUNCTIONS</h1>
<a name="%24ip_address-%3d-inet_aton-%24string"></a><h2>$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 class="inline"><a class="l_k" href="functions/undef.html">undef</a></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>
<a name="%24string-%3d-inet_ntoa-%24ip_address"></a><h2>$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 class="inline"><span class="w">d</span>.<span class="w">d</span>.<span class="w">d</span>.<span class="w">d</span></code>
 where the <code class="inline"><span class="w">d</span></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>
<a name="%24address-%3d-inet_pton-%24family%2c-%24string"></a><h2>$address = inet_pton $family, $string</h2>
<p>Takes an address family (such as <code class="inline"><span class="w">AF_INET</span></code>
 or <code class="inline"><span class="w">AF_INET6</span></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>
<a name="%24string-%3d-inet_ntop-%24family%2c-%24address"></a><h2>$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 class="inline"><span class="w">d</span>.<span class="w">d</span>.<span class="w">d</span>.<span class="w">d</span></code>
 form for <code class="inline"><span class="w">AF_INET</span></code>
 or <code class="inline"><span class="j">hhhh:</span><span class="w">hhhh::hhhh</span></code>
 form for <code class="inline"><span class="w">AF_INET6</span></code>
.</p>
<p>See also getnameinfo() for a more powerful and flexible function to turn
socket addresses into human-readable textual representations.</p>
<a name="(%24err%2c-%40result)-%3d-getaddrinfo-%24host%2c-%24service%2c-%5b%24hints%5d"></a><h2>($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 class="inline"><span class="w">AI_PASSIVE</span></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>
<ul>
<li><a name="flags-%3d%3e-INT"></a><b>flags =&gt; INT</b>
<p>A bitfield containing <code class="inline"><span class="w">AI_</span>*</code>
 constants; see below.</p>
</li>
<li><a name="family-%3d%3e-INT"></a><b>family =&gt; INT</b>
<p>Restrict to only generating addresses in this address family</p>
</li>
<li><a name="socktype-%3d%3e-INT"></a><b>socktype =&gt; INT</b>
<p>Restrict to only generating addresses of this socket type</p>
</li>
<li><a name="protocol-%3d%3e-INT"></a><b>protocol =&gt; INT</b>
<p>Restrict to only generating addresses for this protocol</p>
</li>
</ul>
<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 class="inline"><span class="w">EI_</span>*</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>
<ul>
<li><a name="family-%3d%3e-INT"></a><b>family =&gt; INT</b>
<p>The address family (e.g. <code class="inline"><span class="w">AF_INET</span></code>
)</p>
</li>
<li><a name="socktype-%3d%3e-INT"></a><b>socktype =&gt; INT</b>
<p>The socket type (e.g. <code class="inline"><span class="w">SOCK_STREAM</span></code>
)</p>
</li>
<li><a name="protocol-%3d%3e-INT"></a><b>protocol =&gt; INT</b>
<p>The protocol (e.g. <code class="inline"><span class="w">IPPROTO_TCP</span></code>
)</p>
</li>
<li><a name="addr-%3d%3e-STRING"></a><b>addr =&gt; STRING</b>
<p>The address in a packed string (such as would be returned by
pack_sockaddr_in())</p>
</li>
<li><a name="canonname-%3d%3e-STRING"></a><b>canonname =&gt; STRING</b>
<p>The canonical name for the host if the <code class="inline"><span class="w">AI_CANONNAME</span></code>
 flag was provided, or
<code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> otherwise. This field will only be present on the first returned
address.</p>
</li>
</ul>
<p>The following flag constants are recognised in the $hints hash. Other flag
constants may exist as provided by the OS.</p>
<ul>
<li><a name="AI_PASSIVE"></a><b>AI_PASSIVE</b>
<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>
</li>
<li><a name="AI_CANONNAME"></a><b>AI_CANONNAME</b>
<p>Indicates that the caller wishes the canonical hostname (<code class="inline"><span class="w">canonname</span></code>
) field
of the result to be filled in.</p>
</li>
<li><a name="AI_NUMERICHOST"></a><b>AI_NUMERICHOST</b>
<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>
</li>
</ul>
<a name="(%24err%2c-%24hostname%2c-%24servicename)-%3d-getnameinfo-%24sockaddr%2c-%5b%24flags%2c-%5b%24xflags%5d%5d"></a><h2>($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 class="inline"><span class="w">addr</span></code>
 field), returns the hostname and
symbolic service name it represents. $flags may be a bitmask of <code class="inline"><span class="w">NI_</span>*</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 class="inline"><span class="w">EI_</span>*</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>
<ul>
<li><a name="NI_NUMERICHOST"></a><b>NI_NUMERICHOST</b>
<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>
</li>
<li><a name="NI_NUMERICSERV"></a><b>NI_NUMERICSERV</b>
<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>
</li>
<li><a name="NI_NAMEREQD"></a><b>NI_NAMEREQD</b>
<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>
</li>
<li><a name="NI_DGRAM"></a><b>NI_DGRAM</b>
<p>Indicates that the socket address relates to a <code class="inline"><span class="w">SOCK_DGRAM</span></code>
 socket, for the
services whose name differs between TCP and UDP protocols.</p>
</li>
</ul>
<p>The following constants may be supplied as $xflags.</p>
<ul>
<li><a name="NIx_NOHOST"></a><b>NIx_NOHOST</b>
<p>Indicates that the caller is not interested in the hostname of the result, so
it does not have to be converted. <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> will be returned as the hostname.</p>
</li>
<li><a name="NIx_NOSERV"></a><b>NIx_NOSERV</b>
<p>Indicates that the caller is not interested in the service name of the result,
so it does not have to be converted. <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> will be returned as the service
name.</p>
</li>
</ul>
<a name="getaddrinfo()-%2f-getnameinfo()-ERROR-CONSTANTS"></a><h1>getaddrinfo() / getnameinfo() ERROR CONSTANTS</h1>
<p>The following constants may be returned by getaddrinfo() or getnameinfo().
Others may be provided by the OS.</p>
<ul>
<li><a name="EAI_AGAIN"></a><b>EAI_AGAIN</b>
<p>A temporary failure occurred during name resolution. The operation may be
successful if it is retried later.</p>
</li>
<li><a name="EAI_BADFLAGS"></a><b>EAI_BADFLAGS</b>
<p>The value of the <code class="inline"><span class="w">flags</span></code>
 hint to getaddrinfo(), or the $flags parameter to
getnameinfo() contains unrecognised flags.</p>
</li>
<li><a name="EAI_FAMILY"></a><b>EAI_FAMILY</b>
<p>The <code class="inline"><span class="w">family</span></code>
 hint to getaddrinfo(), or the family of the socket address
passed to getnameinfo() is not supported.</p>
</li>
<li><a name="EAI_NODATA"></a><b>EAI_NODATA</b>
<p>The host name supplied to getaddrinfo() did not provide any usable address
data.</p>
</li>
<li><a name="EAI_NONAME"></a><b>EAI_NONAME</b>
<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 class="inline"><span class="w">NI_NAMEREQD</span></code>
 flag was supplied.</p>
</li>
<li><a name="EAI_SERVICE"></a><b>EAI_SERVICE</b>
<p>The service name supplied to getaddrinfo() is not available for the socket
type given in the $hints.</p>
</li>
</ul>
<a name="EXAMPLES"></a><h1>EXAMPLES</h1>
<a name="Lookup-for-connect()"></a><h2>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 class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">IO::Socket</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(SOCK_STREAM getaddrinfo)</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hints</span> = <span class="s">(</span><span class="w">socktype</span> <span class="cm">=&gt;</span> <span class="w">SOCK_STREAM</span><span class="s">)</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$err</span><span class="cm">,</span> <span class="i">@res</span><span class="s">)</span> = <span class="i">getaddrinfo</span><span class="s">(</span><span class="q">&quot;localhost&quot;</span><span class="cm">,</span> <span class="q">&quot;echo&quot;</span><span class="cm">,</span> \<span class="i">%hints</span><span class="s">)</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot getaddrinfo - $err&quot;</span> <a class="l_k" href="functions/if.html">if</a> <span class="i">$err</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$sock</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/foreach.html">foreach</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$ai</span> <span class="s">(</span><span class="i">@res</span><span class="s">)</span> <span class="s">{</span></li><li>     <a class="l_k" href="functions/my.html">my</a> <span class="i">$candidate</span> = <span class="w">IO::Socket</span><span class="w">-&gt;new</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>     <span class="i">$candidate</span><span class="i">-&gt;socket</span><span class="s">(</span><span class="i">$ai</span>-&gt;{<span class="w">family</span>}<span class="cm">,</span> <span class="i">$ai</span>-&gt;{<span class="w">socktype</span>}<span class="cm">,</span> <span class="i">$ai</span>-&gt;{<span class="w">protocol</span>}<span class="s">)</span></li><li>         <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/next.html">next</a><span class="sc">;</span></li><li></li><li>     <span class="i">$candidate</span><span class="i">-&gt;connect</span><span class="s">(</span><span class="i">$ai</span>-&gt;{<span class="w">addr</span>}<span class="s">)</span></li><li>         <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/next.html">next</a><span class="sc">;</span></li><li></li><li>     <span class="i">$sock</span> = <span class="i">$candidate</span><span class="sc">;</span></li><li>     <a class="l_k" href="functions/last.html">last</a><span class="sc">;</span></li><li> <span class="s">}</span></li><li></li><li> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot connect to localhost:echo&quot;</span> <a class="l_k" href="functions/unless.html">unless</a> <span class="i">$sock</span><span class="sc">;</span></li><li></li><li> <span class="i">$sock</span><span class="i">-&gt;print</span><span class="s">(</span><span class="q">&quot;Hello, world!\n&quot;</span><span class="s">)</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="q">&lt;$sock&gt;</span><span class="sc">;</span></li></ol></pre><p>Because a list of potential candidates is returned, the <code class="inline">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="IO/Socket/IP.html">IO::Socket::IP</a>.</p>
<a name="Making-a-human-readable-string-out-of-an-address"></a><h2>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 class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">IO::Socket::IP</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(getnameinfo)</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$server</span> = <span class="w">IO::Socket::IP</span><span class="w">-&gt;new</span><span class="s">(</span><span class="w">LocalPort</span> <span class="cm">=&gt;</span> <span class="n">12345</span><span class="cm">,</span> <span class="w">Listen</span> <span class="cm">=&gt;</span> <span class="n">1</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a></li><li>     <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot listen - $@&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$socket</span> = <span class="i">$server</span><span class="i">-&gt;accept</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;accept: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$err</span><span class="cm">,</span> <span class="i">$hostname</span><span class="cm">,</span> <span class="i">$servicename</span><span class="s">)</span> = <span class="i">getnameinfo</span><span class="s">(</span><span class="i">$socket</span><span class="i">-&gt;peername</span><span class="s">)</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot getnameinfo - $err&quot;</span> <a class="l_k" href="functions/if.html">if</a> <span class="i">$err</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;The peer is connected from $hostname\n&quot;</span><span class="sc">;</span></li></ol></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 class="inline"><span class="w">NIx_NOSERV</span></code>
 flag.</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(getnameinfo NIx_NOSERV)</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$err</span><span class="cm">,</span> <span class="i">$hostname</span><span class="s">)</span> = <span class="i">getnameinfo</span><span class="s">(</span><span class="i">$socket</span><span class="i">-&gt;peername</span><span class="cm">,</span> <span class="n">0</span><span class="cm">,</span> <span class="w">NIx_NOSERV</span><span class="s">)</span><span class="sc">;</span></li></ol></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="IO/Socket/IP.html">IO::Socket::IP</a>.</p>
<a name="Resolving-hostnames-into-IP-addresses"></a><h2>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 class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(:addrinfo SOCK_RAW)</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$err</span><span class="cm">,</span> <span class="i">@res</span><span class="s">)</span> = <span class="i">getaddrinfo</span><span class="s">(</span><span class="i">$hostname</span><span class="cm">,</span> <span class="q">&quot;&quot;</span><span class="cm">,</span> <span class="s">{</span><span class="w">socktype</span> <span class="cm">=&gt;</span> <span class="w">SOCK_RAW</span><span class="s">}</span><span class="s">)</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot getaddrinfo - $err&quot;</span> <a class="l_k" href="functions/if.html">if</a> <span class="i">$err</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/while.html">while</a><span class="s">(</span> <a class="l_k" href="functions/my.html">my</a> <span class="i">$ai</span> = <a class="l_k" href="functions/shift.html">shift</a> <span class="i">@res</span> <span class="s">)</span> <span class="s">{</span></li><li>     <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$err</span><span class="cm">,</span> <span class="i">$ipaddr</span><span class="s">)</span> = <span class="i">getnameinfo</span><span class="s">(</span><span class="i">$ai</span>-&gt;{<span class="w">addr</span>}<span class="cm">,</span> <span class="w">NI_NUMERICHOST</span><span class="cm">,</span> <span class="w">NIx_NOSERV</span><span class="s">)</span><span class="sc">;</span></li><li>     <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot getnameinfo - $err&quot;</span> <a class="l_k" href="functions/if.html">if</a> <span class="i">$err</span><span class="sc">;</span></li><li></li><li>     <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;$ipaddr\n&quot;</span><span class="sc">;</span></li><li> <span class="s">}</span></li></ol></pre><p>The <code class="inline"><span class="w">socktype</span></code>
 hint to getaddrinfo() filters the results to only include one
socket type and protocol. Without this most OSes return three combinations,
for <code class="inline"><span class="w">SOCK_STREAM</span></code>
, <code class="inline"><span class="w">SOCK_DGRAM</span></code>
 and <code class="inline"><span class="w">SOCK_RAW</span></code>
, resulting in triplicate
output of addresses. The <code class="inline"><span class="w">NI_NUMERICHOST</span></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>
<a name="Accessing-socket-options"></a><h2>Accessing socket options</h2>
<p>The many <code class="inline"><span class="w">SO_</span>*</code>
 and other constants provide the socket option names for
getsockopt() and setsockopt().</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">IO::Socket::INET</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(SOL_SOCKET SO_RCVBUF IPPROTO_IP IP_TTL)</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$socket</span> = <span class="w">IO::Socket::INET</span><span class="w">-&gt;new</span><span class="s">(</span><span class="w">LocalPort</span> <span class="cm">=&gt;</span> <span class="n">0</span><span class="cm">,</span> <span class="w">Proto</span> <span class="cm">=&gt;</span> <span class="q">&#39;udp&#39;</span><span class="s">)</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot create socket: $@&quot;</span><span class="sc">;</span></li><li></li><li> <span class="i">$socket</span><span class="i">-&gt;setsockopt</span><span class="s">(</span><span class="w">SOL_SOCKET</span><span class="cm">,</span> <span class="w">SO_RCVBUF</span><span class="cm">,</span> <span class="n">64</span>*<span class="n">1024</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a></li><li>     <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;setsockopt: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Receive buffer is &quot;</span><span class="cm">,</span> <span class="i">$socket</span><span class="i">-&gt;getsockopt</span><span class="s">(</span><span class="w">SOL_SOCKET</span><span class="cm">,</span> <span class="w">SO_RCVBUF</span><span class="s">)</span><span class="cm">,</span></li><li>     <span class="q">&quot; bytes\n&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;IP TTL is &quot;</span><span class="cm">,</span> <span class="i">$socket</span><span class="i">-&gt;getsockopt</span><span class="s">(</span><span class="w">IPPROTO_IP</span><span class="cm">,</span> <span class="w">IP_TTL</span><span class="s">)</span><span class="cm">,</span> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li></ol></pre><p>As a convenience, <a href="IO/Socket.html">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>
<a name="AUTHOR"></a><h1>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 &lt;leonerd@leonerd.org.uk&gt;</p>




  <div id="page_index" class="hud_container">
    <div id="page_index_header" class="hud_header">
      <div id="page_index_close" class="hud_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title" class="hud_title"><span class="hud_span_top">Page index</span></div>
      <div id="page_index_topright" class="hud_topright"></div>
    </div>
    <div id="page_index_content" class="hud_content">
      <ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><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><a href="#AF_INET%2c-AF_INET6%2c-AF_UNIX%2c-...">AF_INET, AF_INET6, AF_UNIX, ...</a><li><a href="#SOCK_STREAM%2c-SOCK_DGRAM%2c-SOCK_RAW%2c-...">SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ...</a><li><a href="#SOCK_NONBLOCK.-SOCK_CLOEXEC">SOCK_NONBLOCK. SOCK_CLOEXEC</a><li><a href="#SOL_SOCKET">SOL_SOCKET</a><li><a href="#SO_ACCEPTCONN%2c-SO_BROADCAST%2c-SO_ERROR%2c-...">SO_ACCEPTCONN, SO_BROADCAST, SO_ERROR, ...</a><li><a href="#IP_OPTIONS%2c-IP_TOS%2c-IP_TTL%2c-...">IP_OPTIONS, IP_TOS, IP_TTL, ...</a><li><a href="#IPTOS_LOWDELAY%2c-IPTOS_THROUGHPUT%2c-IPTOS_RELIABILITY%2c-...">IPTOS_LOWDELAY, IPTOS_THROUGHPUT, IPTOS_RELIABILITY, ...</a><li><a href="#MSG_BCAST%2c-MSG_OOB%2c-MSG_TRUNC%2c-...">MSG_BCAST, MSG_OOB, MSG_TRUNC, ...</a><li><a href="#SHUT_RD%2c-SHUT_RDWR%2c-SHUT_WR">SHUT_RD, SHUT_RDWR, SHUT_WR</a><li><a href="#INADDR_ANY%2c-INADDR_BROADCAST%2c-INADDR_LOOPBACK%2c-INADDR_NONE">INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE</a><li><a href="#IPPROTO_IP%2c-IPPROTO_IPV6%2c-IPPROTO_TCP%2c-...">IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, ...</a><li><a href="#TCP_CORK%2c-TCP_KEEPALIVE%2c-TCP_NODELAY%2c-...">TCP_CORK, TCP_KEEPALIVE, TCP_NODELAY, ...</a><li><a href="#IN6ADDR_ANY%2c-IN6ADDR_LOOPBACK">IN6ADDR_ANY, IN6ADDR_LOOPBACK</a><li><a href="#IPV6_ADD_MEMBERSHIP%2c-IPV6_MTU%2c-IPV6_V6ONLY%2c-...">IPV6_ADD_MEMBERSHIP, IPV6_MTU, IPV6_V6ONLY, ...</a></ul><li><a href="#STRUCTURE-MANIPULATORS">STRUCTURE MANIPULATORS</a><ul><li><a href="#%24family-%3d-sockaddr_family-%24sockaddr">$family = sockaddr_family $sockaddr</a><li><a href="#%24sockaddr-%3d-pack_sockaddr_in-%24port%2c-%24ip_address">$sockaddr = pack_sockaddr_in $port, $ip_address</a><li><a href="#(%24port%2c-%24ip_address)-%3d-unpack_sockaddr_in-%24sockaddr">($port, $ip_address) = unpack_sockaddr_in $sockaddr</a><li><a href="#%24sockaddr-%3d-sockaddr_in-%24port%2c-%24ip_address">$sockaddr = sockaddr_in $port, $ip_address</a><li><a href="#(%24port%2c-%24ip_address)-%3d-sockaddr_in-%24sockaddr">($port, $ip_address) = sockaddr_in $sockaddr</a><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><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><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><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><a href="#%24sockaddr-%3d-pack_sockaddr_un-%24path">$sockaddr = pack_sockaddr_un $path</a><li><a href="#(%24path)-%3d-unpack_sockaddr_un-%24sockaddr">($path) = unpack_sockaddr_un $sockaddr</a><li><a href="#%24sockaddr-%3d-sockaddr_un-%24path">$sockaddr = sockaddr_un $path</a><li><a href="#(%24path)-%3d-sockaddr_un-%24sockaddr">($path) = sockaddr_un $sockaddr</a><li><a href="#%24ip_mreq-%3d-pack_ip_mreq-%24multiaddr%2c-%24interface">$ip_mreq = pack_ip_mreq $multiaddr, $interface</a><li><a href="#(%24multiaddr%2c-%24interface)-%3d-unpack_ip_mreq-%24ip_mreq">($multiaddr, $interface) = unpack_ip_mreq $ip_mreq</a><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><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><a href="#%24ipv6_mreq-%3d-pack_ipv6_mreq-%24multiaddr6%2c-%24ifindex">$ipv6_mreq = pack_ipv6_mreq $multiaddr6, $ifindex</a><li><a href="#(%24multiaddr6%2c-%24ifindex)-%3d-unpack_ipv6_mreq-%24ipv6_mreq">($multiaddr6, $ifindex) = unpack_ipv6_mreq $ipv6_mreq</a></ul><li><a href="#FUNCTIONS">FUNCTIONS</a><ul><li><a href="#%24ip_address-%3d-inet_aton-%24string">$ip_address = inet_aton $string</a><li><a href="#%24string-%3d-inet_ntoa-%24ip_address">$string = inet_ntoa $ip_address</a><li><a href="#%24address-%3d-inet_pton-%24family%2c-%24string">$address = inet_pton $family, $string</a><li><a href="#%24string-%3d-inet_ntop-%24family%2c-%24address">$string = inet_ntop $family, $address</a><li><a href="#(%24err%2c-%40result)-%3d-getaddrinfo-%24host%2c-%24service%2c-%5b%24hints%5d">($err, @result) = getaddrinfo $host, $service, [$hints]</a><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></ul><li><a href="#getaddrinfo()-%2f-getnameinfo()-ERROR-CONSTANTS">getaddrinfo() / getnameinfo() ERROR CONSTANTS</a><li><a href="#EXAMPLES">EXAMPLES</a><ul><li><a href="#Lookup-for-connect()">Lookup for connect()</a><li><a href="#Making-a-human-readable-string-out-of-an-address">Making a human-readable string out of an address</a><li><a href="#Resolving-hostnames-into-IP-addresses">Resolving hostnames into IP addresses</a><li><a href="#Accessing-socket-options">Accessing socket options</a></ul><li><a href="#AUTHOR">AUTHOR</a></ul>
    </div>
    <div id="page_index_footer" class="hud_footer">
      <div id="page_index_bottomleft" class="hud_bottomleft"></div>
      <div id="page_index_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
      <div id="page_index_resize" class="hud_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
    <div id="footer">
      <div id="footer_content">
        <div id="footer_strapline">
          perldoc.perl.org - Official documentation for the Perl programming language
        </div>
        <div id="footer_links">
          <div id="address">
            <p class="name">Contact details</p>
            <p class="address">
	      Site maintained by <a href="mailto:jj@jonallen.info">Jon Allen (JJ)</a><br>
	    </p>
            <p class="contact">
              Documentation maintained by the <a href="http://lists.cpan.org/showlist.cgi?name=perl5-porters">Perl 5 Porters</a>
            </p>
          </div>
          <ul class="f1">
            <li>Manual
              <ul class="f2">
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">Changes</a>
              </ul>
            <li>Reference
              <ul class="f2">
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Variables</a>
              </ul>
            <li>Modules
              <ul class="f2">
                <li><a href="index-modules-A.html">Modules</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
              </ul>
            <li>Misc
              <ul class="f2">
                <li><a href="index-licence.html">License</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platforms</a>
              </ul>          </ul>
          <div class="clear"></div>
        </div>
      </div>
      <div id="footer_end">
      </div>
    </div>
      
    </div>
      <script language="JavaScript" type="text/javascript" src="static/exploreperl.js"></script>
      <script language="JavaScript" src="static/combined-20100403.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 'Socket';
  perldoc.pageAddress = 'Socket.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>