From 1f4dd9cc4cf59e362f534cd82f178a9c3170d397 Mon Sep 17 00:00:00 2001 From: fanasina Date: Sat, 18 Oct 2025 13:59:26 +0200 Subject: [PATCH] y_socket: add other address: all excluding local address --- .../include/y_socket_t/y_file_handler.h | 1 + y_socket_t/src/y_socket_t/y_file_handler.c | 56 +++++++++++++++++++ y_socket_t/src/y_socket_t/y_list_var_tool.c | 4 +- y_socket_t/src/y_socket_t/y_socket_t.c | 20 +++++++ 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/y_socket_t/include/y_socket_t/y_file_handler.h b/y_socket_t/include/y_socket_t/y_file_handler.h index 433c1f5..25d761c 100644 --- a/y_socket_t/include/y_socket_t/y_file_handler.h +++ b/y_socket_t/include/y_socket_t/y_file_handler.h @@ -27,6 +27,7 @@ struct arg_send_file{ void* y_socket_send_file_for_all_nodes(void* arg); void* y_socket_send_file_for_node(void* arg); void* y_send_buf_for_all_(void* arg); +void* y_send_buf_for_other_(void* arg); enum cmd_type { cmd_update_kill, diff --git a/y_socket_t/src/y_socket_t/y_file_handler.c b/y_socket_t/src/y_socket_t/y_file_handler.c index 0dea6e9..8c59d46 100644 --- a/y_socket_t/src/y_socket_t/y_file_handler.c +++ b/y_socket_t/src/y_socket_t/y_file_handler.c @@ -679,6 +679,62 @@ void* y_send_buf_for_all_(void* arg){ return NULL; } +void* y_send_buf_for_other_(void* arg){ + struct arg_send_file *argS=(struct arg_send_file*)arg; + + struct pollfd *fds=argS->fds; + struct main_list_y_NODE_T *nodes=argS->nodes; +// if(export_nodes_to_file("file_nodes_name", nodes)==-1){ +// fprintf(stderr, "error export_nodes_to_file\n"); +// } + + char * buf_send=argS->filename; +#if TEMP_ADDR + char tempAddr[64]; +#endif + int c_af; +// char host[NI_MAXHOST], service[NI_MAXSERV]; +#if 0 + int status = getnameinfo((struct sockaddr*)&(node.addr), node.addr_len, host, NI_MAXHOST, service, NI_MAXSERV, NI_NUMERICHOST); + if(status) + // printf("debug: status ==0 : success: Received successfully from %s:%s\n", host,service); + // else + fprintf(stderr, "getnameinfo: %s\n", gai_strerror(status)); + + + if(NULL == search_node_in_list_y_NODE_T(nodes, node)) + push_back_list_y_NODE_T(nodes, node); + +#endif + + size_t len_buf_send=strlen(buf_send); + for(struct list_y_NODE_T *local_list_current = nodes->begin_list; local_list_current; local_list_current=local_list_current->next ){ + if(local_list_current->value.local_addr == 0){ + set_addr_str_from_node(tempAddr, local_list_current->value); + c_af=(local_list_current->value).addr.ss_family; + + + if(sendto(fds[(c_af==AF_INET6)].fd, + buf_send, len_buf_send, + 0, + (struct sockaddr*)&((local_list_current->value).addr), + (local_list_current->value).addr_len) != + len_buf_send + ){ + fprintf(stderr, "Error sending %s to %s\n", tempAddr, buf_send); + }/*else{ + printf("debug: sending [%s] -> < %s >",buf_send,tempAddr); + }*/ + + ///printf("debug: for index = %ld\n",local_list_current->index); + } + } + + + + return NULL; +} + /// /// diff --git a/y_socket_t/src/y_socket_t/y_list_var_tool.c b/y_socket_t/src/y_socket_t/y_list_var_tool.c index 3e1a482..fbbf003 100644 --- a/y_socket_t/src/y_socket_t/y_list_var_tool.c +++ b/y_socket_t/src/y_socket_t/y_list_var_tool.c @@ -167,7 +167,9 @@ struct main_list_y_ptr_STRING * split_str_to_main_list_y_ptr_STRING(char *str_or void usage_cmdl(){ printf("usage:\n" "sendto [addr] { \"cmd\" : \"[command]\" }\n" - "addr: ipv4 address or ipv6 address or all to send cmd to all nodes already in the list.\n" + "addr: ipv4 address or ipv6 address \n" + "\tor all to send cmd to all nodes already in the list.\n" + "\tor other to send cmd to all nodes excluding local address in the list.\n" "command: \n" "\tupdate kill: to gracefully shutdown socket server.\n" "\tupdate standby: to suspend all workers, but can receive all task but in queu tasks.\n" diff --git a/y_socket_t/src/y_socket_t/y_socket_t.c b/y_socket_t/src/y_socket_t/y_socket_t.c index c03c642..fb5ae24 100644 --- a/y_socket_t/src/y_socket_t/y_socket_t.c +++ b/y_socket_t/src/y_socket_t/y_socket_t.c @@ -557,6 +557,26 @@ void *y_socket_poll_fds(void *arg){ push_tasQ(argx->tasQ, task_handl); + }else if(strcmp(dst_addr, "other" ) == 0){ + struct arg_send_file *argS = malloc(sizeof(struct arg_send_file)); + argS->fds=fds; + argS->nodes=argSock->nodes; + argS->node=node; + argS->filename=malloc(buf_len-index_buf+1); /* put here message to send for all */ + memcpy(argS->filename, buf+index_buf, buf_len-index_buf); + argS->filename[buf_len-index_buf] = '\0'; + argS->m_ok_head_l_t=m_ok_head_l_t; + + push_back_list_TYPE_PTR(list_arg, argS); + push_back_list_TYPE_PTR(list_arg, argS->filename); + struct y_task_t task_handl = { + .func=y_send_buf_for_other_, + .arg=argS, + .status=TASK_PENDING, + }; + push_tasQ(argx->tasQ, task_handl); + + } else if(set_addr_y_NODE_T_from_str_addr(&node, dst_addr)){ ///printf("debug : set_addr_y_NODE_T done\n");