Skip to content

Commit

Permalink
Deprecate set_ipv6 functions, add set_addr replacement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rawoul committed Jul 2, 2013
1 parent d8781d9 commit 6c4b9ed
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 23 deletions.
20 changes: 13 additions & 7 deletions include/rudp/address.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
27 changes: 22 additions & 5 deletions include/rudp/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -229,14 +229,28 @@ 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.
@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(
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions include/rudp/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 20 additions & 3 deletions include/rudp/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,28 @@ 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.
@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(
Expand All @@ -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
Expand Down
27 changes: 22 additions & 5 deletions include/rudp/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -236,14 +236,28 @@ 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.
@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(
Expand All @@ -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.
Expand Down
18 changes: 17 additions & 1 deletion src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
19 changes: 18 additions & 1 deletion src/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
See AUTHORS for details
*/

#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <rudp/error.h>
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 6c4b9ed

Please sign in to comment.