X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6a2e72251f492b810438fa0d9f9f1d5054ecd012..ddb56b384de2123bc1f82312039f66c7b1004fde:/src/unix/gsocket.c diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index 004f6c38dd..ad6dc22ce6 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -14,12 +14,17 @@ #include #include #include -#ifdef vms +#ifdef __VMS__ #include +struct sockaddr_un { + u_char sun_len; /* sockaddr len including null */ + u_char sun_family; /* AF_UNIX */ + char sun_path[108]; /* path name (gag) */ +}; #else #include -#endif #include +#endif #include #include #include @@ -47,15 +52,19 @@ #ifndef SOCKLEN_T -#ifdef __GLIBC__ -# if __GLIBC__ == 2 -# define SOCKLEN_T socklen_t -# endif +#ifdef VMS +# define SOCKLEN_T unsigned int #else -# define SOCKLEN_T int +# ifdef __GLIBC__ +# if __GLIBC__ == 2 +# define SOCKLEN_T socklen_t +# endif +# else +# define SOCKLEN_T int +# endif #endif -#endif +#endif /* SOCKLEN_T */ #define MASK_SIGNAL() \ { \ @@ -203,7 +212,7 @@ GAddress *GSocket_GetLocal(GSocket *socket) { GAddress *address; struct sockaddr addr; - SOCKLEN_T size; + SOCKLEN_T size = sizeof(addr); GSocketError err; assert(socket != NULL); @@ -218,7 +227,7 @@ GAddress *GSocket_GetLocal(GSocket *socket) size = sizeof(addr); - if (getsockname(socket->m_fd, &addr, &size) < 0) { + if (getsockname(socket->m_fd, &addr, (SOCKLEN_T *) &size) < 0) { socket->m_error = GSOCK_IOERR; return NULL; } @@ -228,9 +237,10 @@ GAddress *GSocket_GetLocal(GSocket *socket) socket->m_error = GSOCK_MEMERR; return NULL; } - socket->m_error = _GAddress_translate_from(address, &addr, size); - if (socket->m_error != GSOCK_NOERROR) { + err = _GAddress_translate_from(address, &addr, size); /*xxx*/ + if (err != GSOCK_NOERROR) { GAddress_destroy(address); + socket->m_error = err; return NULL; } @@ -312,7 +322,10 @@ GSocketError GSocket_SetServer(GSocket *sck) */ GSocket *GSocket_WaitConnection(GSocket *socket) { + struct sockaddr from; + SOCKLEN_T fromlen = sizeof(from); GSocket *connection; + GSocketError err; int arg = 1; assert(socket != NULL); @@ -331,7 +344,7 @@ GSocket *GSocket_WaitConnection(GSocket *socket) connection = GSocket_new(); if (!connection) { - connection->m_error = GSOCK_MEMERR; + socket->m_error = GSOCK_MEMERR; return NULL; } @@ -343,7 +356,7 @@ GSocket *GSocket_WaitConnection(GSocket *socket) return NULL; } - connection->m_fd = accept(socket->m_fd, NULL, NULL); + connection->m_fd = accept(socket->m_fd, &from, (SOCKLEN_T *) &fromlen); if (connection->m_fd == -1) { @@ -361,6 +374,23 @@ GSocket *GSocket_WaitConnection(GSocket *socket) connection->m_stream = TRUE; connection->m_oriented = TRUE; + /* Setup the peer address field */ /*xxx*/ + connection->m_peer = GAddress_new(); + if (!connection->m_peer) + { + GSocket_destroy(connection); + socket->m_error = GSOCK_MEMERR; + return NULL; + } + err = _GAddress_translate_from(connection->m_peer, &from, fromlen); + if (err != GSOCK_NOERROR) + { + GAddress_destroy(connection->m_peer); + GSocket_destroy(connection); + socket->m_error = err; + return NULL; + } + ioctl(connection->m_fd, FIONBIO, &arg); _GSocket_Enable_Events(connection); @@ -792,14 +822,14 @@ int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size) int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size) { struct sockaddr from; - SOCKLEN_T fromlen; + SOCKLEN_T fromlen = sizeof(from); int ret; GSocketError err; fromlen = sizeof(from); MASK_SIGNAL(); - ret = recvfrom(socket->m_fd, buffer, size, 0, &from, &fromlen); + ret = recvfrom(socket->m_fd, buffer, size, 0, &from, (SOCKLEN_T *) &fromlen); UNMASK_SIGNAL(); if (ret == -1) @@ -830,7 +860,6 @@ int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size) int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size) { int ret; - GSocketError err; MASK_SIGNAL(); ret = send(socket->m_fd, buffer, size, 0); @@ -901,7 +930,8 @@ void _GSocket_Detected_Write(GSocket *socket) socket->m_establishing = FALSE; len = sizeof(error); - getsockopt(socket->m_fd, SOL_SOCKET, SO_ERROR, (void*) &error, &len); + getsockopt(socket->m_fd, SOL_SOCKET, SO_ERROR, (void*) &error, + (SOCKLEN_T *) &len); if (error) { @@ -1080,7 +1110,11 @@ GSocketError _GAddress_Init_INET(GAddress *address) address->m_family = GSOCK_INET; address->m_realfamily = PF_INET; ((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET; - ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_ANY; + /* + INADDR_BROADCAST is identical to INADDR_NONE which is not defined + on all unices. INADDR_BROADCAST should be fine to indicate an error. + */ + ((struct sockaddr_in *)address->m_addr)->sin_addr.s_addr = INADDR_BROADCAST; return GSOCK_NOERROR; } @@ -1289,3 +1323,4 @@ GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf) #endif /* wxUSE_SOCKETS */ +