| 1 | /* |
| 2 | * Copyright (C) 2000 Ross Combs ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 19 | #include "udptest_send.h"cxx . . $ `<file>/src/bnetd/udptest_send.h`/ |
| 20 | |
| 21 | #include <cstring> |
| 22 | #include <cstdio> |
| 23 | |
| 24 | #include "compat/psock.h"cxx . . $ `<file>/src/compat/psock.h`/ |
| 25 | #include "compat/strerror.h"cxx . . $ `<file>/src/compat/strerror.h`/ |
| 26 | #include "common/packet.h"cxx . . $ `<file>/src/common/packet.h`/ |
| 27 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 28 | #include "common/bn_type.h"cxx . . $ `<file>/src/common/bn_type.h`/ |
| 29 | #include "common/hexdump.h"cxx . . $ `<file>/src/common/hexdump.h`/ |
| 30 | #include "common/addr.h"cxx . . $ `<file>/src/common/addr.h`/ |
| 31 | #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/ |
| 32 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 33 | |
| 34 | |
| 35 | extern stdcxx . . $ std/::FILEcxx . . $ std/FILE# * hexstrmcxx . . $ hexstrm.; /* from main.c */ |
| 36 | |
| 37 | namespace pvpgncxx . . $ pvpgn/ |
| 38 | { |
| 39 | |
| 40 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 41 | { |
| 42 | |
| 43 | extern int udptest_sendcxx . . $ pvpgn/bnetd/udptest_send(b5160de3e9803af4).(t_connectioncxx . . $ pvpgn/bnetd/t_connection# const * c) |
| 44 | { |
| 45 | t_packetcxx . . $ pvpgn/t_packet# * upacket; |
| 46 | struct sockaddr_in caddr; |
| 47 | unsigned int tries, successes; |
| 48 | |
| 49 | stdcxx . . $ std/::memset(&caddr, 0, sizeof(caddr)); |
| 50 | caddr.sin_family = PSOCK_AF_INETcxx . . $ `src/compat/psock.h:189:9`!; |
| 51 | caddr.sin_port = htons(conn_get_game_portcxx . . $ pvpgn/bnetd/conn_get_game_port(70207a9c46bcade7).(c)); |
| 52 | caddr.sin_addr.s_addr = htonl(conn_get_game_addrcxx . . $ pvpgn/bnetd/conn_get_game_addr(8bd2285a65940781).(c)); |
| 53 | |
| 54 | for (tries = successes = 0; successes != 2 && tries < 5; tries++) |
| 55 | { |
| 56 | if (!(upacket = packet_createcxx . . $ pvpgn/packet_create(f721c565085e24c0).(packet_class_udpcxx . . $ pvpgn/packet_class_udp.))) |
| 57 | { |
| 58 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] could not allocate memory for packet", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c)); |
| 59 | continue; |
| 60 | } |
| 61 | packet_set_sizecxx . . $ pvpgn/packet_set_size(a12d8724e4c46208).(upacket, sizeof(t_server_udptestcxx . . $ pvpgn/t_server_udptest#)); |
| 62 | packet_set_typecxx . . $ pvpgn/packet_set_type(a12d8724e4c46208).(upacket, SERVER_UDPTESTcxx . . $ `src/common/udp_protocol.h:52:9`!); |
| 63 | bn_int_tag_set(&upacket->ucxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#u..server_udptestcxx . . $ pvpgn/$anonymous_type_a1640d8ff791e3e5_2#$anonymous_type_3#server_udptest..bnettagcxx . . $ pvpgn/$anonymous_type_68de0d28359c8d56_2#bnettag., BNETTAGcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/tag.h:181:9`!); |
| 64 | |
| 65 | if (hexstrmcxx . . $ hexstrm.) |
| 66 | { |
| 67 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(hexstrmcxx . . $ hexstrm., "%d: send class=%s[0x%02x] type=%s[0x%04x] ", |
| 68 | conn_get_game_socketcxx . . $ pvpgn/bnetd/conn_get_game_socket(b5160de3e9803af4).(c), |
| 69 | packet_get_class_strcxx . . $ pvpgn/packet_get_class_str(a17b58f78809526d).(upacket), (unsigned int)packet_get_classcxx . . $ pvpgn/packet_get_class(6361653567fd72e5).(upacket), |
| 70 | packet_get_type_strcxx . . $ pvpgn/packet_get_type_str(4ae5f643727ae88e).(upacket, packet_dir_from_servercxx . . $ pvpgn/packet_dir_from_server.), packet_get_typecxx . . $ pvpgn/packet_get_type(e4ac9e2b4744cb4b).(upacket)); |
| 71 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(hexstrmcxx . . $ hexstrm., "from=%s ", |
| 72 | addr_num_to_addr_strcxx . . $ pvpgn/addr_num_to_addr_str(9313bf3c546cb16).(conn_get_game_addrcxx . . $ pvpgn/bnetd/conn_get_game_addr(8bd2285a65940781).(c), conn_get_game_portcxx . . $ pvpgn/bnetd/conn_get_game_port(70207a9c46bcade7).(c))); |
| 73 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(hexstrmcxx . . $ hexstrm., "to=%s ", |
| 74 | addr_num_to_addr_strcxx . . $ pvpgn/addr_num_to_addr_str(9313bf3c546cb16).(ntohl(caddr.sin_addr.s_addr), ntohs(caddr.sin_port))); |
| 75 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(hexstrmcxx . . $ hexstrm., "length=%u\n", |
| 76 | packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(upacket)); |
| 77 | hexdumpcxx . . $ pvpgn/hexdump(23ce3b3157473ba).(hexstrmcxx . . $ hexstrm., packet_get_raw_datacxx . . $ pvpgn/packet_get_raw_data(ed324b086ed1b636).(upacket, 0), packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(upacket)); |
| 78 | } |
| 79 | |
| 80 | if (psock_sendtocxx . . $ `src/compat/psock.h:296:9`!(conn_get_game_socket(c), |
| 81 | packet_get_raw_data_const(upacket, 0), packet_get_size(upacket), |
| 82 | 0, (struct sockaddr *)&caddr, (psock_t_socklencxx . . $ `src/compat/psock.h:273:10`!)sizeof(caddr)) != (int)packet_get_sizecxx . . $ pvpgn/packet_get_size(e4ac9e2b4744cb4b).(upacket)) |
| 83 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "[{}] failed to send UDPTEST to {} (attempt {}) (psock_sendto: {})", conn_get_socketcxx . . $ pvpgn/bnetd/conn_get_socket(b5160de3e9803af4).(c), addr_num_to_addr_strcxx . . $ pvpgn/addr_num_to_addr_str(9313bf3c546cb16).(ntohl(caddr.sin_addr.s_addr), conn_get_game_portcxx . . $ pvpgn/bnetd/conn_get_game_port(70207a9c46bcade7).(c)), tries + 1, pstrerrorcxx . . $ `src/compat/strerror.h:33:10`!(psock_errnocxx . . $ `src/compat/psock.h:286:9`!())); |
| 84 | else |
| 85 | successes++; |
| 86 | |
| 87 | packet_del_refcxx . . $ pvpgn/packet_del_ref(d23439d9c1f63082).(upacket); |
| 88 | } |
| 89 | |
| 90 | if (successes != 2) |
| 91 | return -1; |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |
| 98 | } |