Get IP address from socket descriptor?

后端 未结 4 1156
轻奢々
轻奢々 2021-01-19 03:06

I\'ve opened a TCP socket server (I\'ve omitted a few stuff, it is taken from here

sockfd = socket(p->ai_family, p->ai_socktype,
            p->ai_p         


        
4条回答
  •  粉色の甜心
    2021-01-19 03:47

    If you want to know who's at the other end of your socket you can use getpeername in Linux. getsockname will tell you who you are. You decide what address you want your server to sit on initially though, at bind time.

    You may also find this SO question useful: bind socket to network interface

    And the book "Unix Network Programming, vol 1", by W. Richard Stevens.

提交回复
热议问题