diff --git a/dap_chain_net.h b/dap_chain_net.h index 71258ab56e098cd46af8bc8e8337c1fe99a38355..0a9bdff765e1b0632e64bf598a7afd7cbe1a2d8e 100644 --- a/dap_chain_net.h +++ b/dap_chain_net.h @@ -23,9 +23,10 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ #pragma once +#ifndef _WIN32 #include <sys/socket.h> #include <netinet/in.h> - +#endif #include <stdint.h> #include <string.h> #include "dap_chain_common.h" @@ -99,16 +100,22 @@ void dap_chain_net_links_connect(dap_chain_net_t * a_net); * @param l_chain * @return */ -static inline char * dap_chain_net_get_gdb_group_mempool(dap_chain_t * l_chain) +DAP_STATIC_INLINE char *dap_chain_net_get_gdb_group_mempool( dap_chain_t *l_chain ) { - dap_chain_net_t * l_net = dap_chain_net_by_id(l_chain->net_id); - char * l_ret = NULL; - if ( l_net ) { - const char c_mempool_group_str[]="mempool"; - size_t l_ret_size = strlen( l_net->pub.gdb_groups_prefix ) + 1 + - strlen( l_chain->name)+1+strlen(c_mempool_group_str)+1; - l_ret = DAP_NEW_Z_SIZE(char, l_ret_size); - snprintf( l_ret,l_ret_size,"%s.chain-%s.%s",l_net->pub.gdb_groups_prefix,l_chain->name,c_mempool_group_str); - } + dap_chain_net_t *l_net = dap_chain_net_by_id( l_chain->net_id ); + + char *l_ret = NULL; + if ( !l_net ) + return (char *)l_net; + + static const char *c_mempool_group_str = "mempool"; + + size_t l_ret_size = strlen( l_net->pub.gdb_groups_prefix ) + 1 + + strlen( l_chain->name) + 1 + strlen(c_mempool_group_str) + 1 + 16; + + l_ret = DAP_NEW_Z_SIZE( char, l_ret_size ); + + dap_snprintf( l_ret, l_ret_size, "%s.chain-%s.%s", l_net->pub.gdb_groups_prefix, l_chain->name, c_mempool_group_str ); + return l_ret; } diff --git a/dap_chain_node.c b/dap_chain_node.c index 8358cc143bbf9255a9a8f9b4a9410ff8ffb54d4b..68436d22441b736aeefc2a47cee8b17486fff6ef 100644 --- a/dap_chain_node.c +++ b/dap_chain_node.c @@ -19,9 +19,28 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ +#include <stdlib.h> +#include <stdio.h> +#include <time.h> +#include <stdlib.h> +#include <stddef.h> +#include <stdint.h> +#include <string.h> + +#ifdef WIN32 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#include <winsock2.h> +#include <windows.h> +#include <mswsock.h> +#include <ws2tcpip.h> +#include <io.h> +#include <wepoll.h> +#include <pthread.h> +#else #include <sys/socket.h> #include <netinet/in.h> -#include <string.h> +#endif #include "dap_hash.h" #include "rand/dap_rand.h" diff --git a/dap_chain_node.h b/dap_chain_node.h index 347aef94b646e580e2508419eefe56dc17d2aa09..0780ba53e070c73ea9a941ef7802bd3974a05d21 100644 --- a/dap_chain_node.h +++ b/dap_chain_node.h @@ -25,9 +25,10 @@ #include <stddef.h> #include <stdbool.h> +#ifndef _WIN32 #include <sys/socket.h> #include <netinet/in.h> - +#endif #include "dap_common.h" #include "dap_chain_common.h" #include "dap_chain_global_db.h" diff --git a/dap_chain_node_cli.c b/dap_chain_node_cli.c index a65be2bba8258c573e80b3100f96c5b938ba79d7..f7ae6d724a01d4e1f877a06f32c7c55630ed2fa5 100644 --- a/dap_chain_node_cli.c +++ b/dap_chain_node_cli.c @@ -23,7 +23,6 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ -#include <pthread.h> #include <stdio.h> #include <string.h> #include <errno.h> @@ -47,10 +46,18 @@ typedef int SOCKET; #define INVALID_SOCKET -1 // for win32 = (SOCKET)(~0) // for Windows #else +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 #include <winsock2.h> -#include <WS2tcpip.h> +#include <windows.h> +#include <mswsock.h> +#include <ws2tcpip.h> +#include <io.h> +#include <wepoll.h> #endif +#include <pthread.h> + #include "iputils/iputils.h" #include "dap_common.h" #include "dap_strfuncs.h" @@ -63,7 +70,14 @@ typedef int SOCKET; #define LOG_TAG "chain_node_cli" -static SOCKET server_sockfd = -1; +#define MAX_CONSOLE_CLIENTS 16 + +static SOCKET server_sockfd = -1; // network or local unix +uint32_t conServPort = 0; + +#ifdef _WIN32 + #define poll WSAPoll +#endif static dap_chain_node_cmd_item_t * s_commands = NULL; @@ -77,7 +91,7 @@ static dap_chain_node_cmd_item_t * s_commands = NULL; * return: >0 if data is present to read * return: -1 if error */ -static int s_poll(int socket, int timeout) +static int s_poll( int socket, int timeout ) { struct pollfd fds; int res; @@ -163,7 +177,7 @@ long s_recv(SOCKET sock, unsigned char *buf, size_t bufsize, int timeout) * timeout - in ms * return: string (if waited for final characters) or NULL, if the string requires deletion */ -char* s_get_next_str(SOCKET nSocket, int *dwLen, const char *stop_str, bool del_stop_str, int timeout) +char* s_get_next_str( SOCKET nSocket, int *dwLen, const char *stop_str, bool del_stop_str, int timeout ) { bool bSuccess = false; long nRecv = 0; // count of bytes received @@ -174,6 +188,7 @@ char* s_get_next_str(SOCKET nSocket, int *dwLen, const char *stop_str, bool del_ size_t lpszBuffer_len = 256; char *lpszBuffer = DAP_NEW_Z_SIZE(char, lpszBuffer_len); // received string will not be larger than MAX_REPLY_LEN + while(1) //nRecv < MAX_REPLY_LEN) { // read one byte @@ -199,7 +214,9 @@ char* s_get_next_str(SOCKET nSocket, int *dwLen, const char *stop_str, bool del_ } } }; + // end reading + if(bSuccess) { // delete the searched string if(del_stop_str) { @@ -215,10 +232,14 @@ char* s_get_next_str(SOCKET nSocket, int *dwLen, const char *stop_str, bool del_ lpszBuffer = DAP_REALLOC(lpszBuffer,(size_t) *dwLen + 1); return lpszBuffer; } + // in case of an error or missing string + if(dwLen) *dwLen = 0; + free(lpszBuffer); + return NULL; } @@ -274,7 +295,7 @@ static void* thread_one_client_func(void *args) unsigned int argc = dap_list_length(list); // command is found if(argc >= 1) { - int l_verbose = 0; + int l_verbose = 0; char *cmd_name = list->data; list = dap_list_next(list); // execute command @@ -308,9 +329,9 @@ static void* thread_one_client_func(void *args) } char *reply_body; if(l_verbose) - reply_body = dap_strdup_printf("%d\r\nret_code: %d\r\n%s\r\n", res, res, (str_reply) ? str_reply : ""); + reply_body = dap_strdup_printf("%d\r\nret_code: %d\r\n%s\r\n", res, res, (str_reply) ? str_reply : ""); else - reply_body = dap_strdup_printf("%d\r\n%s\r\n", res, (str_reply) ? str_reply : ""); + reply_body = dap_strdup_printf("%d\r\n%s\r\n", res, (str_reply) ? str_reply : ""); // return the result of the command function char *reply_str = dap_strdup_printf("HTTP/1.1 200 OK\r\n" "Content-Length: %d\r\n\r\n" @@ -333,6 +354,278 @@ static void* thread_one_client_func(void *args) return NULL; } +#ifdef _WIN32 + +char *p_get_next_str( HANDLE hPipe, int *dwLen, const char *stop_str, bool del_stop_str, int timeout ) +{ + bool bSuccess = false; + long nRecv = 0; // count of bytes received + size_t stop_str_len = (stop_str) ? strlen(stop_str) : 0; + // if there is nothing to look for + + if(!stop_str_len) + return NULL; + + size_t lpszBuffer_len = 256; + char *lpszBuffer = DAP_NEW_Z_SIZE(char, lpszBuffer_len); + // received string will not be larger than MAX_REPLY_LEN + + while( 1 ) //nRecv < MAX_REPLY_LEN) + { + long ret = 0; + // read one byte +// long ret = s_recv( nSocket, (unsigned char *) (lpszBuffer + nRecv), 1, timeout); + + bSuccess = ReadFile( hPipe, lpszBuffer + nRecv, + lpszBuffer_len - nRecv, (LPDWORD)&ret, NULL ); + + //int ret = recv(nSocket,lpszBuffer+nRecv,1, 0); + if ( ret <= 0 || !bSuccess ) + break; + + nRecv += ret; + //printf("**debug** socket=%d read %d bytes '%0s'",nSocket, ret, (lpszBuffer + nRecv)); + + while((nRecv + 1) >= (long) lpszBuffer_len) + { + lpszBuffer_len *= 2; + lpszBuffer = (char*) realloc(lpszBuffer, lpszBuffer_len); + } + + // search for the required string + if(nRecv >= (long) stop_str_len) { + // found the required string + if(!strncasecmp(lpszBuffer + nRecv - stop_str_len, stop_str, stop_str_len)) { + bSuccess = true; + break; + } + } + }; + + // end reading + + if(bSuccess) { + // delete the searched string + if(del_stop_str) { + lpszBuffer[nRecv - (long) stop_str_len] = '\0'; + if(dwLen) + *dwLen =(int) nRecv - (int) stop_str_len; + } + else { + lpszBuffer[nRecv] = '\0'; + if(dwLen) + *dwLen = (int) nRecv; + } + lpszBuffer = DAP_REALLOC(lpszBuffer,(size_t) *dwLen + 1); + return lpszBuffer; + } + + // in case of an error or missing string + + if(dwLen) + *dwLen = 0; + + free(lpszBuffer); + + return NULL; +} + + +/** + * threading function for processing a request from a client + */ +static void *thread_pipe_client_func( void *args ) +{ + HANDLE hPipe = (HANDLE)args; + +// SOCKET newsockfd = (SOCKET) (intptr_t) args; + log_it(L_INFO, "new connection pipe = %X", hPipe ); + + int str_len, marker = 0; + int timeout = 5000; // 5 sec + int argc = 0; + + dap_list_t *cmd_param_list = NULL; + + while( 1 ) + { + // wait data from client +// int is_data = s_poll( newsockfd, timeout ); + // timeout +// if(!is_data) +// continue; + // error (may be socket closed) +// if(is_data < 0) +// break; + +// int is_valid = is_valid_socket(newsockfd); +// if(!is_valid) +// { +// break; +// } + + // receiving http header + char *str_header = p_get_next_str( hPipe, &str_len, "\r\n", true, timeout ); + + // bad format + if(!str_header) + break; + + if ( str_header && strlen(str_header) == 0) { + marker++; + if(marker == 1) + continue; + } + + // filling parameters of command + if ( marker == 1 ) { + cmd_param_list = dap_list_append( cmd_param_list, str_header ); + //printf("g_list_append argc=%d command=%s ", argc, str_header); + argc ++; + } + else + free( str_header ); + + if ( marker == 2 ) { + + dap_list_t *list = cmd_param_list; + // form command + + unsigned int argc = dap_list_length( list ); + // command is found + + if ( argc >= 1) { + + int l_verbose = 0; + char *cmd_name = list->data; + list = dap_list_next( list ); + + // execute command + char *str_cmd = dap_strdup_printf( "%s", cmd_name ); + dap_chain_node_cmd_item_t *l_cmd = dap_chain_node_cli_cmd_find( cmd_name ); + int res = -1; + char *str_reply = NULL; + + if ( l_cmd ) { + + while( list ) { + str_cmd = dap_strdup_printf( "%s;%s", str_cmd, list->data ); + list = dap_list_next(list); + } + + log_it(L_INFO, "execute command = %s", str_cmd ); + // exec command + + char **l_argv = dap_strsplit( str_cmd, ";", -1 ); + // Call the command function + + if ( l_cmd && l_argv && l_cmd->func ) + res = (* (l_cmd->func))( argc, l_argv, &str_reply ); + + else if ( l_cmd ) { + log_it(L_WARNING,"NULL arguments for input for command \"%s\"", str_cmd ); + }else { + log_it(L_WARNING,"No function for command \"%s\" but it registred?!", str_cmd ); + } + + // find '-verbose' command + l_verbose = dap_chain_node_cli_find_option_val( l_argv, 1, argc, "-verbose", NULL ); + dap_strfreev( l_argv ); + + } else { + str_reply = dap_strdup_printf("can't recognize command = %s", str_cmd ); + log_it( L_ERROR, str_reply ); + } + + char *reply_body; + + if(l_verbose) + reply_body = dap_strdup_printf("%d\r\nret_code: %d\r\n%s\r\n", res, res, (str_reply) ? str_reply : ""); + else + reply_body = dap_strdup_printf("%d\r\n%s\r\n", res, (str_reply) ? str_reply : ""); + + // return the result of the command function + char *reply_str = dap_strdup_printf( "HTTP/1.1 200 OK\r\n" + "Content-Length: %d\r\n\r\n" + "%s", + strlen(reply_body), reply_body ); + + int ret;// = send( newsockfd, reply_str, strlen(reply_str) ,0 ); + + WriteFile( hPipe, reply_str, strlen(reply_str), (LPDWORD)&ret, NULL ); + + DAP_DELETE(str_reply); + DAP_DELETE(reply_str); + DAP_DELETE(reply_body); + + DAP_DELETE(str_cmd); + } + dap_list_free_full(cmd_param_list, free); + break; + } + } + + // close connection +// int cs = closesocket(newsockfd); + + log_it( L_INFO, "close connection pipe = %X", hPipe ); + + FlushFileBuffers( hPipe ); + DisconnectNamedPipe( hPipe ); + CloseHandle( hPipe ); + + return NULL; +} + + +/** + * main threading server function pipe win32 + */ +static void* thread_pipe_func( void *args ) +{ + BOOL fConnected = FALSE; + pthread_t threadId; + HANDLE hPipe = INVALID_HANDLE_VALUE, hThread = NULL; + static const char *cPipeName = "\\\\.\\pipe\\node_cli.pipe"; + + for (;;) + { +/// printf( "\nPipe Server: Main thread awaiting client connection on %s\n", lpszPipename ); + + hPipe = CreateNamedPipe( + cPipeName, // pipe name + PIPE_ACCESS_DUPLEX, // read/write access + PIPE_TYPE_MESSAGE | // message type pipe + PIPE_READMODE_MESSAGE | // message-read mode + PIPE_WAIT, // blocking mode + PIPE_UNLIMITED_INSTANCES, // max. instances + 4096, // output buffer size + 4096, // input buffer size + 0, // client time-out + NULL ); // default security attribute + + if ( hPipe == INVALID_HANDLE_VALUE ) { + log_it( L_ERROR, "CreateNamedPipe failed, GLE = %d.\n", GetLastError() ); + return NULL; + } + + fConnected = ConnectNamedPipe( hPipe, NULL ) ? TRUE : ( GetLastError() == ERROR_PIPE_CONNECTED ); + + if ( fConnected ) + { + log_it( L_INFO, "Client %X connected, creating a processing thread.\n", hPipe ); + + pthread_create( &threadId, NULL, thread_pipe_client_func, hPipe ); + pthread_detach( threadId ); + } + else + CloseHandle( hPipe ); + } + + return NULL; +} +#endif + /** * main threading server function */ @@ -340,7 +633,7 @@ static void* thread_main_func(void *args) { SOCKET sockfd = (SOCKET) (intptr_t) args; SOCKET newsockfd; - log_it(L_INFO, "Server start socket=%s", UNIX_SOCKET_FILE); + log_it( L_INFO, "Server start socket = %s", UNIX_SOCKET_FILE ); // wait of clients while(1) { @@ -425,7 +718,7 @@ int dap_chain_node_cli_find_option_val( char** argv, int arg_start, int arg_end, void dap_chain_node_cli_cmd_item_create(const char * a_name, cmdfunc_t *a_func, const char *a_doc, const char *a_doc_ex) { dap_chain_node_cmd_item_t *l_cmd_item = DAP_NEW_Z(dap_chain_node_cmd_item_t); - snprintf(l_cmd_item->name,sizeof (l_cmd_item->name),"%s",a_name); + dap_snprintf(l_cmd_item->name,sizeof (l_cmd_item->name),"%s",a_name); l_cmd_item->doc = strdup( a_doc); l_cmd_item->doc_ex = strdup( a_doc_ex); l_cmd_item->func = a_func; @@ -463,9 +756,20 @@ dap_chain_node_cmd_item_t* dap_chain_node_cli_cmd_find(const char *a_name) */ int dap_chain_node_cli_init(dap_config_t * g_config) { - struct sockaddr_un server = { AF_UNIX, UNIX_SOCKET_FILE }; - //server.sun_family = AF_UNIX; - //strcpy(server.sun_path, SOCKET_FILE); +#ifndef _WIN32 + struct sockaddr_un lserver_addr = { AF_UNIX, UNIX_SOCKET_FILE }; +#endif + struct sockaddr_in server_addr; + SOCKET sockfd = -1; + + bool bConServerEnabled = dap_config_get_item_bool_default( g_config, "conserver", "enabled", true ); + + if ( !bConServerEnabled ) { + + log_it( L_WARNING, "Console Server is dissabled." ); + return 0; + } + dap_chain_node_cli_cmd_item_create ("global_db", com_global_db, "Work with global database", "global_db wallet_info set -addr <wallet address> -cell <cell id> \n\n" "global_db cells add -cell <cell id> \n\n" @@ -473,6 +777,7 @@ int dap_chain_node_cli_init(dap_config_t * g_config) "global_db node del -net <net name> -addr <node address> | -alias <node alias>\n\n" "global_db node link {add|del} -net <net name> {-addr <node address> | -alias <node alias>} -link <node address>\n\n" ); + dap_chain_node_cli_cmd_item_create ("node", com_node, "Work with node", "node alias {<node address> | -alias <node alias>}\n\n" "node connect {<node address> | -alias <node alias>}\n\n" @@ -534,47 +839,98 @@ int dap_chain_node_cli_init(dap_config_t * g_config) dap_chain_node_cli_cmd_item_create ("print_log", com_print_log, "Print log info", "print_log [ts_after <timestamp >] [limit <line numbers>]\n" ); + // create thread for waiting of clients + pthread_t threadId; - // init client for handshake + conServPort = (uint16_t)dap_config_get_item_int32_default( g_config, "conserver", "listen_port_tcp", 0 ); - SOCKET sockfd; + if ( !conServPort ) { - if(server_sockfd >= 0) { - dap_chain_node_cli_delete(); - server_sockfd = 0; - } + log_it( L_INFO, "Console Server port 0 - local mode" ); + + #ifndef _WIN32 + + if ( server_sockfd >= 0 ) { + dap_chain_node_cli_delete( ); + server_sockfd = 0; + } + + // create socket + sockfd = socket( AF_UNIX, SOCK_STREAM, 0 ); + if( sockfd == INVALID_SOCKET ) + return -1; + + int gdsg = sizeof(struct sockaddr_un); + + if ( access( UNIX_SOCKET_FILE, R_OK) != -1 ) + unlink( UNIX_SOCKET_FILE ); + + // connecting the address with a socket + if( bind(sockfd, (const struct sockaddr*) &server, sizeof(struct sockaddr_un)) == SOCKET_ERROR) { + // errno = EACCES 13 Permission denied + if ( errno == EACCES ) // EACCES=13 + log_it( L_ERROR, "Server can't start(err=%d). Can't create file=%s [Permission denied]", errno, + UNIX_SOCKET_FILE ); + else + log_it( L_ERROR, "Server can't start(err=%d). May be problem with file=%s?", errno, UNIX_SOCKET_FILE ); + closesocket( sockfd ); + return -1; + } + + #else + + Sleep( 3000 ); + + if( pthread_create(&threadId, NULL, thread_pipe_func, (void*) (intptr_t) sockfd) != 0 ) { + closesocket( sockfd ); + return -1; + } + + return 0; + #endif - // create socket - if((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == INVALID_SOCKET) - return -1; - int gdsg = sizeof(struct sockaddr_un); - if(access( UNIX_SOCKET_FILE, R_OK) != -1) - { - unlink(UNIX_SOCKET_FILE); } - // connecting the address with a socket - if(bind(sockfd, (const struct sockaddr*) &server, sizeof(struct sockaddr_un)) == SOCKET_ERROR) { - // errno = EACCES 13 Permission denied - if(errno == EACCES) // EACCES=13 - log_it(L_ERROR, "Server can't start(err=%d). Can't create file=%s [Permission denied]", errno, - UNIX_SOCKET_FILE); - else - log_it(L_ERROR, "Server can't start(err=%d). May be problem with file=%s?", errno, UNIX_SOCKET_FILE); - closesocket(sockfd); - return -1; + else { + + char *listen_addr = dap_config_get_item_str_default( g_config, + "conserver", + "listen_address", + "0.0.0.0" ); + + log_it( L_INFO, "Console Server: listen addr %s:%u ", listen_addr, conServPort ); + + server_addr.sin_family = AF_INET; + inet_pton( AF_INET, listen_addr, &server_addr.sin_addr ); + //server.sin_addr.s_addr = htonl( INADDR_ANY ); + server_addr.sin_port = htons( (uint16_t)conServPort ); + + // create socket + if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET ) { + log_it( L_ERROR, "Console Server: can't create socket, err %X", errno ); + return -1; + } + + // connecting the address with a socket + if ( bind(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) == SOCKET_ERROR ) { + log_it( L_ERROR, "Console Server: can't bind socket, err %X", errno ); + closesocket( sockfd ); + return -1; + } } + // turn on reception of connections - if(listen(sockfd, 5) == SOCKET_ERROR) + if( listen(sockfd, MAX_CONSOLE_CLIENTS) == SOCKET_ERROR ) return -1; - // create thread for waiting of clients - pthread_t threadId; - if(pthread_create(&threadId, NULL, thread_main_func, (void*) (intptr_t) sockfd) != 0) { - closesocket(sockfd); + + if( pthread_create(&threadId, NULL, thread_main_func, (void*) (intptr_t) sockfd) != 0 ) { + closesocket( sockfd ); return -1; } + // in order to thread not remain in state "dead" after completion - pthread_detach(threadId); + pthread_detach( threadId ); server_sockfd = sockfd; + return 0; } diff --git a/dap_chain_node_cli.h b/dap_chain_node_cli.h index 327819df15239d63e64893c60a6ca082e834b9e9..58233869048cd06fdf98fd7f597fa6b40f0a4bd2 100644 --- a/dap_chain_node_cli.h +++ b/dap_chain_node_cli.h @@ -28,7 +28,9 @@ #include "dap_common.h" #include "dap_config.h" #include "uthash.h" + #define UNIX_SOCKET_FILE "/opt/kelvin-node/var/run/node_cli.sock" + //#define UNIX_SOCKET_FILE "/var/run/node_cli.sock" typedef int cmdfunc_t(int argc, char ** argv, char **str_reply); diff --git a/dap_chain_node_cli_cmd.c b/dap_chain_node_cli_cmd.c index 015907c10ff0619beafe27c6053f12a70570d57d..2b8205f0eecf42627350a97d42ba44e760042110 100644 --- a/dap_chain_node_cli_cmd.c +++ b/dap_chain_node_cli_cmd.c @@ -23,20 +23,35 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ -#include <sys/types.h> -#include <arpa/inet.h> -#include <netinet/in.h> - +#include <stdlib.h> #include <stdio.h> +#include <time.h> #include <stdlib.h> +#include <stddef.h> +#include <stdint.h> #include <string.h> #include <stdbool.h> #include <errno.h> #include <assert.h> -#include <time.h> #include <ctype.h> #include <dirent.h> +#ifdef WIN32 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#include <winsock2.h> +#include <windows.h> +#include <mswsock.h> +#include <ws2tcpip.h> +#include <io.h> +#include <wepoll.h> +#include <pthread.h> +#else +#include <sys/types.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#endif + #include "iputils/iputils.h" #include "uthash.h" @@ -920,6 +935,7 @@ int com_node(int a_argc, char ** a_argv, char **a_str_reply) */ int com_traceroute(int argc, char** argv, char **str_reply) { +#ifndef _WIN32 const char *addr = NULL; int hops = 0, time_usec = 0; if(argc > 1) @@ -987,6 +1003,8 @@ int com_traceroute(int argc, char** argv, char **str_reply) } } return res; +#endif +return 0; } /** @@ -996,6 +1014,7 @@ int com_traceroute(int argc, char** argv, char **str_reply) */ int com_tracepath(int argc, char** argv, char **str_reply) { +#ifndef _WIN32 const char *addr = NULL; int hops = 0, time_usec = 0; if(argc > 1) @@ -1058,6 +1077,8 @@ int com_tracepath(int argc, char** argv, char **str_reply) } } return res; +#endif + return 0; } /** @@ -1067,6 +1088,8 @@ int com_tracepath(int argc, char** argv, char **str_reply) */ int com_ping(int argc, char** argv, char **str_reply) { +#ifndef _WIN32 + int n = 4; if(argc < 2) { dap_chain_node_cli_set_reply_text(str_reply, "host not specified"); @@ -1116,6 +1139,8 @@ int com_ping(int argc, char** argv, char **str_reply) } } return res; +#endif +return 0; } /** @@ -1272,7 +1297,7 @@ int com_tx_wallet(int argc, char ** argv, char **str_reply) char *l_addr_str = dap_chain_addr_to_str((dap_chain_addr_t*) l_addr); if(l_wallet) dap_string_append_printf(l_string_ret, "wallet: %s\n", l_wallet->name); - //dap_string_append_printf(l_string_ret, "addr: %s\n", (l_addr_str) ? l_addr_str : "-"); + dap_string_append_printf(l_string_ret, "addr: %s\n", (l_addr_str) ? l_addr_str : "-"); size_t l_addr_tokens_size = 0; char **l_addr_tokens = NULL; @@ -1796,7 +1821,7 @@ int com_token_decl(int argc, char ** argv, char ** str_reply) // Create new datum token dap_chain_datum_token_t * l_datum_token = DAP_NEW_Z_SIZE(dap_chain_datum_token_t, sizeof(l_datum_token->header)); l_datum_token->header.version = 1; // Current version - snprintf(l_datum_token->header.ticker, sizeof(l_datum_token->header.ticker), "%s", l_ticker); + dap_snprintf(l_datum_token->header.ticker, sizeof(l_datum_token->header.ticker), "%s", l_ticker); l_datum_token->header.total_supply = l_total_supply; l_datum_token->header.signs_total = l_signs_total; l_datum_token->header.signs_valid = l_signs_emission; diff --git a/dap_chain_node_client.c b/dap_chain_node_client.c index 25dce5bc72c2a8e3736ed22e50a77d6f5f110a20..ec4641f16d9bbd24838f7269fa6d89f7aed24745 100644 --- a/dap_chain_node_client.c +++ b/dap_chain_node_client.c @@ -19,13 +19,27 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ -#include <stdint.h> #include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <errno.h> -#include <glib.h> +#include <stdio.h> #include <time.h> +#include <stdlib.h> +#include <stddef.h> +#include <stdint.h> +#include <errno.h> +#include <assert.h> +#include <string.h> + +#ifdef WIN32 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#include <winsock2.h> +#include <windows.h> +#include <mswsock.h> +#include <ws2tcpip.h> +#include <io.h> +#include <wepoll.h> +#include <pthread.h> +#endif #include "dap_common.h" #include "dap_client.h" @@ -174,7 +188,7 @@ static void s_ch_chain_callback_notify_packet_in(dap_stream_ch_chain_t* a_ch_cha case DAP_STREAM_CH_CHAIN_NET_PKT_TYPE_ERROR: pthread_mutex_lock(&l_node_client->wait_mutex); l_node_client->state = NODE_CLIENT_STATE_ERROR ; - snprintf(l_node_client->last_error,sizeof (l_node_client->last_error), + dap_snprintf(l_node_client->last_error,sizeof (l_node_client->last_error), "%s", (char*) a_pkt->data ); log_it(L_WARNING,"Received packet DAP_STREAM_CH_CHAIN_NET_PKT_TYPE_ERROR with error \"%s\"", l_node_client->last_error); diff --git a/dap_chain_node_remote.c b/dap_chain_node_remote.c index be119272751f27f5a7cf2cadc868371b8c80c872..515d1123b8f99cb0effe8f4c77fb3fad138a2a1c 100644 --- a/dap_chain_node_remote.c +++ b/dap_chain_node_remote.c @@ -19,11 +19,25 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ -#include <stdint.h> #include <stdlib.h> -#include <string.h> +#include <stdio.h> +#include <time.h> +#include <stdlib.h> +#include <stddef.h> +#include <stdint.h> #include <pthread.h> +#ifdef WIN32 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#include <winsock2.h> +#include <windows.h> +#include <mswsock.h> +#include <ws2tcpip.h> +#include <io.h> +#include <wepoll.h> +#endif + #include "uthash.h" #include "dap_common.h" #include "dap_chain_node_remote.h" diff --git a/iputils/ping.h b/iputils/ping.h index e2923cd4c041b567ddd9319dfa2efc619b69a3ed..ddc445f9322fb63c089f50272e27b637adf55aa1 100644 --- a/iputils/ping.h +++ b/iputils/ping.h @@ -1,14 +1,26 @@ + #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <time.h> #include <signal.h> #include <poll.h> + #include <sys/param.h> #include <sys/socket.h> + +#define __USE_GNU + +#include <netinet/in.h> +#include <netinet/ip.h> +#include <netinet/ip6.h> +#include <netinet/ip_icmp.h> +#include <netinet/icmp6.h> + +#include <linux/filter.h> #include <linux/types.h> #include <linux/sockios.h> -# define __USE_KERNEL_IPV6_DEFS + #include <sys/file.h> #include <sys/time.h> #include <sys/ioctl.h> @@ -19,16 +31,11 @@ #include <string.h> #include <netdb.h> #include <setjmp.h> -#include <netinet/icmp6.h> + #include <asm/byteorder.h> #include <sched.h> #include <math.h> -#include <netinet/ip.h> -#include <netinet/ip6.h> -#include <netinet/ip_icmp.h> -#include <netinet/icmp6.h> -#include <linux/filter.h> #include <resolv.h> #include "iputils.h" @@ -77,56 +84,56 @@ #define SCOPE_DELIMITER '%' #endif -#define DEFDATALEN (64 - 8) /* default data length */ +#define DEFDATALEN (64 - 8) /* default data length */ -#define MAXWAIT 10 /* max seconds to wait for response */ -#define MININTERVAL 10 /* Minimal interpacket gap */ -#define MINUSERINTERVAL 200 /* Minimal allowed interval for non-root */ +#define MAXWAIT 10 /* max seconds to wait for response */ +#define MININTERVAL 10 /* Minimal interpacket gap */ +#define MINUSERINTERVAL 200 /* Minimal allowed interval for non-root */ -#define SCHINT(a) (((a) <= MININTERVAL) ? MININTERVAL : (a)) +#define SCHINT(a) (((a) <= MININTERVAL) ? MININTERVAL : (a)) /* various options */ extern int options; -#define F_FLOOD 0x001 -#define F_INTERVAL 0x002 -#define F_NUMERIC 0x004 -#define F_PINGFILLED 0x008 -#define F_QUIET 0x010 -#define F_RROUTE 0x020 -#define F_SO_DEBUG 0x040 -#define F_SO_DONTROUTE 0x080 -#define F_VERBOSE 0x100 -#define F_TIMESTAMP 0x200 -#define F_SOURCEROUTE 0x400 -#define F_FLOOD_POLL 0x800 -#define F_LATENCY 0x1000 -#define F_AUDIBLE 0x2000 -#define F_ADAPTIVE 0x4000 -#define F_STRICTSOURCE 0x8000 -#define F_NOLOOP 0x10000 -#define F_TTL 0x20000 -#define F_MARK 0x40000 -#define F_PTIMEOFDAY 0x80000 -#define F_OUTSTANDING 0x100000 -#define F_FLOWINFO 0x200000 -#define F_TCLASS 0x400000 +#define F_FLOOD 0x001 +#define F_INTERVAL 0x002 +#define F_NUMERIC 0x004 +#define F_PINGFILLED 0x008 +#define F_QUIET 0x010 +#define F_RROUTE 0x020 +#define F_SO_DEBUG 0x040 +#define F_SO_DONTROUTE 0x080 +#define F_VERBOSE 0x100 +#define F_TIMESTAMP 0x200 +#define F_SOURCEROUTE 0x400 +#define F_FLOOD_POLL 0x800 +#define F_LATENCY 0x1000 +#define F_AUDIBLE 0x2000 +#define F_ADAPTIVE 0x4000 +#define F_STRICTSOURCE 0x8000 +#define F_NOLOOP 0x10000 +#define F_TTL 0x20000 +#define F_MARK 0x40000 +#define F_PTIMEOFDAY 0x80000 +#define F_OUTSTANDING 0x100000 +#define F_FLOWINFO 0x200000 +#define F_TCLASS 0x400000 /* * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum * number of received sequence numbers we can keep track of. */ -#define MAX_DUP_CHK 0x10000 +#define MAX_DUP_CHK 0x10000 #if defined(__WORDSIZE) && __WORDSIZE == 64 # define USE_BITMAP64 #endif #ifdef USE_BITMAP64 -typedef uint64_t bitmap_t; -# define BITMAP_SHIFT 6 +typedef uint64_t bitmap_t; +# define BITMAP_SHIFT 6 #else -typedef uint32_t bitmap_t; -# define BITMAP_SHIFT 5 +typedef uint32_t bitmap_t; +# define BITMAP_SHIFT 5 #endif #if ((MAX_DUP_CHK >> (BITMAP_SHIFT + 3)) << (BITMAP_SHIFT + 3)) != MAX_DUP_CHK @@ -134,67 +141,67 @@ typedef uint32_t bitmap_t; #endif struct rcvd_table { - bitmap_t bitmap[MAX_DUP_CHK / (sizeof(bitmap_t) * 8)]; + bitmap_t bitmap[MAX_DUP_CHK / (sizeof(bitmap_t) * 8)]; }; extern struct rcvd_table rcvd_tbl; -#define A(bit) (rcvd_tbl.bitmap[(bit) >> BITMAP_SHIFT]) /* identify word in array */ -#define B(bit) (((bitmap_t)1) << ((bit) & ((1 << BITMAP_SHIFT) - 1))) /* identify bit in word */ +#define A(bit) (rcvd_tbl.bitmap[(bit) >> BITMAP_SHIFT]) /* identify word in array */ +#define B(bit) (((bitmap_t)1) << ((bit) & ((1 << BITMAP_SHIFT) - 1))) /* identify bit in word */ static inline void rcvd_set(uint16_t seq) { - unsigned bit = seq % MAX_DUP_CHK; - A(bit) |= B(bit); + unsigned bit = seq % MAX_DUP_CHK; + A(bit) |= B(bit); } static inline void rcvd_clear(uint16_t seq) { - unsigned bit = seq % MAX_DUP_CHK; - A(bit) &= ~B(bit); + unsigned bit = seq % MAX_DUP_CHK; + A(bit) &= ~B(bit); } static inline bitmap_t rcvd_test(uint16_t seq) { - unsigned bit = seq % MAX_DUP_CHK; - return A(bit) & B(bit); + unsigned bit = seq % MAX_DUP_CHK; + return A(bit) & B(bit); } #ifndef HAVE_ERROR_H static void error(int status, int errnum, const char *format, ...) { - va_list ap; - - fprintf(stderr, "ping: "); - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - if (errnum) - fprintf(stderr, ": %s\n", strerror(errnum)); - else - fprintf(stderr, "\n"); - if (status) - exit(status); + va_list ap; + + fprintf(stderr, "ping: "); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + if (errnum) + fprintf(stderr, ": %s\n", strerror(errnum)); + else + fprintf(stderr, "\n"); + if (status) + exit(status); } #endif extern int datalen; extern char *hostname; extern int uid; -extern int ident; /* process id to identify our packets */ +extern int ident; /* process id to identify our packets */ extern int sndbuf; extern int ttl; -extern long npackets; /* max packets to transmit */ -extern long nreceived; /* # of packets we got back */ -extern long nrepeats; /* number of duplicates */ -extern long ntransmitted; /* sequence # for outbound packets = #sent */ -extern long nchecksum; /* replies with bad checksum */ -extern long nerrors; /* icmp errors */ -extern int interval; /* interval between packets (msec) */ +extern long npackets; /* max packets to transmit */ +extern long nreceived; /* # of packets we got back */ +extern long nrepeats; /* number of duplicates */ +extern long ntransmitted; /* sequence # for outbound packets = #sent */ +extern long nchecksum; /* replies with bad checksum */ +extern long nerrors; /* icmp errors */ +extern int interval; /* interval between packets (msec) */ extern int preload; -extern int deadline; /* time to die */ +extern int deadline; /* time to die */ extern int lingertime; extern struct timeval start_time, cur_time; extern volatile int exiting; @@ -204,7 +211,7 @@ extern int confirm_flag; extern char *device; extern int pmtudisc; -extern volatile int in_pr_addr; /* pr_addr() is executing */ +extern volatile int in_pr_addr; /* pr_addr() is executing */ extern jmp_buf pr_addr_jmp; #ifndef MSG_CONFIRM @@ -213,10 +220,10 @@ extern jmp_buf pr_addr_jmp; /* timing */ -extern int timing; /* flag to do timing */ -extern long tmin; /* minimum round trip time */ -extern long tmax; /* maximum round trip time */ -extern long long tsum; /* sum of all times, for doing average */ +extern int timing; /* flag to do timing */ +extern long tmin; /* minimum round trip time */ +extern long tmax; /* maximum round trip time */ +extern long long tsum; /* sum of all times, for doing average */ extern long long tsum2; extern int rtt; extern uint16_t acked; @@ -227,71 +234,71 @@ extern int pipesize; */ static inline void write_stdout(const char *str, size_t len) { - size_t o = 0; - ssize_t cc; - do { - cc = write(STDOUT_FILENO, str + o, len - o); - o += cc; - } while (len > o || cc < 0); + size_t o = 0; + ssize_t cc; + do { + cc = write(STDOUT_FILENO, str + o, len - o); + o += cc; + } while (len > o || cc < 0); } /* * tvsub -- - * Subtract 2 timeval structs: out = out - in. Out is assumed to + * Subtract 2 timeval structs: out = out - in. Out is assumed to * be >= in. */ static inline void tvsub(struct timeval *out, struct timeval *in) { - if ((out->tv_usec -= in->tv_usec) < 0) { - --out->tv_sec; - out->tv_usec += 1000000; - } - out->tv_sec -= in->tv_sec; + if ((out->tv_usec -= in->tv_usec) < 0) { + --out->tv_sec; + out->tv_usec += 1000000; + } + out->tv_sec -= in->tv_sec; } static inline void set_signal(int signo, void (*handler)(int)) { - struct sigaction sa; + struct sigaction sa; - memset(&sa, 0, sizeof(sa)); + memset(&sa, 0, sizeof(sa)); - sa.sa_handler = (void (*)(int))handler; - sigaction(signo, &sa, NULL); + sa.sa_handler = (void (*)(int))handler; + sigaction(signo, &sa, NULL); } extern int __schedule_exit(int next); static inline int schedule_exit(int next) { - if (npackets && ntransmitted >= npackets && !deadline) - next = __schedule_exit(next); - return next; + if (npackets && ntransmitted >= npackets && !deadline) + next = __schedule_exit(next); + return next; } static inline int in_flight(void) { - uint16_t diff = (uint16_t)ntransmitted - acked; - return (diff<=0x7FFF) ? diff : ntransmitted-nreceived-nerrors; + uint16_t diff = (uint16_t)ntransmitted - acked; + return (diff<=0x7FFF) ? diff : ntransmitted-nreceived-nerrors; } static inline void acknowledge(uint16_t seq) { - uint16_t diff = (uint16_t)ntransmitted - seq; - if (diff <= 0x7FFF) { - if ((int)diff+1 > pipesize) - pipesize = (int)diff+1; - if ((int16_t)(seq - acked) > 0 || - (uint16_t)ntransmitted - acked > 0x7FFF) - acked = seq; - } + uint16_t diff = (uint16_t)ntransmitted - seq; + if (diff <= 0x7FFF) { + if ((int)diff+1 > pipesize) + pipesize = (int)diff+1; + if ((int16_t)(seq - acked) > 0 || + (uint16_t)ntransmitted - acked > 0x7FFF) + acked = seq; + } } static inline void advance_ntransmitted(void) { - ntransmitted++; - /* Invalidate acked, if 16 bit seq overflows. */ - if ((uint16_t)ntransmitted - acked > 0x7FFF) - acked = (uint16_t)ntransmitted + 1; + ntransmitted++; + /* Invalidate acked, if 16 bit seq overflows. */ + if ((uint16_t)ntransmitted - acked > 0x7FFF) + acked = (uint16_t)ntransmitted + 1; } extern void usage(void) __attribute__((noreturn)); @@ -302,22 +309,22 @@ static int enable_capability_admin(void); static int disable_capability_admin(void); #ifdef HAVE_LIBCAP extern int modify_capability(cap_value_t, cap_flag_value_t); -static inline int enable_capability_raw(void) { return modify_capability(CAP_NET_RAW, CAP_SET); } -static inline int disable_capability_raw(void) { return modify_capability(CAP_NET_RAW, CAP_CLEAR); } -static inline int enable_capability_admin(void) { return modify_capability(CAP_NET_ADMIN, CAP_SET); } -static inline int disable_capability_admin(void) { return modify_capability(CAP_NET_ADMIN, CAP_CLEAR); } +static inline int enable_capability_raw(void) { return modify_capability(CAP_NET_RAW, CAP_SET); } +static inline int disable_capability_raw(void) { return modify_capability(CAP_NET_RAW, CAP_CLEAR); } +static inline int enable_capability_admin(void) { return modify_capability(CAP_NET_ADMIN, CAP_SET); } +static inline int disable_capability_admin(void) { return modify_capability(CAP_NET_ADMIN, CAP_CLEAR); } #else extern int modify_capability(int); -static inline int enable_capability_raw(void) { return modify_capability(1); } -static inline int disable_capability_raw(void) { return modify_capability(0); } -static inline int enable_capability_admin(void) { return modify_capability(1); } -static inline int disable_capability_admin(void) { return modify_capability(0); } +static inline int enable_capability_raw(void) { return modify_capability(1); } +static inline int disable_capability_raw(void) { return modify_capability(0); } +static inline int enable_capability_admin(void) { return modify_capability(1); } +static inline int disable_capability_admin(void) { return modify_capability(0); } #endif extern void drop_capabilities(void); typedef struct socket_st { - int fd; - int socktype; + int fd; + int socktype; } socket_st; char *pr_addr(void *sa, socklen_t salen); @@ -331,13 +338,13 @@ int ping4_parse_reply(socket_st *, struct msghdr *msg, int len, void *addr, stru void ping4_install_filter(socket_st *); typedef struct ping_func_set_st { - int (*send_probe)(socket_st *, void *packet, unsigned packet_size); - int (*receive_error_msg)(socket_st *sock); - int (*parse_reply)(socket_st *, struct msghdr *msg, int len, void *addr, struct timeval *); - void (*install_filter)(socket_st *); + int (*send_probe)(socket_st *, void *packet, unsigned packet_size); + int (*receive_error_msg)(socket_st *sock); + int (*parse_reply)(socket_st *, struct msghdr *msg, int len, void *addr, struct timeval *); + void (*install_filter)(socket_st *); } ping_func_set_st; -#define MAXPACKET 128000 /* max packet size */ +#define MAXPACKET 128000 /* max packet size */ extern ping_func_set_st ping4_func_set; extern int pinger(ping_func_set_st *fset, socket_st *sock); @@ -349,9 +356,9 @@ extern void finish(void);// __attribute__((noreturn)); extern void status(void); extern void common_options(int ch); extern int gather_statistics(uint8_t *ptr, int icmplen, - int cc, uint16_t seq, int hops, - int csfailed, struct timeval *tv, char *from, - void (*pr_reply)(uint8_t *ptr, int cc)); + int cc, uint16_t seq, int hops, + int csfailed, struct timeval *tv, char *from, + void (*pr_reply)(uint8_t *ptr, int cc)); extern void print_timestamp(void); void fill(char *patp, unsigned char *packet, unsigned packet_size); @@ -380,50 +387,50 @@ extern struct sockaddr_in6 firsthop6; /* IPv6 node information query */ -#define NI_NONCE_SIZE 8 +#define NI_NONCE_SIZE 8 struct ni_hdr { - struct icmp6_hdr ni_u; - uint8_t ni_nonce[NI_NONCE_SIZE]; + struct icmp6_hdr ni_u; + uint8_t ni_nonce[NI_NONCE_SIZE]; }; -#define ni_type ni_u.icmp6_type -#define ni_code ni_u.icmp6_code -#define ni_cksum ni_u.icmp6_cksum -#define ni_qtype ni_u.icmp6_data16[0] -#define ni_flags ni_u.icmp6_data16[1] +#define ni_type ni_u.icmp6_type +#define ni_code ni_u.icmp6_code +#define ni_cksum ni_u.icmp6_cksum +#define ni_qtype ni_u.icmp6_data16[0] +#define ni_flags ni_u.icmp6_data16[1] /* Types */ #ifndef ICMPV6_NI_QUERY -# define ICMPV6_NI_QUERY 139 -# define ICMPV6_NI_REPLY 140 +# define ICMPV6_NI_QUERY 139 +# define ICMPV6_NI_REPLY 140 #endif /* Query Codes */ -#define NI_SUBJ_IPV6 0 -#define NI_SUBJ_NAME 1 -#define NI_SUBJ_IPV4 2 +#define NI_SUBJ_IPV6 0 +#define NI_SUBJ_NAME 1 +#define NI_SUBJ_IPV4 2 /* Reply Codes */ -#define NI_SUCCESS 0 -#define NI_REFUSED 1 -#define NI_UNKNOWN 2 +#define NI_SUCCESS 0 +#define NI_REFUSED 1 +#define NI_UNKNOWN 2 /* Qtypes */ -#define NI_QTYPE_NOOP 0 -#define NI_QTYPE_NAME 2 -#define NI_QTYPE_IPV6ADDR 3 -#define NI_QTYPE_IPV4ADDR 4 +#define NI_QTYPE_NOOP 0 +#define NI_QTYPE_NAME 2 +#define NI_QTYPE_IPV6ADDR 3 +#define NI_QTYPE_IPV4ADDR 4 /* Flags */ -#define NI_IPV6ADDR_F_TRUNCATE __constant_cpu_to_be16(0x0001) -#define NI_IPV6ADDR_F_ALL __constant_cpu_to_be16(0x0002) -#define NI_IPV6ADDR_F_COMPAT __constant_cpu_to_be16(0x0004) -#define NI_IPV6ADDR_F_LINKLOCAL __constant_cpu_to_be16(0x0008) -#define NI_IPV6ADDR_F_SITELOCAL __constant_cpu_to_be16(0x0010) -#define NI_IPV6ADDR_F_GLOBAL __constant_cpu_to_be16(0x0020) - -#define NI_IPV4ADDR_F_TRUNCATE NI_IPV6ADDR_F_TRUNCATE -#define NI_IPV4ADDR_F_ALL NI_IPV6ADDR_F_ALL +#define NI_IPV6ADDR_F_TRUNCATE __constant_cpu_to_be16(0x0001) +#define NI_IPV6ADDR_F_ALL __constant_cpu_to_be16(0x0002) +#define NI_IPV6ADDR_F_COMPAT __constant_cpu_to_be16(0x0004) +#define NI_IPV6ADDR_F_LINKLOCAL __constant_cpu_to_be16(0x0008) +#define NI_IPV6ADDR_F_SITELOCAL __constant_cpu_to_be16(0x0010) +#define NI_IPV6ADDR_F_GLOBAL __constant_cpu_to_be16(0x0020) + +#define NI_IPV4ADDR_F_TRUNCATE NI_IPV6ADDR_F_TRUNCATE +#define NI_IPV4ADDR_F_ALL NI_IPV6ADDR_F_ALL diff --git a/iputils/ping6_common.c b/iputils/ping6_common.c index 0d17cb5ec1c1098a6e907d2b905c26c24e464fa2..ee2690cb541dfe12fd3beaca4856690af97f93e5 100644 --- a/iputils/ping6_common.c +++ b/iputils/ping6_common.c @@ -1,10 +1,10 @@ /* * - * Modified for AF_INET6 by Pedro Roque + * Modified for AF_INET6 by Pedro Roque * - * <roque@di.fc.ul.pt> + * <roque@di.fc.ul.pt> * - * Original copyright notice included bellow + * Original copyright notice included bellow */ /* @@ -39,33 +39,33 @@ * SUCH DAMAGE. */ /* - * P I N G . C + * P I N G . C * * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, * measure round-trip-delays and packet loss across network paths. * * Author - - * Mike Muuss - * U. S. Army Ballistic Research Laboratory - * December, 1983 + * Mike Muuss + * U. S. Army Ballistic Research Laboratory + * December, 1983 * * Status - - * Public Domain. Distribution Unlimited. + * Public Domain. Distribution Unlimited. * Bugs - - * More statistics could always be gathered. - * If kernel does not support non-raw ICMP sockets or - * if -N option is used, this program has to run SUID to ROOT or - * with net_cap_raw enabled. + * More statistics could always be gathered. + * If kernel does not support non-raw ICMP sockets or + * if -N option is used, this program has to run SUID to ROOT or + * with net_cap_raw enabled. */ #include "ping.h" /* IPv6 packet information. */ -struct in6_pktinfo - { - struct in6_addr ipi6_addr; /* src/dst IPv6 address */ - unsigned int ipi6_ifindex; /* send/recv interface index */ - }; +//struct in6_pktinfo +// { +// struct in6_addr ipi6_addr; /* src/dst IPv6 address */ +// unsigned int ipi6_ifindex; /* send/recv interface index */ +// }; ping_func_set_st ping6_func_set = { .send_probe = ping6_send_probe, @@ -128,14 +128,14 @@ struct niquery_option { int (*handler)(int index, const char *arg); }; -#define NIQUERY_OPTION(_name, _has_arg, _data, _handler) \ - { \ - .name = _name, \ - .namelen = sizeof(_name) - 1, \ - .has_arg = _has_arg, \ - .data = _data, \ - .handler = _handler \ - } +#define NIQUERY_OPTION(_name, _has_arg, _data, _handler) \ + { \ + .name = _name, \ + .namelen = sizeof(_name) - 1, \ + .has_arg = _has_arg, \ + .data = _data, \ + .handler = _handler \ + } static int niquery_option_name_handler(int index __attribute__((__unused__)), const char *arg __attribute__((__unused__))); @@ -333,8 +333,8 @@ static int niquery_set_subject_type(int type) return 0; } -#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) -#define OFFSET_OF(type,elem) ((size_t)&((type *)0)->elem) +#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) +#define OFFSET_OF(type,elem) ((size_t)&((type *)0)->elem) static int niquery_option_subject_addr_handler(int index, const char *arg) { @@ -763,7 +763,7 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock #endif /* - * select icmp echo reply as icmp type to receive + * select icmp echo reply as icmp type to receive */ ICMP6_FILTER_SETBLOCKALL(&filter); @@ -946,7 +946,7 @@ int ping6_receive_error_msg(socket_st *sock) /* * pinger -- - * Compose and transmit an ICMP ECHO REQUEST packet. The IP packet + * Compose and transmit an ICMP ECHO REQUEST packet. The IP packet * will be added on by the kernel. The ID field is our UNIX process ID, * and the sequence number is an ascending integer. The first several bytes * of the data portion are used to hold a UNIX "timeval" struct in VAX @@ -1178,7 +1178,7 @@ void pr_niquery_reply(uint8_t *_nih, int len) /* * parse_reply -- - * Print out the packet, if it came from us. This logic is necessary + * Print out the packet, if it came from us. This logic is necessary * because ALL readers of the ICMP socket get a copy of ALL ICMP packets * which arrive ('tis only fair). This permits multiple copies of this * program to be run without having intermingled output (or statistics!).