changeset 1:32210a783cf7

Many improvements
author Josef "Jeff" Sipek <jeffpc@optonline.net>
date Fri, 26 Aug 2005 14:21:10 -0500
parents 41118bca4f06
children b91d9b779dd6
files main.c
diffstat 1 files changed, 40 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Fri Aug 26 13:56:45 2005 -0500
+++ b/main.c	Fri Aug 26 14:21:10 2005 -0500
@@ -6,23 +6,43 @@
 #include <arpa/inet.h>
 #include <string.h>
 #include <unistd.h>
+#include <signal.h>
+#include <errno.h>
 
 #define RCON_PASSWORD "foo;bar"
 #define RCON_PORT 27960
 #define RCON_HOST "127.0.0.1"
 
+#define BUF_LEN getpagesize()
+#define MAX_PID 65535
+
+inline void init_outbuf(char* b)
+{
+	/* all the commands begin with 4 0xff */
+	snprintf(b, BUF_LEN, "\xff\xff\xff\xffrcon %s ", RCON_PASSWORD);
+}
+
 int main(int argc, char** argv)
 {
 	int sockfd;
 	struct sockaddr_in dest_addr;
-	char *buf;
+	char *ibuf, *obuf;
+	int pid, pids;
+	int ret;
 
-	buf = (char*) malloc(sizeof(char)*getpagesize());
-	if (!buf) {
+	ibuf = (char*) malloc(sizeof(char)*getpagesize());
+	if (!ibuf) {
 		fprintf(stderr,"OOM\n");
 		return 1;
 	}
 	
+	obuf = (char*) malloc(sizeof(char)*BUF_LEN);
+	if (!obuf) {
+		fprintf(stderr,"OOM\n");
+		free(ibuf);
+		return 1;
+	}
+	
 	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
 
 	dest_addr.sin_family = AF_INET;
@@ -31,12 +51,24 @@
 	memset(&(dest_addr.sin_zero), '\0', 8);
 
 	connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
-	strcpy(buf, "\xff\xff\xff\xffrcon foo;bar status");
-	write(sockfd, buf, strlen(buf));
+	
+	init_outbuf(obuf);
+	
+	strcpy(obuf + strlen(obuf), "bot addbot foobar 1 3");
+	
+	for(pid=0, pids=0; pid < MAX_PID; pid++) {
+		ret = kill(pid,0);
+		if ((!ret) || (ret==-1 && errno==EPERM)) {
+			printf("pid %d exists%s\n",pid, (pid==getpid()?", ignoring":""));
+			pids++;
+		}
+	}
+	printf("Total %d pids found\n", pids);
+	
+	write(sockfd, obuf, strlen(obuf));
 	while(1) {
-		int ret;
-		ret = read(sockfd, buf, 250);
-		printf("%d bytes: %s\n",ret, buf);
+		ret = read(sockfd, ibuf, BUF_LEN-1);
+		printf("%d bytes: %s\n",ret, ibuf);
 	}
 	
 	return 0;