From 95d2ca8a4621d655fc42b9e5df1c558d2e622e3a Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Mon, 11 Sep 2000 16:19:53 +0000 Subject: [PATCH] Add proper struct sockaddr * casts and make use of memcpy/memset ('coz we don't provide any fallbacks for bcopy/bzero). --- ext/sockets/sockets.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index b472139dae..98d477c788 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -430,7 +430,7 @@ static int open_listen_sock(int port) return -1; } - bcopy(hp->h_addr, (char *)&la.sin_addr, hp->h_length); + memcpy((char *)&la.sin_addr, hp->h_addr, hp->h_length); la.sin_family = hp->h_addrtype; la.sin_port = htons(port); @@ -633,7 +633,7 @@ PHP_FUNCTION(getsockname) v_convert_to_long_ex(2, fd, port); convert_to_string_ex(addr); - ret = getsockname(Z_LVAL_PP(fd), &sa, &salen); + ret = getsockname(Z_LVAL_PP(fd), (struct sockaddr *) &sa, &salen); if (ret < 0) { RETURN_LONG(-errno); } else { @@ -643,7 +643,7 @@ PHP_FUNCTION(getsockname) inet_ntoa_lock = 1; addr_string = inet_ntoa(sa.sin_addr); tmp = emalloc(strlen(addr_string) + 1); - bzero(tmp, strlen(addr_string) + 1); + memset(tmp, 0, strlen(addr_string) + 1); strncpy(tmp, addr_string, strlen(addr_string)); inet_ntoa_lock = 0; @@ -729,7 +729,7 @@ PHP_FUNCTION(getpeername) v_convert_to_long_ex(2, fd, port); convert_to_string_ex(addr); - ret = getpeername(Z_LVAL_PP(fd), &sa, &salen); + ret = getpeername(Z_LVAL_PP(fd), (struct sockaddr *) &sa, &salen); if (ret < 0) { RETURN_LONG(-errno); @@ -740,7 +740,7 @@ PHP_FUNCTION(getpeername) inet_ntoa_lock = 1; addr_string = inet_ntoa(sa.sin_addr); tmp = emalloc(strlen(addr_string) + 1); - bzero(tmp, strlen(addr_string) + 1); + memset(tmp, 0, strlen(addr_string) + 1); strncpy(tmp, addr_string, strlen(addr_string)); inet_ntoa_lock = 0; @@ -863,7 +863,7 @@ PHP_FUNCTION(connect) convert_to_long_ex(port); } - bzero(&sa, sizeof(sa)); + memset(&sa, 0, sizeof(sa)); ret = getsockname(Z_LVAL_PP(sockfd), &sa, &salen); if (ret < 0) { @@ -968,7 +968,7 @@ PHP_FUNCTION(bind) if (sock_type.sa_family == AF_UNIX) { struct sockaddr_un sa; snprintf(sa.sun_path, 108, "%s", Z_STRVAL_PP(arg1)); - ret = bind(Z_LVAL_PP(arg0), &sa, SUN_LEN(&sa)); + ret = bind(Z_LVAL_PP(arg0), (struct sockaddr *) &sa, SUN_LEN(&sa)); } else if (sock_type.sa_family == AF_INET) { struct sockaddr_in sa; struct in_addr addr_buf; @@ -991,7 +991,7 @@ PHP_FUNCTION(bind) sa.sin_addr.s_addr = addr_buf.s_addr; } - ret = bind(Z_LVAL_PP(arg0), &sa, sizeof(sa)); + ret = bind(Z_LVAL_PP(arg0), (struct sockaddr *) &sa, sizeof(sa)); } else { RETURN_LONG(-EPROTONOSUPPORT); } @@ -1115,7 +1115,7 @@ PHP_FUNCTION(add_iovec) ZEND_FETCH_RESOURCE(vector, php_iovec_t *, iovec_id, -1, "IO vector table", SOCKETSG(le_iov)); vector_array = emalloc(sizeof(struct iovec) * (vector->count + 2)); - bcopy(vector->iov_array, vector_array, sizeof(struct iovec) * vector->count); + memcpy(vector_array, vector->iov_array, sizeof(struct iovec) * vector->count); vector_array[vector->count].iov_base = emalloc(Z_LVAL_PP(iov_len)); vector_array[vector->count].iov_len = Z_LVAL_PP(iov_len); @@ -1153,9 +1153,9 @@ PHP_FUNCTION(delete_iovec) for (i = 0; i < vector->count; i++) { if (i < Z_LVAL_PP(iov_pos)) { - bcopy(&(vector_array[i]), &(vector->iov_array[i]), sizeof(struct iovec)); + memcpy(&(vector->iov_array[i]), &(vector_array[i]), sizeof(struct iovec)); } else if (i > Z_LVAL_PP(iov_pos)) { - bcopy(&(vector_array[i - 1]), &(vector->iov_array[i]), sizeof(struct iovec)); + memcpy(&(vector->iov_array[i]), &(vector_array[i - 1]), sizeof(struct iovec)); } } @@ -1249,7 +1249,7 @@ PHP_FUNCTION(recv) convert_to_string_ex(buf); recv_buf = emalloc(Z_LVAL_PP(len) + 2); - bzero(recv_buf, Z_LVAL_PP(len) + 2); + memset(recv_buf, 0, Z_LVAL_PP(len) + 2); ret = recv(Z_LVAL_PP(fd), recv_buf, Z_LVAL_PP(len), Z_LVAL_PP(flags)); @@ -1337,7 +1337,7 @@ PHP_FUNCTION(recvfrom) if (ZEND_NUM_ARGS() != 5) { WRONG_PARAM_COUNT; } - bzero(recv_buf, Z_LVAL_PP(len) + 2); + memset(recv_buf, 0, Z_LVAL_PP(len) + 2); ret = recvfrom(Z_LVAL_PP(fd), recv_buf, Z_LVAL_PP(len), Z_LVAL_PP(flags), (struct sockaddr *)&sun, (socklen_t *) & sun_length); @@ -1376,7 +1376,7 @@ PHP_FUNCTION(recvfrom) if (ZEND_NUM_ARGS() != 6) { WRONG_PARAM_COUNT; } - bzero(recv_buf, Z_LVAL_PP(len) + 2); + memset(recv_buf, 0, Z_LVAL_PP(len) + 2); ret = recvfrom(Z_LVAL_PP(fd), recv_buf, Z_LVAL_PP(len), Z_LVAL_PP(flags), (struct sockaddr *)&sin, (socklen_t *) & sin_length); @@ -1463,12 +1463,12 @@ PHP_FUNCTION(sendto) if (ZEND_NUM_ARGS() != 5) { WRONG_PARAM_COUNT; } - bzero(&sun, sizeof(sun)); + memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; snprintf(sun.sun_path, 108, "%s", Z_STRVAL_PP(port)); ret = sendto(Z_LVAL_PP(fd), Z_STRVAL_PP(buf), (Z_STRLEN_PP(buf) > Z_LVAL_PP(len) ? Z_LVAL_PP(len) : Z_STRLEN_PP(buf)), - Z_LVAL_PP(flags), &sun, SUN_LEN(&sun)); + Z_LVAL_PP(flags), (struct sockaddr *) &sun, SUN_LEN(&sun)); RETURN_LONG(((ret < 0) ? -errno : ret)); } @@ -1481,7 +1481,7 @@ PHP_FUNCTION(sendto) if (ZEND_NUM_ARGS() != 6) { WRONG_PARAM_COUNT; } - bzero(&sin, sizeof(sin)); + memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; if (inet_aton(Z_STRVAL_PP(addr), &addr_buf) == 0) { @@ -1498,7 +1498,7 @@ PHP_FUNCTION(sendto) sin.sin_port = htons(Z_LVAL_PP(port)); ret = sendto(Z_LVAL_PP(fd), Z_STRVAL_PP(buf), (Z_STRLEN_PP(buf) > Z_LVAL_PP(len) ? Z_LVAL_PP(len) : Z_STRLEN_PP(buf)), - Z_LVAL_PP(flags), &sin, sizeof(sin)); + Z_LVAL_PP(flags), (struct sockaddr *) &sin, sizeof(sin)); RETURN_LONG(((ret < 0) ? -errno : ret)); } @@ -1570,7 +1570,7 @@ PHP_FUNCTION(recvmsg) efree(ctl_buf); WRONG_PARAM_COUNT; } - bzero(&sa, sizeof(sa)); + memset(&sa, 0, sizeof(sa)); hdr.msg_name = sin; hdr.msg_namelen = sizeof(sa); hdr.msg_iov = iov->iov_array; @@ -1629,7 +1629,7 @@ PHP_FUNCTION(recvmsg) efree(ctl_buf); WRONG_PARAM_COUNT; } - bzero(&sa, sizeof(sa)); + memset(&sa, 0, sizeof(sa)); hdr.msg_name = sun; hdr.msg_namelen = sizeof(sa); hdr.msg_iov = iov->iov_array; @@ -1708,7 +1708,7 @@ PHP_FUNCTION(sendmsg) struct sockaddr_in *sin = (struct sockaddr_in *) &sa; h_errno = 0; errno = 0; - bzero(&hdr, sizeof(hdr)); + memset(&hdr, 0, sizeof(hdr)); hdr.msg_name = &sa; hdr.msg_namelen = sizeof(sa); hdr.msg_iov = iov->iov_array; -- 2.40.0