hlswmaster/plugin_helper.c

79 lines
2.7 KiB
C
Raw Permalink Normal View History

2006-02-02 16:25:55 +01:00
/***************************************************************************
* Copyright (C) 03/2005 by Olaf Rempel *
* razzor@kopf-tisch.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
2006-02-02 16:24:06 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
2006-02-02 16:27:19 +01:00
2006-11-24 21:53:25 +01:00
#include "gamelist.h"
#include "logging.h"
2006-02-02 16:24:06 +01:00
#include "netpkt.h"
#include "plugin_helper.h"
2006-11-24 21:53:25 +01:00
#include "scanner.h"
int server_add(uint16_t gameid, uint32_t ip, uint16_t port1, uint16_t port2)
{
struct game_entry *entry = malloc(sizeof(struct game_entry));
if (entry == NULL) {
log_print(LOG_WARN, "server_add(): out of memory");
return -1;
}
entry->gameid = gameid;
entry->ip = ip;
entry->port1 = port1;
entry->port2 = port2;
return gamelist_add(entry);
}
int server_add_pkt(unsigned int gameid, struct net_pkt *pkt)
{
return server_add(gameid, pkt->addr.sin_addr.s_addr, ntohs(pkt->addr.sin_port), 0);
}
2006-02-02 16:25:55 +01:00
int pkt_send_portarr(struct in_addr *dstip, struct scan_ports *portarr, char *buf, unsigned int size)
{
2006-02-02 16:25:55 +01:00
unsigned short port;
2006-11-24 21:53:25 +01:00
int ret = 0;
2006-02-02 16:25:55 +01:00
while (portarr && portarr->portlo) {
for (port = portarr->portlo; port <= portarr->porthi; port++)
2006-11-24 21:53:25 +01:00
if (pkt_send(dstip, port, buf, size) < 0)
ret = -1;
2006-02-02 16:27:19 +01:00
2006-02-02 16:25:55 +01:00
portarr++;
}
return ret;
2006-02-02 16:24:06 +01:00
}
int pkt_check_portarr(struct net_pkt *pkt, struct scan_ports *portarr)
{
2006-02-02 16:25:55 +01:00
unsigned short port;
while (portarr && portarr->portlo) {
for (port = portarr->portlo; port <= portarr->porthi; port++)
if (port == ntohs(pkt->addr.sin_port))
return portarr->gameid;
2006-02-02 16:27:19 +01:00
2006-02-02 16:25:55 +01:00
portarr++;
}
return 0;
}