commit 73aa359e5310299b9307a37320e05c6f4eaea635 parent 335bc8df608c445139e142301bba574b272ef34b Author: Michael Savage <mikejsavage@gmail.com> Date: Thu Dec 29 15:46:01 +0200 Fix some srv warnings on OpenBSD Diffstat:
server/main.cc | | | 36 | ++++++++++++++++++------------------ |
diff --git a/server/main.cc b/server/main.cc @@ -47,8 +47,6 @@ struct Address { }; bool receive( int fd, char * buf, size_t * bytes_read, size_t buf_len, sockaddr_storage * addr ) { - // http://stackoverflow.com/questions/18995361/can-recvfrom-function-from-socket-extract-the-sender-ip-address - char ip[ INET6_ADDRSTRLEN ]; socklen_t addr_len = sizeof( *addr ); ssize_t len = recvfrom( fd, buf, buf_len, 0, ( sockaddr * ) addr, &addr_len ); if( len == -1 ) { @@ -58,26 +56,28 @@ bool receive( int fd, char * buf, size_t * bytes_read, size_t buf_len, sockaddr_ *bytes_read = ( size_t ) len; + // http://stackoverflow.com/questions/18995361/can-recvfrom-function-from-socket-extract-the-sender-ip-address // char hbuf[ INET6_ADDRSTRLEN ], sbuf[NI_MAXSERV]; // if (getnameinfo( ( const sockaddr * ) &client_addr, client_addr_len, hbuf, sizeof(hbuf), sbuf, // sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) == 0) // printf("host=%s, serv=%s\n", hbuf, sbuf); - inet_ntop( addr->ss_family, - addr->ss_family == AF_INET ? - ( void * ) &( ( sockaddr_in * ) &addr )->sin_addr : - ( void * ) &( ( sockaddr_in6 * ) &addr )->sin6_addr, - ip, sizeof( ip ) ); + // char ip[ INET6_ADDRSTRLEN ]; + // inet_ntop( addr->ss_family, + // addr->ss_family == AF_INET ? + // ( void * ) &( ( sockaddr_in * ) &addr )->sin_addr : + // ( void * ) &( ( sockaddr_in6 * ) &addr )->sin6_addr, + // ip, sizeof( ip ) ); // printf( "%s: %.*s\n", ip, len, buf ); - if( addr->ss_family == AF_INET ) { - sockaddr_in * sadin = ( sockaddr_in * ) &addr; - // printf( "%d\n", ntohs( sadin->sin_port ) ); - } - else { - sockaddr_in6 * sadin6 = ( sockaddr_in6 * ) &addr; - // printf( "%d\n", ntohs( sadin6->sin6_port ) ); - } + // if( addr->ss_family == AF_INET ) { + // sockaddr_in * sadin = ( sockaddr_in * ) &addr; + // printf( "%d\n", ntohs( sadin->sin_port ) ); + // } + // else { + // sockaddr_in6 * sadin6 = ( sockaddr_in6 * ) &addr; + // printf( "%d\n", ntohs( sadin6->sin6_port ) ); + // } return true; } @@ -90,7 +90,7 @@ static double get_time() { struct timespec ts; clock_gettime( CLOCK_MONOTONIC, &ts ); - return ( double ) ts.tv_sec + ts.tv_nsec / 1000000000.0; + return double( ts.tv_sec ) + double( ts.tv_nsec ) / 1000000000.0; } int main() { @@ -108,12 +108,12 @@ int main() { setsockopt( server_fd_ipv4, SOL_SOCKET, SO_REUSEADDR, &one, sizeof( one ) ); setsockopt( server_fd_ipv6, SOL_SOCKET, SO_REUSEADDR, &one, sizeof( one ) ); - sockaddr_in server_addr_ipv4 = { }; + sockaddr_in server_addr_ipv4; server_addr_ipv4.sin_family = AF_INET; server_addr_ipv4.sin_addr.s_addr = INADDR_ANY; server_addr_ipv4.sin_port = htons( PORT ); - sockaddr_in6 server_addr_ipv6 = { }; + sockaddr_in6 server_addr_ipv6; server_addr_ipv6.sin6_family = AF_INET6; server_addr_ipv6.sin6_addr = in6addr_any; server_addr_ipv6.sin6_port = htons( PORT );