}
else if (main->setting.flag & kt_tacocat_main_flag_resolve_classic_e) {
memset(&host, 0, sizeof(struct hostent));
+ memset(&family, 0, sizeof(f_network_family_ip_t));
- port = 0;
address = main->program.parameters.arguments.array[index];
f_char_t address_string[address.used];
- f_string_range_t port_range = f_string_range_t_initialize;
+ f_string_range_double_t range_ip = f_string_range_double_t_initialize;
memcpy(address_string, address.string, address.used);
address.string = address_string;
- f_network_is_ip_address(address, &port, &main->setting.state);
+ f_network_is_ip_address(address, &range_ip, &main->setting.state);
if (F_status_is_error(main->setting.state.status)) {
// @todo print error message about bad port number or similar.
if (main->setting.state.status == F_network_version_four) {
host.h_addrtype = f_socket_address_family_inet4_e;
+ family.type = f_network_family_ip_4_e;
}
else if (main->setting.state.status == F_network_version_six) {
host.h_addrtype = f_socket_address_family_inet6_e;
+ family.type = f_network_family_ip_6_e;
}
else {
host.h_addrtype = 0;
+ family.type = f_network_family_none_e;
}
- kt_tacocat_setting_load_address_port_extract(main, &address, &port, &port_range);
+ kt_tacocat_setting_load_address_port_extract(main, range_ip, &address, &port);
if (F_status_is_error(main->setting.state.status)) {
macro_setting_load_print_first();
- if (port_range.start > port_range.stop) {
+ if (F_status_set_fine(main->setting.state.status) == F_parameter) {
kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(kt_tacocat_setting_load_address_port_extract));
}
else {
- kt_tacocat_print_error_port_number_invalid(&main->program.error, address, port_range);
+ kt_tacocat_print_error_port_number_invalid(&main->program.error, address, range_ip);
}
if (F_status_is_error_not(failed)) {
main->setting.state.status = f_string_dynamic_append(address, &sets[i]->array[j].network);
macro_setting_load_handle_send_receive_error_continue_2(f_string_dynamic_append);
+
+ main->setting.state.status = f_network_from_ip_string(address, &family);
+
+ macro_setting_load_handle_send_receive_error_continue_2(f_network_from_ip_string);
}
else {
main->setting.state.status = f_network_from_ip_name(address, &host);
macro_setting_load_handle_send_receive_error_continue_2(f_memory_array_increase_by);
- if (host.h_addrtype == f_socket_address_family_inet4_e) {
- family.type = f_network_family_ip_4_e;
- family.address.v4 = *((struct in_addr *) host.h_addr_list[k]);
- }
- else {
- family.type = f_network_family_ip_6_e;
- family.address.v6 = *((struct in6_addr *) host.h_addr_list[k]);
- }
-
main->setting.state.status = f_network_to_ip_string(family, &sets[i]->array[j].network);
if (main->setting.state.status == F_data_not || !host.h_addr_list || !host.h_addr_list[0]) {
if (host.h_addrtype == f_socket_address_family_inet4_e) {
sets[i]->array[j].socket.domain = f_socket_protocol_family_inet4_e;
sets[i]->array[j].socket.address.inet4.sin_port = htons((in_port_t) port);
- sets[i]->array[j].socket.address.inet4.sin_addr.s_addr = INADDR_ANY;
+ sets[i]->array[j].socket.address.inet4.sin_addr.s_addr = family.address.v4.s_addr;
}
else if (host.h_addrtype == f_socket_address_family_inet6_e) {
sets[i]->array[j].socket.domain = f_socket_protocol_family_inet6_e;
sets[i]->array[j].socket.address.inet6.sin6_port = htons((in_port_t) port);
- sets[i]->array[j].socket.address.inet6.sin6_addr = in6addr_any;
+ sets[i]->array[j].socket.address.inet6.sin6_addr = family.address.v6;
}
}
else {
#endif // _di_kt_tacocat_setting_load_send_receive_
#ifndef _di_kt_tacocat_setting_load_address_port_extract_
- void kt_tacocat_setting_load_address_port_extract(kt_tacocat_main_t * const main, f_string_static_t * const address, f_number_unsigned_t * const port, f_string_range_t * const port_range) {
+ void kt_tacocat_setting_load_address_port_extract(kt_tacocat_main_t * const main, const f_string_range_double_t range_ip, f_string_static_t * const address, f_number_unsigned_t * const port) {
if (!main) return;
- if (!address || !port || !port_range) {
+ if (!address || !port) {
main->setting.state.status = F_status_set_error(F_parameter);
return;
return;
}
- port_range->stop = address->used;
-
if (main->setting.state.status == F_network_version_four || main->setting.state.status == F_network_version_six) {
- port_range->start = 0;
-
- if (*port) {
- port_range->start = *port;
+ if (range_ip.start_2 <= range_ip.stop_2) {
*port = 0;
- const f_string_static_t adjusted = macro_f_string_static_t_initialize_1(address->string + port_range->start, 0, address->used - port_range->start);
+ {
+ const f_string_static_t adjusted = macro_f_string_static_t_initialize_1(address->string + range_ip.start_2, 0, (range_ip.start_2 - range_ip.stop_2) + 1);
- main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, adjusted, port);
- if (F_status_is_error(main->setting.state.status)) return;
+ main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, adjusted, port);
+ if (F_status_is_error(main->setting.state.status)) return;
+ }
- address->string[port_range->start] = 0;
- address->used = port_range->start;
+ address->string[range_ip.start_2] = 0;
+ address->used = range_ip.start_2;
while (address->used && address->string[address->used] != f_string_ascii_colon_s.string[0]) --address->used;
+
+ // Be sure to also remove the colon.
+ if (address->used) {
+ address->string[address->used--] = 0;
+ }
}
main->setting.state.status = F_okay;
return;
}
- *port = 0;
- port_range->start = address->used;
-
- while (--port_range->start) {
- if (address->string[port_range->start] == f_string_ascii_colon_s.string[0]) break;
- } // while
-
- if (port_range->start && ++port_range->start < address->used) {
- const f_string_static_t adjusted = macro_f_string_static_t_initialize_1(address->string + port_range->start, 0, address->used - port_range->start);
-
- main->setting.state.status = fl_conversion_dynamic_to_unsigned_detect(fl_conversion_data_base_10_c, adjusted, port);
- if (F_status_is_error(main->setting.state.status)) return;
-
- address->string[--port_range->start] = 0;
- address->used = port_range->start;
- main->setting.state.status = F_okay;
- }
- else {
- main->setting.state.status = F_number_not;
- }
+ main->setting.state.status = F_number_not;
}
#endif // _di_kt_tacocat_setting_load_address_port_extract_
#endif // _di_kt_tacocat_print_error_parameter_value_resolve_unknown_
#ifndef _di_kt_tacocat_print_error_port_number_invalid_
- f_status_t kt_tacocat_print_error_port_number_invalid(fl_print_t * const print, const f_string_static_t address, const f_string_range_t port_range) {
+ f_status_t kt_tacocat_print_error_port_number_invalid(fl_print_t * const print, const f_string_static_t address, const f_string_range_double_t range_ip) {
if (!print || !print->custom) return F_status_set_error(F_output_not);
if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
kt_tacocat_main_t * const main = (kt_tacocat_main_t *) print->custom;
+ const f_string_range_t range = macro_f_string_range_t_initialize_1(range_ip.start_2, range_ip.stop_2);
+
f_file_stream_lock(print->to);
fl_print_format("%[%QUnknown or invalid port number%] ", print->to, print->set->error, print->prefix, print->set->error);
- fl_print_format("%[%/Q%]", print->to, print->set->notable, address, port_range, print->set->notable);
+ fl_print_format("%[%/Q%]", print->to, print->set->notable, address, range, print->set->notable);
fl_print_format(" %[from the address '%]", print->to, print->set->error, print->set->error, f_string_eol_s);
fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, address, print->set->notable);
fl_print_format("%['.%]%r", print->to, print->set->error, print->set->error, f_string_eol_s);
continue;
}
- // The id_data socket ID is the same when sending (writing) to the socket.
- main->setting.send.array[i].socket.id_data = main->setting.send.array[i].socket.id;
-
// Make the socket re-usable.
{
value_socket = 1;
for (main->setting.send.array[i].retry = 0; main->setting.send.array[i].retry < kt_tacocat_startup_retry_max_d; ++main->setting.send.array[i].retry) {
if (main->setting.send.array[i].socket.domain == f_socket_protocol_family_inet4_e || main->setting.send.array[i].socket.domain == f_socket_protocol_family_inet6_e || main->setting.send.array[i].socket.domain == f_socket_protocol_family_local_e) {
- main->setting.send.array[i].status = f_socket_connect(main->setting.send.array[i].socket);
+ main->setting.send.array[i].status = f_socket_connect(main->setting.send.array[i].socket); // @fixme this is currently failing because part of the parameters is invalid (figure out why).
+
+ // The id_data socket ID is the same when sending (writing) to the socket.
+ if (F_status_is_error_not(main->setting.send.array[i].status)) {
+ main->setting.send.array[i].socket.id_data = main->setting.send.array[i].socket.id;
+ }
+
+ // Treat invalid file descriptor as an error as the descriptor should be valid at this point in time.
+ if (main->setting.send.array[i].status == F_file_descriptor) {
+ main->setting.send.array[i].status = F_status_set_error(F_file_descriptor);
+ }
}
else {
main->setting.status_send = F_status_set_error(F_parameter);
main->setting.send_polls.array[i].revents = 0;
}
else {
+ // @todo do not forget to utilize the poll fd.
main->setting.send_polls.array[i].fd = main->setting.send.array[i].socket.id;
main->setting.send_polls.array[i].events = f_poll_write_e;
main->setting.send_polls.array[i].revents = 0;