Bug in GAddress_UNIX_init fixed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4210 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1074,14 +1074,14 @@ GSocketError _GAddress_translate_to(GAddress *address,
|
|||||||
|
|
||||||
GSocketError _GAddress_Init_INET(GAddress *address)
|
GSocketError _GAddress_Init_INET(GAddress *address)
|
||||||
{
|
{
|
||||||
address->m_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
|
address->m_len = sizeof(struct sockaddr_in);
|
||||||
if (address->m_addr == NULL) {
|
address->m_addr = (struct sockaddr *)malloc(address->m_len));
|
||||||
|
if (address->m_addr == NULL)
|
||||||
|
{
|
||||||
address->m_error = GSOCK_MEMERR;
|
address->m_error = GSOCK_MEMERR;
|
||||||
return GSOCK_MEMERR;
|
return GSOCK_MEMERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
address->m_len = sizeof(struct sockaddr_in);
|
|
||||||
|
|
||||||
address->m_family = GSOCK_INET;
|
address->m_family = GSOCK_INET;
|
||||||
address->m_realfamily = PF_INET;
|
address->m_realfamily = PF_INET;
|
||||||
((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET;
|
((struct sockaddr_in *)address->m_addr)->sin_family = AF_INET;
|
||||||
@@ -1103,18 +1103,22 @@ GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname)
|
|||||||
|
|
||||||
/* If it is a numeric host name, convert it now */
|
/* If it is a numeric host name, convert it now */
|
||||||
#if defined(HAVE_INET_ATON)
|
#if defined(HAVE_INET_ATON)
|
||||||
if (inet_aton(hostname, addr) == 0) {
|
if (inet_aton(hostname, addr) == 0)
|
||||||
|
{
|
||||||
#elif defined(HAVE_INET_ADDR)
|
#elif defined(HAVE_INET_ADDR)
|
||||||
/* Fix from Guillermo Rodriguez Garcia <guille@iies.es> */
|
/* Fix from Guillermo Rodriguez Garcia <guille@iies.es> */
|
||||||
if ( (addr->s_addr = inet_addr(hostname)) == -1 ) {
|
if ( (addr->s_addr = inet_addr(hostname)) == -1 )
|
||||||
|
{
|
||||||
#else
|
#else
|
||||||
/* Use gethostbyname by default */
|
/* Use gethostbyname by default */
|
||||||
if (1) {
|
if (1)
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
struct in_addr *array_addr;
|
struct in_addr *array_addr;
|
||||||
|
|
||||||
/* It is a real name, we solve it */
|
/* It is a real name, we solve it */
|
||||||
if ((he = gethostbyname(hostname)) == NULL) {
|
if ((he = gethostbyname(hostname)) == NULL)
|
||||||
|
{
|
||||||
address->m_error = GSOCK_NOHOST;
|
address->m_error = GSOCK_NOHOST;
|
||||||
return GSOCK_NOHOST;
|
return GSOCK_NOHOST;
|
||||||
}
|
}
|
||||||
@@ -1148,14 +1152,16 @@ GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
|
|||||||
assert(address != NULL);
|
assert(address != NULL);
|
||||||
CHECK_ADDRESS(address, INET, GSOCK_INVADDR);
|
CHECK_ADDRESS(address, INET, GSOCK_INVADDR);
|
||||||
|
|
||||||
if (!port) {
|
if (!port)
|
||||||
|
{
|
||||||
address->m_error = GSOCK_INVPORT;
|
address->m_error = GSOCK_INVPORT;
|
||||||
return GSOCK_INVPORT;
|
return GSOCK_INVPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
se = getservbyname(port, protocol);
|
se = getservbyname(port, protocol);
|
||||||
if (!se) {
|
if (!se) {
|
||||||
if (isdigit(port[0])) {
|
if (isdigit(port[0]))
|
||||||
|
{
|
||||||
int port_int;
|
int port_int;
|
||||||
|
|
||||||
port_int = atoi(port);
|
port_int = atoi(port);
|
||||||
@@ -1200,7 +1206,8 @@ GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t
|
|||||||
addr_buf = (char *)&(addr->sin_addr);
|
addr_buf = (char *)&(addr->sin_addr);
|
||||||
|
|
||||||
he = gethostbyaddr(addr_buf, sizeof(addr->sin_addr), AF_INET);
|
he = gethostbyaddr(addr_buf, sizeof(addr->sin_addr), AF_INET);
|
||||||
if (he == NULL) {
|
if (he == NULL)
|
||||||
|
{
|
||||||
address->m_error = GSOCK_NOHOST;
|
address->m_error = GSOCK_NOHOST;
|
||||||
return GSOCK_NOHOST;
|
return GSOCK_NOHOST;
|
||||||
}
|
}
|
||||||
@@ -1241,13 +1248,14 @@ unsigned short GAddress_INET_GetPort(GAddress *address)
|
|||||||
|
|
||||||
GSocketError _GAddress_Init_UNIX(GAddress *address)
|
GSocketError _GAddress_Init_UNIX(GAddress *address)
|
||||||
{
|
{
|
||||||
|
address->m_len = sizeof(struct sockaddr_un);
|
||||||
address->m_addr = (struct sockaddr *)malloc(address->m_len);
|
address->m_addr = (struct sockaddr *)malloc(address->m_len);
|
||||||
if (address->m_addr == NULL) {
|
if (address->m_addr == NULL)
|
||||||
|
{
|
||||||
address->m_error = GSOCK_MEMERR;
|
address->m_error = GSOCK_MEMERR;
|
||||||
return GSOCK_MEMERR;
|
return GSOCK_MEMERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
address->m_len = sizeof(struct sockaddr_un);
|
|
||||||
address->m_family = GSOCK_UNIX;
|
address->m_family = GSOCK_UNIX;
|
||||||
address->m_realfamily = PF_UNIX;
|
address->m_realfamily = PF_UNIX;
|
||||||
((struct sockaddr_un *)address->m_addr)->sun_family = AF_UNIX;
|
((struct sockaddr_un *)address->m_addr)->sun_family = AF_UNIX;
|
||||||
|
Reference in New Issue
Block a user