Update of /cvsroot/agd/server/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10923
Modified Files:
dfuns.c
Log Message:
Added dfuns query_ip, query_hostname, asctime, changed time().
Index: dfuns.c
===================================================================
RCS file: /cvsroot/agd/server/src/dfuns.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- dfuns.c 18 Mar 2004 20:47:36 -0000 1.13
+++ dfuns.c 21 Mar 2004 08:52:29 -0000 1.14
@@ -3,6 +3,7 @@
#include "dfuns.h"
#include <time.h>
#include <errno.h>
+#include <netdb.h> /* for gethostbyaddr() */
extern time_t startup_time; /* for uptime() */
extern variable_t *fp, *sp;
@@ -53,6 +54,7 @@
return len;
}
+#if 0
char *do_time(void)
{
static char buf[512];
@@ -63,6 +65,7 @@
strftime(buf, 512, "%T %d %B %Y", tm);
return buf;
}
+#endif
void shout(char *s, object_t *exclude)
{
@@ -88,8 +91,49 @@
push_void();
}
+char *get_ip(object_t *ob) {
+ if(!ob->iaob)
+ return NULL;
+ return inet_ntoa(ob->iaob->conn.addr.sin_addr);
+}
+
+void df_query_ip(void) {
+ char *s;
+ s = get_ip(fp->u.ob);
+ pop_stack();
+ push_string(s, ST_STATIC);
+}
+
+void df_query_hostname(void) {
+ char *s;
+ struct hostent *he;
+
+ s = get_ip(fp->u.ob);
+ if(!s)
+ goto out;
+ he = gethostbyaddr(s, strlen(s), AF_INET);
+ if(!he)
+ goto out;
+ s = he->h_name;
+
+out:
+ pop_stack();
+ push_string(s, ST_STATIC);
+}
+
void df_time(void) {
- push_string(do_time(), ST_STATIC);
+ push_int(time(NULL));
+}
+
+void df_asctime(void) {
+ time_t t;
+ char *s;
+
+ t = fp->u.i;
+ s = ctime(&t);
+ s[strlen(s)-1] = '\0'; /* Remove the newline. */
+ pop_stack();
+ push_string(s, ST_STATIC);
}
void df_shout(void) {
@@ -250,10 +294,3 @@
push_string(s, ST_MALLOC);
}
-/* Debugging. */
-void df_print_objs(void)
-{
- print_objs();
- push_void();
-}
-
|