~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to lib/kernel/src/inet.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
%% ``The contents of this file are subject to the Erlang Public License,
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
 
5
%% 
 
6
%% The contents of this file are subject to the Erlang Public License,
2
7
%% Version 1.1, (the "License"); you may not use this file except in
3
8
%% compliance with the License. You should have received a copy of the
4
9
%% Erlang Public License along with this software. If not, it can be
5
 
%% retrieved via the world wide web at http://www.erlang.org/.
 
10
%% retrieved online at http://www.erlang.org/.
6
11
%% 
7
12
%% Software distributed under the License is distributed on an "AS IS"
8
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
14
%% the License for the specific language governing rights and limitations
10
15
%% under the License.
11
16
%% 
12
 
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
 
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
 
%% AB. All Rights Reserved.''
15
 
%% 
16
 
%%     $Id$
 
17
%% %CopyrightEnd%
17
18
%%
18
19
-module(inet).
19
20
 
100
101
      {'active',          bool() | 'once'} |
101
102
      {'packet',        
102
103
       0 | 1 | 2 | 4 | 'raw' | 'sunrm' |  'asn1' |
103
 
       'cdr' | 'fcgi' | 'line' | 'tpkt' | 'http' | 'httph'} |
 
104
       'cdr' | 'fcgi' | 'line' | 'tpkt' | 'http' | 'httph' | 'http_bin' | 'httph_bin' } |
104
105
      {'mode',           list() | binary()} |
105
106
      {'port',           'port', 'term'} |
106
107
      {'exit_on_close',   bool()} |
108
109
      {'high_watermark',  non_neg_integer()} |
109
110
      {'bit8',            'clear' | 'set' | 'on' | 'off'} |
110
111
      {'send_timeout',    non_neg_integer() | 'infinity'} |
 
112
      {'send_timeout_close', bool()} |
111
113
      {'delay_send',      bool()} |
112
114
      {'packet_size',     non_neg_integer()} |
113
115
      {'read_packets',    non_neg_integer()} |
138
140
      'add_membership' | 'drop_membership' | 
139
141
      'header' | 'buffer' | 'active' | 'packet' | 'mode' | 'port' | 
140
142
      'exit_on_close' | 'low_watermark' | 'high_watermark' | 'bit8' | 
141
 
      'send_timeout' | 'delay_send' | 'packet_size' | 'read_packets' | 
 
143
      'send_timeout' | 'send_timeout_close' |
 
144
      'delay_send' | 'packet_size' | 'read_packets' | 
142
145
      %% SCTP options
143
146
      {'sctp_status',                #sctp_status{}} |
144
147
      'sctp_get_peer_addr_info' |
538
541
     buffer, header, active, packet, deliver, mode,
539
542
     multicast_if, multicast_ttl, multicast_loop,
540
543
     exit_on_close, high_watermark, low_watermark,
541
 
     bit8, send_timeout
 
544
     bit8, send_timeout, send_timeout_close
542
545
    ].
543
546
 
544
547
%% Return a list of statistics options
556
559
    [tos, priority, reuseaddr, keepalive, linger, sndbuf, recbuf, nodelay,
557
560
     header, active, packet, packet_size, buffer, mode, deliver,
558
561
     exit_on_close, high_watermark, low_watermark, bit8, send_timeout,
559
 
     delay_send,raw].
 
562
     send_timeout_close, delay_send,raw].
560
563
    
561
564
connect_options(Opts, Family) ->
562
565
    BaseOpts = 
612
615
    [tos, priority, reuseaddr, keepalive, linger, sndbuf, recbuf, nodelay,
613
616
     header, active, packet, buffer, mode, deliver, backlog,
614
617
     exit_on_close, high_watermark, low_watermark, bit8, send_timeout,
615
 
     delay_send, packet_size,raw].
 
618
     send_timeout_close, delay_send, packet_size,raw].
616
619
 
617
620
listen_options(Opts, Family) ->
618
621
    BaseOpts = 
814
817
        ?ip(A,B,C,D) ->
815
818
            if
816
819
                Fam =:= inet -> {ok,[IP]};
817
 
                true -> {error,nxdomain}
 
820
                true -> {error,eafnosupport}
818
821
            end;
819
 
        true ->         {error,einval}
 
822
        true -> {error,einval}
820
823
    end;
821
824
getaddrs_tm({A,B,C,D,E,F,G,H} = IP, Fam, _) ->
822
825
    %% Only "syntactic" validation; we assume that the address was
825
828
        ?ip6(A,B,C,D,E,F,G,H) ->
826
829
            if
827
830
                Fam =:= inet6 -> {ok,[IP]};
828
 
                true -> {error,nxdomain}
 
831
                true -> {error,eafnosupport}
829
832
            end;
830
833
        true -> {error,einval}
831
834
    end;
862
865
        Result -> Result
863
866
    end;
864
867
gethostbyname_tm(Name, Type, Timer, [yp | Opts]) ->
865
 
    gethostbyname_tm(Name, Type, Timer, [native|Opts]);
 
868
    gethostbyname_tm_native(Name, Type, Timer, Opts);
866
869
gethostbyname_tm(Name, Type, Timer, [nis | Opts]) ->
867
 
    gethostbyname_tm(Name, Type, Timer, [native|Opts]);
 
870
    gethostbyname_tm_native(Name, Type, Timer, Opts);
868
871
gethostbyname_tm(Name, Type, Timer, [nisplus | Opts]) ->
869
 
    gethostbyname_tm(Name, Type, Timer, [native|Opts]);
 
872
    gethostbyname_tm_native(Name, Type, Timer, Opts);
870
873
gethostbyname_tm(Name, Type, Timer, [wins | Opts]) ->
871
 
    gethostbyname_tm(Name, Type, Timer, [native|Opts]);
 
