Linux HLSW LAN Master
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7 KiB

  1. /***************************************************************************
  2. * Copyright (C) 03/2005 by Olaf Rempel *
  3. * razzor@kopf-tisch.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <string.h>
  24. #include "gamelist.h"
  25. #include "logging.h"
  26. #include "netpkt.h"
  27. #include "plugin_helper.h"
  28. #include "scanner.h"
  29. int server_add(uint16_t gameid, uint32_t ip, uint16_t port1, uint16_t port2)
  30. {
  31. struct game_entry *entry = malloc(sizeof(struct game_entry));
  32. if (entry == NULL) {
  33. log_print(LOG_WARN, "server_add(): out of memory");
  34. return -1;
  35. }
  36. entry->gameid = gameid;
  37. entry->ip = ip;
  38. entry->port1 = port1;
  39. entry->port2 = port2;
  40. return gamelist_add(entry);
  41. }
  42. int server_add_pkt(unsigned int gameid, struct net_pkt *pkt)
  43. {
  44. return server_add(gameid, pkt->addr.sin_addr.s_addr, ntohs(pkt->addr.sin_port), 0);
  45. }
  46. int pkt_send_portarr(struct in_addr *dstip, struct scan_ports *portarr, char *buf, unsigned int size)
  47. {
  48. unsigned short port;
  49. int ret = 0;
  50. while (portarr && portarr->portlo) {
  51. for (port = portarr->portlo; port <= portarr->porthi; port++)
  52. if (pkt_send(dstip, port, buf, size) < 0)
  53. ret = -1;
  54. portarr++;
  55. }
  56. return ret;
  57. }
  58. int pkt_check_portarr(struct net_pkt *pkt, struct scan_ports *portarr)
  59. {
  60. unsigned short port;
  61. while (portarr && portarr->portlo) {
  62. for (port = portarr->portlo; port <= portarr->porthi; port++)
  63. if (port == ntohs(pkt->addr.sin_port))
  64. return portarr->gameid;
  65. portarr++;
  66. }
  67. return 0;
  68. }