How to compare socket address in C?

后端 未结 2 2115
别跟我提以往
别跟我提以往 2021-02-07 07:10

I mean, which fields of struct sockaddr should I compare when I check whether two struct sockaddr\'s have the same ip address and port number? And what

2条回答
  •  既然无缘
    2021-02-07 07:53

    First you need to check the family (IPv4, IPv6, or other). Then you can cast each sockaddr to the appropriate "derived" type like sockaddr_in. See how Apple does it here: http://www.opensource.apple.com/source/postfix/postfix-197/postfix/src/util/sock_addr.c

提交回复
热议问题