diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-22 01:12:52 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-22 01:12:52 +0000 |
commit | 8ecd9729cb7da906470a88decb77620ed3d7ffdf (patch) | |
tree | 23486d0498a03b341b7f2a6bca2543a7705fe63d /src/common | |
parent | 0c74559d80136821bee587473b01dab5935ebf26 (diff) | |
download | hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.tar.gz hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.tar.bz2 hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.tar.xz hercules-8ecd9729cb7da906470a88decb77620ed3d7ffdf.zip |
- Tested and fixed resolve_hostbyname.
- Applied said function around most of the code where needed. Removed includes for the OS/network system pretty much from every file (our socket.c file should handle this)
- Added clif_getip_long, which returns the ip as a long. Prevents having to include the files to define the int_addr structure in all files that include clif.h
- Made the GM mute request bypass the manner_system setting.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7285 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/socket.c | 7 | ||||
-rw-r--r-- | src/common/socket.h | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/common/socket.c b/src/common/socket.c index a9a9c628b..dc8162ee1 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -1392,14 +1392,17 @@ bool session_isActive(int fd) return ( session_isValid(fd) && !session[fd]->eof );
}
-in_addr_t resolve_hostbyname(char* hostname, char *ip) {
+in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str) {
struct hostent *h = gethostbyname(hostname);
- char ip_str[16];
+ unsigned char ip_buf[16];
+ char ip2[4];
if (!h) return 0;
+ if (ip == NULL) ip = ip2;
ip[0] = (unsigned char) h->h_addr[0];
ip[1] = (unsigned char) h->h_addr[1];
ip[2] = (unsigned char) h->h_addr[2];
ip[3] = (unsigned char) h->h_addr[3];
+ if (ip_str == NULL) ip_str = ip_buf;
sprintf(ip_str, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
return inet_addr(ip_str);
}
diff --git a/src/common/socket.h b/src/common/socket.h index 4d8d36807..158759f9e 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -9,6 +9,7 @@ #ifdef __WIN32
#define __USE_W32_SOCKETS
#include <windows.h>
+typedef long in_addr_t;
#else
#include <sys/types.h>
#include <sys/socket.h>
@@ -157,7 +158,10 @@ void set_defaultconsoleparse(int (*defaultparse)(char*)); //Resolves the hostname and stores the string representation of the string in ip.
//Meant to simplify calls to gethostbyname without the need of all the
//required network includes.
-in_addr_t resolve_hostbyname(char* hostname, char *ip);
+//hostname is the name to resolve.
+//ip is an array of char[4] where the individual parts of the ip are stored (optional)
+//ip_str is a char[16] where the whole ip is stored in string notation (optional)
+in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str);
extern unsigned int addr_[16]; // ip addresses of local host (host byte order)
extern unsigned int naddr_; // # of ip addresses
|