diff options
Diffstat (limited to 'lib/server/Socket.cpp')
-rw-r--r-- | lib/server/Socket.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index 28dae69f..4a83bdb0 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -32,12 +32,15 @@ // -------------------------------------------------------------------------- // // Function -// Name: Socket::NameLookupToSockAddr(SocketAllAddr &, int, char *, int) +// Name: Socket::NameLookupToSockAddr(SocketAllAddr &, int, +// char *, int) // Purpose: Sets up a sockaddr structure given a name and type // Created: 2003/07/31 // // -------------------------------------------------------------------------- -void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type, const char *Name, int Port, int &rSockAddrLenOut) +void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, + enum Type Type, const std::string& rName, int Port, + int &rSockAddrLenOut) { int sockAddrLen = 0; @@ -47,7 +50,7 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type sockDomain = AF_INET; { // Lookup hostname - struct hostent *phost = ::gethostbyname(Name); + struct hostent *phost = ::gethostbyname(rName.c_str()); if(phost != NULL) { if(phost->h_addr_list[0] != 0) @@ -81,7 +84,7 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type sockDomain = AF_UNIX; { // Check length of name is OK - unsigned int nameLen = ::strlen(Name); + unsigned int nameLen = rName.length(); if(nameLen >= (sizeof(addr.sa_unix.sun_path) - 1)) { THROW_EXCEPTION(ServerException, SocketNameUNIXPathTooLong); @@ -91,7 +94,9 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type addr.sa_unix.sun_len = sockAddrLen; #endif addr.sa_unix.sun_family = PF_UNIX; - ::strcpy(addr.sa_unix.sun_path, Name); + ::strncpy(addr.sa_unix.sun_path, rName.c_str(), + sizeof(addr.sa_unix.sun_path) - 1); + addr.sa_unix.sun_path[sizeof(addr.sa_unix.sun_path)-1] = 0; } break; #endif |