What is the difference between AF_INET and PF_INET in socket programming?

前端 未结 7 829
一向
一向 2020-11-30 16:13

What is the difference between AF_INET and PF_INET in socket programming?

I\'m confused between using AF_INET and PF_INET in socket() and bind()

7条回答
  •  执笔经年
    2020-11-30 16:53

    • AF = Address Family
    • PF = Protocol Family

    Meaning, AF_INET refers to addresses from the internet, IP addresses specifically. PF_INET refers to anything in the protocol, usually sockets/ports.

    Consider reading the man pages for socket(2) and bind(2). For the sin_addr field, just do something like the following to set it:

    struct sockaddr_in addr;
    inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr); 
    

提交回复
热议问题