Commit f7296885ea86be9557608e8397983b06da1d7db0

Authored by Georg Hopp
1 parent a9dffbc9

fix makros for access to addrinfo structure.

Showing 1 changed file with 21 additions and 23 deletions
@@ -74,10 +74,7 @@ TR_INSTANCE_INIT(TR_Socket); @@ -74,10 +74,7 @@ TR_INSTANCE_INIT(TR_Socket);
74 #define TR_socketPort(socket) (((TR_Socket)(socket))->port) 74 #define TR_socketPort(socket) (((TR_Socket)(socket))->port)
75 #define TR_socketCname(socket) (((TR_Socket)(socket))->cname) 75 #define TR_socketCname(socket) (((TR_Socket)(socket))->cname)
76 #define TR_socketTtl(socket) (((TR_Socket)(socket))->ttl) 76 #define TR_socketTtl(socket) (((TR_Socket)(socket))->ttl)
77 -  
78 -#define TR_socketAddr(socket) \  
79 - ((unsigned char *)&((TR_Socket)(socket))->addr)  
80 - 77 +#define TR_socketAddr(socket) ((void *)&((TR_Socket)(socket))->addr)
81 #define TR_socketAddrlen(socket) (((TR_Socket)(socket))->addrlen) 78 #define TR_socketAddrlen(socket) (((TR_Socket)(socket))->addrlen)
82 #define TR_socketHandle(socket) (((TR_Socket)(socket))->handle) 79 #define TR_socketHandle(socket) (((TR_Socket)(socket))->handle)
83 #define TR_socketFinState(socket) (((TR_Socket)(socket))->fin_state) 80 #define TR_socketFinState(socket) (((TR_Socket)(socket))->fin_state)
@@ -86,31 +83,32 @@ TR_INSTANCE_INIT(TR_Socket); @@ -86,31 +83,32 @@ TR_INSTANCE_INIT(TR_Socket);
86 #define TR_socketFinRdWr(socket) ((TR_socketFinState((socket)) & 3) == 3) 83 #define TR_socketFinRdWr(socket) ((TR_socketFinState((socket)) & 3) == 3)
87 84
88 #define TR_socketAddrPort(socket) \ 85 #define TR_socketAddrPort(socket) \
89 - (((TR_Socket)(socket))->addr.info.sa_family == AF_INET \ 86 + (((TR_Socket)(socket))->addr.info.sa_family == AF_INET \
90 ? ((TR_Socket)(socket))->addr.in.sin_port \ 87 ? ((TR_Socket)(socket))->addr.in.sin_port \
91 : ((TR_Socket)(socket))->addr.info.sa_family == AF_INET6 \ 88 : ((TR_Socket)(socket))->addr.info.sa_family == AF_INET6 \
92 ? ((TR_Socket)(socket))->addr.in6.sin6_port \ 89 ? ((TR_Socket)(socket))->addr.in6.sin6_port \
93 - : -1) 90 + : 0)
94 91
95 -#define TR_socketAddrIp(socket) \  
96 - (((TR_Socket)(socket))->addr.info.sa_family == AF_INET \  
97 - ? ((TR_Socket)(socket))->addr.in.sin_addr.s_addr \  
98 - : ((TR_Socket)(socket))->addr.info.sa_family == AF_INET6 \  
99 - ? ((TR_Socket)(socket))->addr.in6.sin6_addr.s6_addr \ 92 +#define TR_socketAddrIp(socket) \
  93 + (((TR_Socket)(socket))->addr.info.sa_family == AF_INET \
  94 + ? (void *)&((TR_Socket)(socket))->addr.in.sin_addr.s_addr \
  95 + : ((TR_Socket)(socket))->addr.info.sa_family == AF_INET6 \
  96 + ? (void *)&((TR_Socket)(socket))->addr.in6.sin6_addr.s6_addr \
100 : NULL) 97 : NULL)
101 98
102 -#define TR_socketAddrIpStr(socket, buffer, nbuffer) \  
103 - (((TR_Socket)(socket))->addr.info.sa_family == AF_INET \  
104 - ? inet_ntop( \  
105 - ((TR_Socket)(socket))->addr.info.sa_family, \  
106 - &((TR_Socket)(socket))->addr.in.sin_addr.s_addr, \  
107 - buffer, nbuffer) \  
108 - : ((TR_Socket)(socket))->addr.info.sa_family == AF_INET6 \  
109 - ? inet_ntop( \  
110 - ((TR_Socket)(socket))->addr.info.sa_family, \  
111 - ((TR_Socket)(socket))->addr.in6.sin6_addr.s6_addr, \  
112 - buffer, nbuffer) \  
113 - : NULL) 99 +#define TR_socketAddrIplen(socket) \
  100 + (((TR_Socket)(socket))->addr.info.sa_family == AF_INET \
  101 + ? sizeof(((TR_Socket)(socket))->addr.in.sin_addr) \
  102 + : ((TR_Socket)(socket))->addr.info.sa_family == AF_INET6 \
  103 + ? sizeof(((TR_Socket)(socket))->addr.in6.sin6_addr) \
  104 + : 0)
  105 +
  106 +#define TR_socketAddrIpStr(socket, buffer, nbuffer) \
  107 + if (TR_socketAddrIp((socket))) \
  108 + inet_ntop( \
  109 + ((TR_Socket)(socket))->addr.info.sa_family, \
  110 + TR_socketAddrIp((socket)), \
  111 + buffer, nbuffer)
114 112
115 TR_CLASS(TR_TcpSocket) { 113 TR_CLASS(TR_TcpSocket) {
116 TR_EXTENDS(TR_Socket); 114 TR_EXTENDS(TR_Socket);
Please register or login to post a comment