@@ -32,6 +32,12 @@ void* request_server_information(void* request_server_information_args_void) {
32
32
return NULL ;
33
33
}
34
34
35
+ SwiftNetDebug (
36
+ if (check_debug_flag (DEBUG_INITIALIZATION )) {
37
+ send_debug_message ("Requested server information: {\"server_ip_address\": \"%s\"}\n" , inet_ntoa (request_server_information_args -> server_addr .sin_addr ));
38
+ }
39
+ )
40
+
35
41
sendto (request_server_information_args -> sockfd , request_server_information_args -> data , request_server_information_args -> size , 0 , (struct sockaddr * )& request_server_information_args -> server_addr , request_server_information_args -> server_addr_len );
36
42
37
43
usleep (1000000 );
@@ -125,16 +131,33 @@ SwiftNetClientConnection* swiftnet_create_client(const char* const restrict ip_a
125
131
while (1 ) {
126
132
const int bytes_received = recvfrom (empty_connection -> sockfd , server_information_buffer , sizeof (server_information_buffer ), 0x00 , NULL , NULL );
127
133
if (bytes_received != PACKET_HEADER_SIZE + sizeof (SwiftNetServerInformation )) {
134
+ SwiftNetDebug (
135
+ if (check_debug_flag (DEBUG_INITIALIZATION )) {
136
+ send_debug_message ("Invalid packet received from server. Expected server information: {\"bytes_received\": %d, \"expected_bytes\": %d}\n" , bytes_received , PACKET_HEADER_SIZE + sizeof (SwiftNetServerInformation ));
137
+ }
138
+ )
128
139
continue ;
129
140
}
130
141
131
- const SwiftNetPacketInfo * const restrict packetInfo = (SwiftNetPacketInfo * )& server_information_buffer [sizeof (struct ip )];
142
+ const struct ip * const restrict ip_header = (struct ip * )& server_information_buffer ;
143
+
144
+ const SwiftNetPacketInfo * const restrict packet_info = (SwiftNetPacketInfo * )& server_information_buffer [sizeof (struct ip )];
132
145
133
- if (packetInfo -> port_info .destination_port != empty_connection -> port_info .source_port || packetInfo -> port_info .source_port != empty_connection -> port_info .destination_port ) {
146
+ if (packet_info -> port_info .destination_port != empty_connection -> port_info .source_port || packet_info -> port_info .source_port != empty_connection -> port_info .destination_port ) {
147
+ SwiftNetDebug (
148
+ if (check_debug_flag (DEBUG_INITIALIZATION )) {
149
+ send_debug_message ("Port info does not match: {\"destination_port\": %d, \"source_port\": %d, \"source_ip_address\": \"%s\"}\n" , packet_info -> port_info .destination_port , packet_info -> port_info .source_port , ip_header -> ip_src .s_addr );
150
+ }
151
+ )
134
152
continue ;
135
153
}
136
154
137
- if (packetInfo -> packet_type != PACKET_TYPE_REQUEST_INFORMATION ) {
155
+ if (packet_info -> packet_type != PACKET_TYPE_REQUEST_INFORMATION ) {
156
+ SwiftNetDebug (
157
+ if (check_debug_flag (DEBUG_INITIALIZATION )) {
158
+ send_debug_message ("Invalid packet type: {\"packet_type\": %d}\n" , packet_info -> packet_type );
159
+ }
160
+ )
138
161
continue ;
139
162
}
140
163
@@ -153,5 +176,11 @@ SwiftNetClientConnection* swiftnet_create_client(const char* const restrict ip_a
153
176
154
177
pthread_create (& empty_connection -> handle_packets_thread , NULL , swiftnet_client_handle_packets , empty_connection );
155
178
179
+ SwiftNetDebug (
180
+ if (check_debug_flag (DEBUG_INITIALIZATION )) {
181
+ send_debug_message ("Successfully initialized client\n" );
182
+ }
183
+ )
184
+
156
185
return empty_connection ;
157
186
}
0 commit comments