]> Kevux Git Server - kevux-tools/commitdiff
Progress: Further work in TacocaT.
authorKevin Day <kevin@kevux.org>
Sat, 8 Jul 2023 03:40:09 +0000 (22:40 -0500)
committerKevin Day <kevin@kevux.org>
Sat, 8 Jul 2023 03:40:09 +0000 (22:40 -0500)
Do more of the needed configuration.
Call the appropriate bind functions.

sources/c/tacocat/main/common.c
sources/c/tacocat/main/common/define.h
sources/c/tacocat/main/common/print.c
sources/c/tacocat/main/common/print.h
sources/c/tacocat/main/process.c

index cd652e1d732514ed73927a624151b5372bef370f..60ae83f871bd139bac5d7a946c39237909489d23 100644 (file)
@@ -264,6 +264,12 @@ extern "C" {
 
                 macro_setting_load_handle_send_receive_error_continue_basic(f_string_dynamic_append_nulless);
               }
+
+              strings[i]->array[j].string[strings[i]->array[j].used] = 0;
+              sockets[i]->array[j].domain = f_socket_protocol_family_local_e;
+              sockets[i]->array[j].protocol = f_socket_protocol_tcp_e;
+              sockets[i]->array[j].type = f_socket_address_family_local_e;
+              sockets[i]->array[j].name = strings[i]->array[j];
             }
             else if (main->setting.flag & kt_tacocat_main_flag_resolve_classic_e) {
               memset(&host, 0, sizeof(struct hostent));
@@ -287,7 +293,7 @@ extern "C" {
               }
 
               // Two is added to support a trailing NULL and a type character.
-              main->setting.state.status = f_string_dynamic_increase_by(INET6_ADDRSTRLEN + 2, &strings[i]->array[j]);
+              main->setting.state.status = f_string_dynamic_increase_by(INET6_ADDRSTRLEN + 1, &strings[i]->array[j]);
 
               macro_setting_load_handle_send_receive_error_continue_basic(f_string_dynamic_increase_by);
 
@@ -306,11 +312,11 @@ extern "C" {
               }
 
               // Two is added to support a trailing NULL and a type character.
-              main->setting.state.status = f_string_dynamic_increase_by(INET6_ADDRSTRLEN + 2, &strings[i]->array[j]);
+              main->setting.state.status = f_string_dynamic_increase_by(INET6_ADDRSTRLEN + 1, &strings[i]->array[j]);
 
               macro_setting_load_handle_send_receive_error_continue_basic(f_string_dynamic_increase_by);
 
-              if (host.h_addrtype == AF_INET) {
+              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]);
               }
@@ -334,11 +340,20 @@ extern "C" {
                 continue;
               }
 
-              // The terminating NULL, past the used length.
               strings[i]->array[j].string[strings[i]->array[j].used] = 0;
