mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fixes for maxhostnamelen - all use NSHost.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@5113 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ec8ac9c3d6
commit
13b2d91b6c
4 changed files with 22 additions and 58 deletions
|
@ -148,17 +148,23 @@ static NSMutableDictionary*_hostCache = nil;
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Max hostname length in line with RFC 1123
|
||||
*/
|
||||
#define GSMAXHOSTNAMELEN 255
|
||||
|
||||
+ (NSHost*) currentHost
|
||||
{
|
||||
char name[MAXHOSTNAMELEN];
|
||||
int res;
|
||||
struct hostent*h;
|
||||
char name[GSMAXHOSTNAMELEN+1];
|
||||
int res;
|
||||
struct hostent *h;
|
||||
|
||||
res = gethostname(name, sizeof(name));
|
||||
res = gethostname(name, GSMAXHOSTNAMELEN);
|
||||
if (res < 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
name[GSMAXHOSTNAMELEN] = '\0';
|
||||
|
||||
h = gethostbyname(name);
|
||||
if (h == NULL)
|
||||
|
|
|
@ -54,13 +54,6 @@
|
|||
#include <config.h>
|
||||
#include <base/preface.h>
|
||||
|
||||
/* One of these two should have MAXHOSTNAMELEN */
|
||||
#if !defined(__WIN32__) || defined(__CYGWIN__)
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <netdb.h>
|
||||
#endif /* !__WIN32__ */
|
||||
|
||||
#ifdef HAVE_STRERROR
|
||||
#include <errno.h>
|
||||
#endif /* HAVE_STRERROR */
|
||||
|
@ -76,6 +69,7 @@
|
|||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
|
||||
/* This error message should be called only if the private main function
|
||||
* was not executed successfully. This may happen ONLY if another library
|
||||
|
@ -540,10 +534,7 @@ int main(int argc, char *argv[], char *env[])
|
|||
{
|
||||
if (!_gnu_hostName)
|
||||
{
|
||||
char hn[MAXHOSTNAMELEN];
|
||||
|
||||
gethostname(hn, MAXHOSTNAMELEN);
|
||||
_gnu_hostName = [[NSString alloc] initWithCString: hn];
|
||||
_gnu_hostName = [[[NSHost currentHost] name] copy];
|
||||
}
|
||||
return _gnu_hostName;
|
||||
}
|
||||
|
|
|
@ -49,12 +49,12 @@
|
|||
#include <Foundation/NSPortMessage.h>
|
||||
#include <Foundation/NSPortNameServer.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#if !defined(__WIN32__) || defined(__CYGWIN__)
|
||||
#include <unistd.h> /* for gethostname() */
|
||||
#include <sys/param.h> /* for MAXHOSTNAMELEN */
|
||||
#include <netinet/in.h> /* for inet_ntoa() */
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
@ -1110,8 +1110,7 @@ static NSMapTable* port_number_2_port;
|
|||
that when we encode the address, another machine can find us. */
|
||||
{
|
||||
struct hostent *hp;
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
int len = MAXHOSTNAMELEN;
|
||||
NSString *hostname;
|
||||
int r;
|
||||
|
||||
/* Set the re-use socket option so that we don't get this socket
|
||||
|
@ -1186,25 +1185,13 @@ static NSMapTable* port_number_2_port;
|
|||
machine so that, when we encoded our _LISTENING_ADDRESS for a
|
||||
Distributed Objects connection to another machine, they get our
|
||||
unique host address that can identify us across the network. */
|
||||
if (gethostname (hostname, len) < 0)
|
||||
{
|
||||
[p release];
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"[TcpInPort +newForReceivingFromPortNumber:] gethostname(): %s",
|
||||
strerror(errno)];
|
||||
}
|
||||
/* Terminate the name at the first dot. */
|
||||
{
|
||||
char *first_dot = strchr (hostname, '.');
|
||||
if (first_dot)
|
||||
*first_dot = '\0';
|
||||
}
|
||||
hp = gethostbyname (hostname);
|
||||
hostname = [[NSHost currentHost] name];
|
||||
hp = gethostbyname ([hostname cString]);
|
||||
if (!hp)
|
||||
hp = gethostbyname ("localhost");
|
||||
if (hp == 0)
|
||||
{
|
||||
NSLog(@"Unable to get IP address of '%s' or of 'localhost'", hostname);
|
||||
NSLog(@"Unable to get IP address of '%@' or of 'localhost'", hostname);
|
||||
#ifndef HAVE_INET_ATON
|
||||
p->_listening_address.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
#else
|
||||
|
@ -1934,27 +1921,13 @@ static NSMapTable *out_port_bag = NULL;
|
|||
struct hostent *hp;
|
||||
const char *host_cstring;
|
||||
struct sockaddr_in addr;
|
||||
/* Only used if no hostname is passed in. */
|
||||
char local_hostname[MAXHOSTNAMELEN];
|
||||
|
||||
/* Look up the hostname. */
|
||||
if (!hostname || ![hostname length])
|
||||
{
|
||||
int len = sizeof (local_hostname);
|
||||
char *first_dot;
|
||||
if (gethostname (local_hostname, len) < 0)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"[TcpInPort newForSendingToPortNumber:onHost:] gethostname(): %s",
|
||||
strerror(errno)];
|
||||
}
|
||||
host_cstring = local_hostname;
|
||||
first_dot = strchr (host_cstring, '.');
|
||||
if (first_dot)
|
||||
*first_dot = '\0';
|
||||
hostname = [[NSHost currentHost] name];
|
||||
}
|
||||
else
|
||||
host_cstring = [hostname cString];
|
||||
host_cstring = [hostname cString];
|
||||
hp = gethostbyname ((char*)host_cstring);
|
||||
if (!hp)
|
||||
[self error: "unknown host: \"%s\"", host_cstring];
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#include <base/Array.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#ifndef __WIN32__
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h> /* for MAXHOSTNAMELEN */
|
||||
#endif /* !__WIN32__ */
|
||||
#if _AIX
|
||||
#include <sys/select.h>
|
||||
|
@ -126,14 +126,8 @@ static NSMapTable *port_number_2_in_port = NULL;
|
|||
/* Give the socket a name using bind */
|
||||
{
|
||||
struct hostent *hp;
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
int len = MAXHOSTNAMELEN;
|
||||
if (gethostname (hostname, len) < 0)
|
||||
{
|
||||
perror ("[UdpInPort +newForReceivingFromPortNumber:] gethostname()");
|
||||
abort ();
|
||||
}
|
||||
hp = gethostbyname (hostname);
|
||||
|
||||
hp = gethostbyname ([[[NSHost currentHost] name] cString]);
|
||||
if (!hp)
|
||||
/* xxx This won't work with port connections on a network, though.
|
||||
Fix this. Perhaps there is a better way of getting the address
|
||||
|
|
Loading…
Reference in a new issue