diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-21 18:30:39 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-21 18:30:39 +0000 |
commit | 2fffc25ea8895cbd7748b4a84565091a91490995 (patch) | |
tree | 5636e6c7a930c462adeec55f1e2029745db195d6 /src/common/socket.c | |
parent | 30eb0d043dff54ee877e408c53d7ecd547686a22 (diff) | |
download | hercules-2fffc25ea8895cbd7748b4a84565091a91490995.tar.gz hercules-2fffc25ea8895cbd7748b4a84565091a91490995.tar.bz2 hercules-2fffc25ea8895cbd7748b4a84565091a91490995.tar.xz hercules-2fffc25ea8895cbd7748b4a84565091a91490995.zip |
- Added function parse_hostbyname() which takes a hostname and a char[4]. The hostname is resolved to an ip, whose individual components are stored in char[], the return value of the function is the inet_addr result of the lookup (or returns 0 when failed). Meant to be used in the rest of the code without the need to do socket/network related includes.
- Applied use of parse_hostbyname() in chrif.c to fix compilation errors.
- status_percent_change will now account for when the target's max hp/sp is above INT_MAX.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7281 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/socket.c')
-rw-r--r-- | src/common/socket.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/common/socket.c b/src/common/socket.c index 8fba86e0e..a9a9c628b 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -9,6 +9,7 @@ #ifdef __WIN32
#define __USE_W32_SOCKETS
#include <windows.h>
+#include <winsock.h>
#include <io.h>
typedef int socklen_t;
#else
@@ -16,9 +17,11 @@ typedef int socklen_t; #include <netinet/in.h>
#include <netinet/tcp.h>
#include <net/if.h>
-#include <sys/time.h>
#include <unistd.h>
+#include <sys/time.h>
#include <sys/ioctl.h>
+#include <netdb.h>
+#include <arpa/inet.h>
#ifndef SIOCGIFCONF
#include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
@@ -1388,3 +1391,15 @@ bool session_isActive(int fd) {
return ( session_isValid(fd) && !session[fd]->eof );
}
+
+in_addr_t resolve_hostbyname(char* hostname, char *ip) {
+ struct hostent *h = gethostbyname(hostname);
+ char ip_str[16];
+ if (!h) return 0;
+ 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];
+ sprintf(ip_str, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ return inet_addr(ip_str);
+}
|