CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2018
    Posts
    158

    structure sockaddr

    What is reason to put data (ip, port) into structure of sockaddr to use connect primitive or bind ?
    It could to be easier to pass as single parameters (ip or ports) instead to pass the structure ?
    Why It's implemented in this way ?

  2. #2
    Join Date
    Nov 2018
    Posts
    115

    Re: structure sockaddr

    https://www.man7.org/linux/man-pages/man2/bind.2.html
    There are many different kinds of sockets. sockaddr is just the base type (think C++ base class).

    sockaddr_in https://www.man7.org/linux/man-pages/man7/ip.7.html
    sockaddr_in6 https://www.man7.org/linux/man-pages/man7/ipv6.7.html
    sockaddr_un https://www.man7.org/linux/man-pages/man7/unix.7.html
    and so on.

    So changing from ipv4 to ipv6 say just involves changing/initialising instances of sockaddr_in to be sockaddr_in6.

  3. #3
    Join Date
    May 2018
    Posts
    158

    Re: structure sockaddr

    Quote Originally Posted by salem_c View Post
    https://www.man7.org/linux/man-pages/man2/bind.2.html
    There are many different kinds of sockets. sockaddr is just the base type (think C++ base class).

    sockaddr_in
    I'm referencing to this one sockaddr_in

    Why it has been implemented a structure to contain af_family, port and ip address ?

  4. #4
    Join Date
    Nov 2018
    Posts
    115

    Re: structure sockaddr

    > Why it has been implemented a structure to contain af_family, port and ip address ?
    Because those are things you need to know to create an IP socket.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured