comparison src/core/ngx_connection.c @ 5463:1ab1cf63f885

Core: keep the length of the local sockaddr.
author Ruslan Ermilov <ru@nginx.com>
date Mon, 09 Dec 2013 10:14:51 +0400
parents 692afcea9d0d
children 30e806b8636a
comparison
equal deleted inserted replaced
5462:58716fd3bd2d 5463:1ab1cf63f885
1076 #if (NGX_HAVE_INET6) 1076 #if (NGX_HAVE_INET6)
1077 ngx_uint_t i; 1077 ngx_uint_t i;
1078 struct sockaddr_in6 *sin6; 1078 struct sockaddr_in6 *sin6;
1079 #endif 1079 #endif
1080 1080
1081 if (c->local_socklen == 0) {
1082 return NGX_ERROR;
1083 }
1084
1081 switch (c->local_sockaddr->sa_family) { 1085 switch (c->local_sockaddr->sa_family) {
1082 1086
1083 #if (NGX_HAVE_INET6) 1087 #if (NGX_HAVE_INET6)
1084 case AF_INET6: 1088 case AF_INET6:
1085 sin6 = (struct sockaddr_in6 *) c->local_sockaddr; 1089 sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
1086 len = sizeof(struct sockaddr_in6);
1087 1090
1088 for (addr = 0, i = 0; addr == 0 && i < 16; i++) { 1091 for (addr = 0, i = 0; addr == 0 && i < 16; i++) {
1089 addr |= sin6->sin6_addr.s6_addr[i]; 1092 addr |= sin6->sin6_addr.s6_addr[i];
1090 } 1093 }
1091 1094
1092 break; 1095 break;
1093 #endif 1096 #endif
1094 1097
1095 default: /* AF_INET */ 1098 default: /* AF_INET */
1096 sin = (struct sockaddr_in *) c->local_sockaddr; 1099 sin = (struct sockaddr_in *) c->local_sockaddr;
1097 len = sizeof(struct sockaddr_in);
1098 addr = sin->sin_addr.s_addr; 1100 addr = sin->sin_addr.s_addr;
1099 break; 1101 break;
1100 } 1102 }
1101 1103
1102 if (addr == 0) { 1104 if (addr == 0) {
1112 if (c->local_sockaddr == NULL) { 1114 if (c->local_sockaddr == NULL) {
1113 return NGX_ERROR; 1115 return NGX_ERROR;
1114 } 1116 }
1115 1117
1116 ngx_memcpy(c->local_sockaddr, &sa, len); 1118 ngx_memcpy(c->local_sockaddr, &sa, len);
1119
1120 c->local_socklen = len;
1117 } 1121 }
1118 1122
1119 if (s == NULL) { 1123 if (s == NULL) {
1120 return NGX_OK; 1124 return NGX_OK;
1121 } 1125 }
1122 1126
1123 s->len = ngx_sock_ntop(c->local_sockaddr, len, s->data, s->len, port); 1127 s->len = ngx_sock_ntop(c->local_sockaddr, c->local_socklen,
1128 s->data, s->len, port);
1124 1129
1125 return NGX_OK; 1130 return NGX_OK;
1126 } 1131 }
1127 1132
1128 1133