From 6c4b9edf65efa165012191ad5da45181952998c5 Mon Sep 17 00:00:00 2001 From: Arnaud Vrac Date: Tue, 2 Jul 2013 22:38:28 +0200 Subject: [PATCH] Deprecate set_ipv6 functions, add set_addr replacement The set_ipv6 do not allow setting the IPv6 scope, so deprecate those functions and instead recommend using the new set_addr functions which take a sockaddr directly. --- include/rudp/address.h | 20 +++++++++++++------- include/rudp/client.h | 27 ++++++++++++++++++++++----- include/rudp/compiler.h | 7 +++++++ include/rudp/endpoint.h | 23 ++++++++++++++++++++--- include/rudp/server.h | 27 ++++++++++++++++++++++----- src/client.c | 18 +++++++++++++++++- src/endpoint.c | 19 ++++++++++++++++++- src/server.c | 18 +++++++++++++++++- 8 files changed, 136 insertions(+), 23 deletions(-) diff --git a/include/rudp/address.h b/include/rudp/address.h index 23fbd26..7af5fba 100644 --- a/include/rudp/address.h +++ b/include/rudp/address.h @@ -167,6 +167,10 @@ void rudp_address_set_ipv4( /** @this specifies an IPv6 address and port + @deprecated + This function should not be used anymore, since it does not allow + to set the IPv6 scope. Use @ref rudp_address_set instead. + @param addr The address structure @param address IPv6 to use (usual @tt {struct in6_addr} order) @param port Numeric target port (machine order) @@ -175,20 +179,22 @@ RUDP_EXPORT void rudp_address_set_ipv6( struct rudp_address *addr, const struct in6_addr *address, - const uint16_t port); + const uint16_t port) RUDP_DEPRECATED; /** - @this specifies an address (AF_INET or AF_INET6) + @this specifies an address to connect to. Supported address families + are AF_INET and AF_INET6. - @param addr The address structure - @param address Generic address to use - @param size Address structure size + @param rua The address handle + @param addr IPv4 or IPv6 address structure to set + @param addrlen Size of the address structure + @returns 0 on success, EAFNOSUPPORT if address family is not supported */ RUDP_EXPORT rudp_error_t rudp_address_set( struct rudp_address *rua, - const struct sockaddr *sockaddr, - socklen_t size); + const struct sockaddr *addr, + socklen_t addrlen); /** @this initializes an address structure for future usage. This diff --git a/include/rudp/client.h b/include/rudp/client.h index 1706c6b..d3aa26b 100644 --- a/include/rudp/client.h +++ b/include/rudp/client.h @@ -33,7 +33,7 @@ An initialized but not yet connected Client context must have its server address setup with any of the following functions: @ref rudp_client_set_hostname, @ref rudp_client_set_ipv4 or @ref - rudp_client_set_ipv6. + rudp_client_set_addr. Once the server address is setup properly, Client context can be connected with @ref rudp_client_connect. After successful @@ -181,7 +181,7 @@ rudp_error_t rudp_client_init( /** @this tries to establish a connection with the server. Server address can be set with any of the @ref rudp_client_set_hostname, - @ref rudp_client_set_ipv4 or @ref rudp_client_set_ipv6. + @ref rudp_client_set_ipv4 or @ref rudp_client_set_addr. @param client An initialized client context structure @@ -229,6 +229,21 @@ rudp_error_t rudp_client_set_hostname( const uint16_t port, uint32_t ip_flags); +/** + @this specifies an address to connect to. Supported address families + are AF_INET and AF_INET6. + + @param server An initialized server context structure + @param addr IPv4 or IPv6 address to use + @param addrlen Size of the address structure + @returns 0 on success, EAFNOSUPPORT if address family is not supported + */ +RUDP_EXPORT +rudp_error_t rudp_client_set_addr( + struct rudp_client *client, + const struct sockaddr *addr, + socklen_t addrlen); + /** @this specifies an IPv4 address to connect to. @see rudp_address_set_ipv4 for details. @@ -236,7 +251,6 @@ rudp_error_t rudp_client_set_hostname( @param client An initialized client context structure @param address IPv4 to use (usual @tt {struct in_addr} order) @param port Numeric target port (machine order) - @returns a possible error */ RUDP_EXPORT void rudp_client_set_ipv4( @@ -248,16 +262,19 @@ void rudp_client_set_ipv4( @this specifies an IPv6 address to connect to. @see rudp_address_set_ipv6 for details. + @deprecated + This function should not be used anymore, since it does not allow + to set the IPv6 scope. Use @ref rudp_client_set_addr instead. + @param client An initialized client context structure @param address IPv6 to use (usual @tt {struct in6_addr} order) @param port Numeric target port (machine order) - @returns a possible error */ RUDP_EXPORT void rudp_client_set_ipv6( struct rudp_client *client, const struct in6_addr *address, - const uint16_t port); + const uint16_t port) RUDP_DEPRECATED; /** @this sends data to remote server diff --git a/include/rudp/compiler.h b/include/rudp/compiler.h index 0ad2f43..6024712 100644 --- a/include/rudp/compiler.h +++ b/include/rudp/compiler.h @@ -25,4 +25,11 @@ #define RUDP_EXPORT #endif +/* GCC deprecated */ +#if defined(__GNUC__) && __GNUC__ >= 4 /** mkdoc:skip */ +#define RUDP_DEPRECATED __attribute__ ((deprecated)) +#else +#define RUDP_DEPRECATED +#endif + #endif diff --git a/include/rudp/endpoint.h b/include/rudp/endpoint.h index e96eef9..de78186 100644 --- a/include/rudp/endpoint.h +++ b/include/rudp/endpoint.h @@ -121,6 +121,21 @@ rudp_error_t rudp_endpoint_set_hostname( const uint16_t port, uint32_t ip_flags); +/** + @this specifies an address to bind to. Supported address families + are AF_INET and AF_INET6. + + @param server An initialized server context structure + @param addr IPv4 or IPv6 address to use + @param addrlen Size of the address structure + @returns 0 on success, EAFNOSUPPORT if address family is not supported + */ +RUDP_EXPORT +rudp_error_t rudp_endpoint_set_addr( + struct rudp_endpoint *endpoint, + const struct sockaddr *addr, + socklen_t addrlen); + /** @this specifies an IPv4 address to bind to. @see rudp_address_set_ipv4 for details. @@ -128,7 +143,6 @@ rudp_error_t rudp_endpoint_set_hostname( @param endpoint An initialized endpoint context structure @param address IPv4 to use (usual @tt {struct in_addr} order) @param port Numeric target port (machine order) - @returns a possible error */ RUDP_EXPORT void rudp_endpoint_set_ipv4( @@ -140,16 +154,19 @@ void rudp_endpoint_set_ipv4( @this specifies an IPv6 address to bind to. @see rudp_address_set_ipv6 for details. + @deprecated + This function should not be used anymore, since it does not allow + to set the IPv6 scope. Use @ref rudp_endpoint_set_addr instead. + @param endpoint An initialized endpoint context structure @param address IPv6 to use (usual @tt {struct in6_addr} order) @param port Numeric target port (machine order) - @returns a possible error */ RUDP_EXPORT void rudp_endpoint_set_ipv6( struct rudp_endpoint *endpoint, const struct in6_addr *address, - const uint16_t port); + const uint16_t port) RUDP_DEPRECATED; /** @this open and binds an endpoint to its address diff --git a/include/rudp/server.h b/include/rudp/server.h index ae28c9b..0941364 100644 --- a/include/rudp/server.h +++ b/include/rudp/server.h @@ -34,7 +34,7 @@ An initialized but not yet bound Server context must have its server address setup with any of the following functions: @ref rudp_server_set_hostname, @ref rudp_server_set_ipv4 or @ref - rudp_server_set_ipv6. + rudp_server_set_addr. Once the server address is setup properly, Server context can be bound with @ref rudp_server_bind. After successful binding, the @@ -187,7 +187,7 @@ rudp_error_t rudp_server_init( @this binds the server context to an address. This both creates a socket and binds it to the relevant address/port set with any of the @ref rudp_server_set_hostname, @ref rudp_server_set_ipv4 or - @ref rudp_server_set_ipv6. + @ref rudp_server_set_addr. @param server An initialized server context structure @@ -236,6 +236,21 @@ rudp_error_t rudp_server_set_hostname( const uint16_t port, uint32_t ip_flags); +/** + @this specifies an address to bind to. Supported address families + are AF_INET and AF_INET6. + + @param server An initialized server context structure + @param addr IPv4 or IPv6 address to use + @param addrlen Size of the address structure + @returns 0 on success, EAFNOSUPPORT if address family is not supported + */ +RUDP_EXPORT +rudp_error_t rudp_server_set_addr( + struct rudp_server *server, + const struct sockaddr *addr, + socklen_t addrlen); + /** @this specifies an IPv4 address to bind to. @see rudp_address_set_ipv4 for details. @@ -243,7 +258,6 @@ rudp_error_t rudp_server_set_hostname( @param server An initialized server context structure @param address IPv4 to use (usual @tt {struct in_addr} order) @param port Numeric target port (machine order) - @returns a possible error */ RUDP_EXPORT void rudp_server_set_ipv4( @@ -255,16 +269,19 @@ void rudp_server_set_ipv4( @this specifies an IPv6 address to bind to. @see rudp_address_set_ipv6 for details. + @deprecated + This function should not be used anymore, since it does not allow + to set the IPv6 scope. Use @ref rudp_server_set_addr instead. + @param server An initialized server context structure @param address IPv6 to use (usual @tt {struct in6_addr} order) @param port Numeric target port (machine order) - @returns a possible error */ RUDP_EXPORT void rudp_server_set_ipv6( struct rudp_server *server, const struct in6_addr *address, - const uint16_t port); + const uint16_t port) RUDP_DEPRECATED; /** @this sends data from this server to a peer. diff --git a/src/client.c b/src/client.c index 7c6445c..639ca7a 100644 --- a/src/client.c +++ b/src/client.c @@ -188,5 +188,21 @@ void rudp_client_set_ipv6( const struct in6_addr *address, const uint16_t port) { - return rudp_address_set_ipv6(&client->address, address, port); + struct sockaddr_in6 addr6; + + memset(&addr6, 0, sizeof (addr6)); + addr6.sin6_family = AF_INET6; + addr6.sin6_addr = *address; + addr6.sin6_port = htons(port); + + rudp_address_set(&client->address, (struct sockaddr *)&addr6, + sizeof (addr6)); +} + +rudp_error_t rudp_client_set_addr( + struct rudp_client *client, + const struct sockaddr *addr, + socklen_t addrlen) +{ + return rudp_address_set(&client->address, addr, addrlen); } diff --git a/src/endpoint.c b/src/endpoint.c index feb2822..e2609f5 100644 --- a/src/endpoint.c +++ b/src/endpoint.c @@ -9,6 +9,7 @@ See AUTHORS for details */ +#include #include #include #include @@ -186,7 +187,23 @@ void rudp_endpoint_set_ipv6( const struct in6_addr *address, const uint16_t port) { - return rudp_address_set_ipv6(&endpoint->addr, address, port); + struct sockaddr_in6 addr6; + + memset(&addr6, 0, sizeof (addr6)); + addr6.sin6_family = AF_INET6; + addr6.sin6_addr = *address; + addr6.sin6_port = htons(port); + + rudp_address_set(&endpoint->addr, (struct sockaddr *)&addr6, + sizeof (addr6)); +} + +rudp_error_t rudp_endpoint_set_addr( + struct rudp_endpoint *endpoint, + const struct sockaddr *addr, + socklen_t addrlen) +{ + return rudp_address_set(&endpoint->addr, addr, addrlen); } rudp_error_t rudp_endpoint_set_hostname( diff --git a/src/server.c b/src/server.c index 5028e6a..f996c95 100644 --- a/src/server.c +++ b/src/server.c @@ -324,5 +324,21 @@ void rudp_server_set_ipv6( const struct in6_addr *address, const uint16_t port) { - return rudp_endpoint_set_ipv6(&server->endpoint, address, port); + struct sockaddr_in6 addr6; + + memset(&addr6, 0, sizeof (addr6)); + addr6.sin6_family = AF_INET6; + addr6.sin6_addr = *address; + addr6.sin6_port = htons(port); + + rudp_endpoint_set_addr(&server->endpoint, (struct sockaddr *)&addr6, + sizeof (addr6)); +} + +rudp_error_t rudp_server_set_addr( + struct rudp_server *server, + const struct sockaddr *addr, + socklen_t addrlen) +{ + return rudp_endpoint_set_addr(&server->endpoint, addr, addrlen); }