-              strings[i]->array[j].string[strings[i]->array[j].used + 1] = (family.type & f_network_family_ip_4_e)
-                ? f_string_ascii_4_s.string[0]
-                : f_string_ascii_6_s.string[0];
+              sockets[i]->array[j].protocol = f_socket_protocol_tcp_e;
+              sockets[i]->array[j].type = host.h_addrtype;
+
+              if (host.h_addrtype == f_socket_address_family_inet4_e) {
+                sockets[i]->array[j].domain = f_socket_protocol_family_inet4_e;
+                sockets[i]->array[j].address.inet4.sin_port = 0; // @todo detect and pull port number from host name if supplied.
+                sockets[i]->array[j].address.inet4.sin_addr.s_addr = INADDR_ANY;
+              }
+              else if (host.h_addrtype == f_socket_address_family_inet6_e) {
+                sockets[i]->array[j].domain = f_socket_protocol_family_inet6_e;
+                sockets[i]->array[j].address.inet6.sin6_port = 0; // @todo detect and pull port number from host name if supplied.
+                sockets[i]->array[j].address.inet6.sin6_addr = in6addr_any;
+              }
             }
             else {
               // @todo Kevux DNS resolution.
index c927259aacbf2e048032de23186cebad0b151d97..5fafccbce35a22ac50d9c655df5a6f15bc6e2c56 100644 (file)
@@ -24,24 +24,29 @@ extern "C" {
  *   - large:   An allocation step used for buffers that are anticipated to have large buffers.
  *   - small:   An allocation step used for buffers that are anticipated to have small buffers.
  *
- * kt_tacocat_signal_*_d:
- *   - check:          When not using threads, this is how often to perform the check (lower numbers incur more kernel I/O).
- *   - check_failsafe: When using threads, how many consecutive failures to check signal before aborting (as a recursion failsafe).
+ * kt_tacocat_backlog_*_d:
+ *   - max: The max backlog size to use.
  *
  * kt_tacocat_block_size_*_d:
  *   - receive: The block size in bytes to use when sending packets.
  *   - send:    The block size in bytes to use when receiving packets.
+ *
+ * kt_tacocat_signal_*_d:
+ *   - check:          When not using threads, this is how often to perform the check (lower numbers incur more kernel I/O).
+ *   - check_failsafe: When using threads, how many consecutive failures to check signal before aborting (as a recursion failsafe).
  */
 #ifndef _di_kt_tacocat_d_
   #define kt_tacocat_allocation_console_d 4
   #define kt_tacocat_allocation_large_d   2048
   #define kt_tacocat_allocation_small_d   128
 
-  #define kt_tacocat_signal_check_d          20000
-  #define kt_tacocat_signal_check_failsafe_d 20000
+  #define kt_tacocat_backlog_max_d 1024
 
   #define kt_tacocat_block_size_receive_d 65535
   #define kt_tacocat_block_size_send_d    65535
+
+  #define kt_tacocat_signal_check_d          20000
+  #define kt_tacocat_signal_check_failsafe_d 20000
 #endif // _di_kt_tacocat_d_
 
 /**
index 01e38a28333b5412fffb99f9054bad2d9bd76799..94f0aed84999fc39def443c92fce5dca30dafabe 100644 (file)
@@ -10,6 +10,9 @@ extern "C" {
     "f_file_open",
     "f_files_increase_by",
     "f_network_from_ip_name",
+    "f_socket_bind_inet4",
+    "f_socket_bind_inet6",
+    "f_socket_bind_local",
     "f_socket_close",
     "f_socket_create",
     "f_socket_disconnect",
index 1d420387e5e9f2e766d1368c032957c4b30c9cd3..36235ed0a18c4045e855f3ddcfbdea130a75f4f6 100644 (file)
@@ -43,6 +43,9 @@ extern "C" {
     kt_tacocat_f_f_file_open_e,
     kt_tacocat_f_f_files_increase_by_e,
     kt_tacocat_f_f_network_from_ip_name_e,
+    kt_tacocat_f_f_socket_bind_inet4_e,
+    kt_tacocat_f_f_socket_bind_inet6_e,
+    kt_tacocat_f_f_socket_bind_local_e,
     kt_tacocat_f_f_socket_close_e,
     kt_tacocat_f_f_socket_create_e,
     kt_tacocat_f_f_socket_disconnect_e,
index 3469a2dee6ce8ff300b0299cb65f24331d4f4f8d..a2dd618a20f2cc67097558113d7ea01623ffb7de 100644 (file)
@@ -30,13 +30,11 @@ extern "C" {
     // @todo Make this threaded, if threading is enabled (if threading is disabled then fork).
     //       TacocaT is intended to be simple, so be lazy and create a thread/fork for every single receive and send.
 
-    // Create socket and connect to socket (bind / listen).
+    // Create, bind, and listen to the socket.
     for (; i < main->setting.socket_receives.used; ++i) {
 
       if (kt_tacocat_signal_check(main)) return;
 
-      // @todo check to see if connection is one of "local", "inet" (ipv4), or "inet6" (ipv6) and configure socket appropriately.
-
       main->setting.status_receives.array[i] = f_socket_create(&main->setting.socket_receives.array[i]);
 
       if (F_status_is_error(main->setting.status_receives.array[i])) {
@@ -47,7 +45,33 @@ extern "C" {
         continue;
       }
 
-      main->setting.status_receives.array[i] = f_socket_listen(&main->setting.socket_receives.array[i], 100); // @todo setup a max back log define rather than hardcode 100 here (and 100 is arbitrarily chosen).
+      if (main->setting.socket_receives.array[i].domain == f_socket_protocol_family_inet4_e) {
+        main->setting.status_receives.array[i] = f_socket_bind_inet4(&main->setting.socket_receives.array[i]);
+      }
+      else if (main->setting.socket_receives.array[i].domain == f_socket_protocol_family_inet6_e) {
+        main->setting.status_receives.array[i] = f_socket_bind_inet6(&main->setting.socket_receives.array[i]);
+      }
+      else if (main->setting.socket_receives.array[i].domain == f_socket_protocol_family_local_e) {
+        main->setting.status_receives.array[i] = f_socket_bind_local(&main->setting.socket_receives.array[i]);
+      }
+      else {
+        // @todo error, not supported.
+      }
+
+      if (F_status_is_error(main->setting.status_receives.array[i])) {
+        main->setting.state.status = main->setting.status_receives.array[i];
+
+        kt_tacocat_print_error(&main->program.error, main->setting.socket_receives.array[i].domain == f_socket_protocol_family_inet4_e
+          ? macro_kt_tacocat_f(f_socket_bind_inet4)
+          : main->setting.socket_receives.array[i].domain == f_socket_protocol_family_inet6_e
+            ? macro_kt_tacocat_f(f_socket_bind_inet6)
+            : macro_kt_tacocat_f(f_socket_bind_local)
+        );
+
+        continue;
+      }
+
+      main->setting.status_receives.array[i] = f_socket_listen(&main->setting.socket_receives.array[i], kt_tacocat_backlog_max_d);
 
       if (F_status_is_error(main->setting.status_receives.array[i])) {
         main->setting.state.status = main->setting.status_receives.array[i];