874
    gethostbyname_tm_native(Name, Type, Timer, Opts);
872
875
gethostbyname_tm(Name, Type, Timer, [native | Opts]) ->
873
 
    %% Fixme: add (global) timeout to gethost_native
874
 
    case inet_gethost_native:gethostbyname(Name, Type) of
875
 
        {error,formerr} -> {error,einval};
876
 
        {error,timeout} -> {error,timeout};
877
 
        {error,_} -> gethostbyname_tm(Name, Type, Timer, Opts++no_default);
878
 
        Result -> Result
879
 
    end;
 
876
    gethostbyname_tm_native(Name, Type, Timer, Opts);
 
877
gethostbyname_tm(_, _, _, [no_default|_]) ->
 
878
    %% If the native resolver has failed, we should not bother
 
879
    %% to try to be smarter and parse the IP address here.
 
880
    {error,nxdomain};
880
881
gethostbyname_tm(Name, Type, Timer, [_ | Opts]) ->
881
882
    gethostbyname_tm(Name, Type, Timer, Opts);
 
883
%% Last resort - parse the hostname as address
882
884
gethostbyname_tm(Name, inet, _Timer, []) ->
883
885
    case inet_parse:ipv4_address(Name) of
884
886
        {ok,IP4} ->
890
892
               h_length = 4,
891
893
               h_addr_list = [IP4]}};
892
894
        _ ->
893
 
            case inet_parse:ipv6_address(Name) of
894
 
                {ok,_} -> {error,einval};
895
 
                _ ->      {error,nxdomain}
896
 
            end
 
895
            {error,nxdomain}
897
896
    end;
898
897
gethostbyname_tm(Name, inet6, _Timer, []) ->
899
898
    case inet_parse:ipv6_address(Name) of
911
910
            %% format ( {0,0,0,0,0,16#ffff,?u16(A,B),?u16(C,D)} ).
912
911
            %% This host might not support IPv6.
913
912
            {error,nxdomain}
914
 
    end;
915
 
gethostbyname_tm(Name, inet, _, no_default) ->
916
 
    %% If the native resolver has failed, we should not bother
917
 
    %% to try to be smarter and parse the IP address here.
918
 
    case inet_parse:ipv6_address(Name) of
919
 
        {ok,_} -> {error,einval};
920
 
        _ ->      {error,nxdomain}
921
 
    end;
922
 
gethostbyname_tm(_Name, inet6, _, no_default) ->
923
 
    %% If the native resolver has failed, we should not bother
924
 
    %% to try to be smarter and parse the IP address here.
925
 
    {error,nxdomain}.
 
913
    end.
 
914
 
 
915
gethostbyname_tm_native(Name, Type, Timer, Opts) ->
 
916
    %% Fixme: add (global) timeout to gethost_native
 
917
    case inet_gethost_native:gethostbyname(Name, Type) of
 
918
        {error,formerr} -> {error,einval};
 
919
        {error,timeout} -> {error,timeout};
 
920
        {error,_} -> gethostbyname_tm(Name, Type, Timer, Opts++[no_default]);
 
921
        Result -> Result
 
922
    end.
 
923
 
 
924
 
926
925
 
927
926
%%
928
927
%% gethostbyaddr with option search
942
941
        Result -> Result
943
942
    end;
944
943
gethostbyaddr_tm(Addr, Timer, [yp | Opts]) ->
945
 
    gethostbyaddr_tm(Addr, Timer, [native | Opts]);
 
944
    gethostbyaddr_tm_native(Addr, Timer, Opts);
946
945
gethostbyaddr_tm(Addr, Timer, [nis | Opts]) ->
947
 
    gethostbyaddr_tm(Addr, Timer, [native | Opts]);
 
946
    gethostbyaddr_tm_native(Addr, Timer, Opts);
948
947
gethostbyaddr_tm(Addr, Timer,  [nisplus | Opts]) ->
949
 
    gethostbyaddr_tm(Addr, Timer, [native | Opts]);
 
948
    gethostbyaddr_tm_native(Addr, Timer, Opts);
950
949
gethostbyaddr_tm(Addr, Timer, [wins | Opts]) ->
951
 
    gethostbyaddr_tm(Addr, Timer, [native | Opts]);
 
950
    gethostbyaddr_tm_native(Addr, Timer, Opts);
952
951
gethostbyaddr_tm(Addr, Timer, [native | Opts]) ->
953
 
    %% Fixme: user timer for timeoutvalue
954
 
    case inet_gethost_native:gethostbyaddr(Addr) of
955
 
        {error,formerr} -> {error, einval};
956
 
        {error,_} -> gethostbyaddr_tm(Addr,Timer,Opts);
957
 
        Result -> Result
958
 
    end;    
 
952
    gethostbyaddr_tm_native(Addr, Timer, Opts);
959
953
gethostbyaddr_tm(Addr, Timer, [_ | Opts]) ->
960
954
    gethostbyaddr_tm(Addr, Timer, Opts);
961
955
gethostbyaddr_tm(_Addr, _Timer, []) ->
962
956
    {error, nxdomain}.
963
957
 
 
958
gethostbyaddr_tm_native(Addr, Timer, Opts) ->
 
959
    %% Fixme: user timer for timeoutvalue
 
960
    case inet_gethost_native:gethostbyaddr(Addr) of
 
961
        {error,formerr} -> {error, einval};
 
962
        {error,_} -> gethostbyaddr_tm(Addr,Timer,Opts);
 
963
        Result -> Result
 
964
    end.
 
965
 
964
966
-spec open(Fd :: integer(),
965
967
           Addr :: ip_address(),
966
968
           Port :: ip_port(),