mirror of
https://github.com/xcat2/xNBA.git
synced 2025-01-11 10:17:49 +00:00
Eliminate PF_INET; just use the AF_INET from the struct sockaddr instead.
This commit is contained in:
parent
070c55a838
commit
a1210e4fca
@ -75,30 +75,29 @@ int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
|
||||
* Open socket
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
* @v domain Communication domain (e.g. PF_INET)
|
||||
* @v type Communication semantics (e.g. SOCK_STREAM)
|
||||
* @v semantics Communication semantics (e.g. SOCK_STREAM)
|
||||
* @v peer Peer socket address
|
||||
* @v local Local socket address, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int xfer_open_socket ( struct xfer_interface *xfer,
|
||||
int domain, int type, struct sockaddr *peer,
|
||||
struct sockaddr *local ) {
|
||||
int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
|
||||
struct sockaddr *peer, struct sockaddr *local ) {
|
||||
struct socket_opener *opener;
|
||||
|
||||
DBGC ( xfer, "XFER %p opening (%s,%s) socket\n", xfer,
|
||||
socket_domain_name ( domain ), socket_type_name ( type ) );
|
||||
socket_semantics_name ( semantics ),
|
||||
socket_family_name ( peer->sa_family ) );
|
||||
|
||||
for ( opener = socket_openers; opener < socket_openers_end; opener++ ){
|
||||
if ( ( opener->domain == domain ) &&
|
||||
( opener->type == type ) ) {
|
||||
if ( ( opener->semantics == semantics ) &&
|
||||
( opener->family == peer->sa_family ) ) {
|
||||
return opener->open ( xfer, peer, local );
|
||||
}
|
||||
}
|
||||
|
||||
DBGC ( xfer, "XFER %p attempted to open unsupported socket type "
|
||||
"(%s,%s)\n", xfer, socket_domain_name ( domain ),
|
||||
socket_type_name ( type ) );
|
||||
"(%s,%s)\n", xfer, socket_semantics_name ( semantics ),
|
||||
socket_family_name ( peer->sa_family ) );
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@ -117,12 +116,11 @@ int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args ) {
|
||||
|
||||
return xfer_open_uri ( xfer, uri_string ); }
|
||||
case LOCATION_SOCKET: {
|
||||
int domain = va_arg ( args, int );
|
||||
int type = va_arg ( args, int );
|
||||
int semantics = va_arg ( args, int );
|
||||
struct sockaddr *peer = va_arg ( args, struct sockaddr * );
|
||||
struct sockaddr *local = va_arg ( args, struct sockaddr * );
|
||||
|
||||
return xfer_open_socket ( xfer, domain, type, peer, local ); }
|
||||
return xfer_open_socket ( xfer, semantics, peer, local ); }
|
||||
default:
|
||||
DBGC ( xfer, "XFER %p attempted to open unsupported location "
|
||||
"type %d\n", xfer, type );
|
||||
|
@ -26,7 +26,9 @@ enum {
|
||||
*
|
||||
* Parameter list for open() is:
|
||||
*
|
||||
*
|
||||
* int semantics;
|
||||
* struct sockaddr *peer;
|
||||
* struct sockaddr *local;
|
||||
*/
|
||||
LOCATION_SOCKET,
|
||||
};
|
||||
@ -56,10 +58,10 @@ struct uri_opener {
|
||||
|
||||
/** A socket opener */
|
||||
struct socket_opener {
|
||||
/** Communication domain (e.g. PF_INET) */
|
||||
int domain;
|
||||
/** Communication semantics (e.g. SOCK_STREAM) */
|
||||
int type;
|
||||
int semantics;
|
||||
/** Address family (e.g. AF_INET) */
|
||||
int family;
|
||||
/** Open socket
|
||||
*
|
||||
* @v xfer Data transfer interface
|
||||
@ -76,9 +78,11 @@ struct socket_opener {
|
||||
|
||||
extern int xfer_open_uri ( struct xfer_interface *xfer,
|
||||
const char *uri_string );
|
||||
extern int xfer_open_socket ( struct xfer_interface *xfer,
|
||||
int domain, int type, struct sockaddr *peer,
|
||||
struct sockaddr *local );
|
||||
extern int xfer_open_named_socket ( struct xfer_interface *xfer,
|
||||
int semantics, struct sockaddr *peer,
|
||||
const char *name, struct sockaddr *local );
|
||||
extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
|
||||
struct sockaddr *peer, struct sockaddr *local );
|
||||
extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
|
||||
extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
|
||||
|
||||
|
@ -8,31 +8,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup commdomains Communication domains
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define PF_INET 1 /**< IPv4 Internet protocols */
|
||||
#define PF_INET6 2 /**< IPv6 Internet protocols */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Name communication domain
|
||||
*
|
||||
* @v domain Communication domain (e.g. PF_INET)
|
||||
* @ret name Name of communication domain
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) const char *
|
||||
socket_domain_name ( int domain ) {
|
||||
switch ( domain ) {
|
||||
case PF_INET: return "PF_INET";
|
||||
case PF_INET6: return "PF_INET6";
|
||||
default: return "PF_UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @defgroup commtypes Communication types
|
||||
* @defgroup commtypes Communication semantics
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
@ -41,14 +17,14 @@ socket_domain_name ( int domain ) {
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Name communication type
|
||||
* Name communication semantics
|
||||
*
|
||||
* @v type Communication type (e.g. SOCK_STREAM)
|
||||
* @ret name Name of communication type
|
||||
* @v semantics Communication semantics (e.g. SOCK_STREAM)
|
||||
* @ret name Name of communication semantics
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) const char *
|
||||
socket_type_name ( int type ) {
|
||||
switch ( type ) {
|
||||
socket_semantics_name ( int semantics ) {
|
||||
switch ( semantics ) {
|
||||
case SOCK_STREAM: return "SOCK_STREAM";
|
||||
case SOCK_DGRAM: return "SOCK_DGRAM";
|
||||
default: return "SOCK_UNKNOWN";
|
||||
@ -64,6 +40,21 @@ socket_type_name ( int type ) {
|
||||
#define AF_INET6 2 /**< IPv6 Internet addresses */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Name address family
|
||||
*
|
||||
* @v family Address family (e.g. AF_INET)
|
||||
* @ret name Name of address family
|
||||
*/
|
||||
static inline __attribute__ (( always_inline )) const char *
|
||||
socket_family_name ( int family ) {
|
||||
switch ( family ) {
|
||||
case AF_INET: return "AF_INET";
|
||||
case AF_INET6: return "AF_INET6";
|
||||
default: return "AF_UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
/** A socket address family */
|
||||
typedef uint16_t sa_family_t;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user