怎么没见过PF_INET,好象只有AF_INET啊?

解决方案 »

  1.   

    在winsock2.h里有 
    #define PF_INET AF_INET|> | AF = address family.  These constants go into the sin_family member of the
    |> | socket address structure.
    |> |
    |> | PF = protocol family.  These constants are the first argument to socket().
    |> 
    |> There is a little more to it than that.  Although I don't have the ancient
    |> sources handy to check (and my memory of this particular aspect is fading),
    |> I recall that the original socket code (4.1c/2.8/2.9BSD) employed a protocol
    |> structure similar in concept to the sockaddr structure.  The protocol
    |> structure contained a family element and a family-specific protocol number.
    |> The PF_ constants were used for the family element of the protocol structure.
    |> A protocol structure (or, rather, the address of one) could be passed to the
    |> socket() call to serve a purpose similar to that of the last (integer)
    |> argument
    |> of the current socket() call.  (Keep in mind that the old socket() call did
    |> not
    |> take a family/domain argument at all, so interpretation of the protocol
    |> number
    |> would not have been possible without the PF_ cue.)  Originally, then, the PF_
    |> and AF_ constants had a much more parallel purpose as structure tags.  When
    |> socket() started requiring a family/domain argument, the protocol structure
    |> was dropped.

    | Well, actually your memory is a bit off.
      

  2.   

    那么socket(PF_INET,SOCK_STREAM,IPPROTO_TCP)
    與socket(AF_INET,SOCK_STREAM,0)或socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)有什么區別啊?在程式中用起來好象沒有什么區別呢.
    能不能再解釋一下?