Browse Source

Eliminate PF_INET; just use the AF_INET from the struct sockaddr instead.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
a1210e4fca
3 changed files with 43 additions and 50 deletions
  1. 11
    13
      src/core/open.c
  2. 11
    7
      src/include/gpxe/open.h
  3. 21
    30
      src/include/gpxe/socket.h

+ 11
- 13
src/core/open.c View File

75
  * Open socket
75
  * Open socket
76
  *
76
  *
77
  * @v xfer		Data transfer interface
77
  * @v xfer		Data transfer interface
78
- * @v domain		Communication domain (e.g. PF_INET)
79
- * @v type		Communication semantics (e.g. SOCK_STREAM)
78
+ * @v semantics		Communication semantics (e.g. SOCK_STREAM)
80
  * @v peer		Peer socket address
79
  * @v peer		Peer socket address
81
  * @v local		Local socket address, or NULL
80
  * @v local		Local socket address, or NULL
82
  * @ret rc		Return status code
81
  * @ret rc		Return status code
83
  */
82
  */
84
-int xfer_open_socket ( struct xfer_interface *xfer,
85
-		       int domain, int type, struct sockaddr *peer,
86
-		       struct sockaddr *local ) {
83
+int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
84
+		       struct sockaddr *peer, struct sockaddr *local ) {
87
 	struct socket_opener *opener;
85
 	struct socket_opener *opener;
88
 
86
 
89
 	DBGC ( xfer, "XFER %p opening (%s,%s) socket\n", xfer,
87
 	DBGC ( xfer, "XFER %p opening (%s,%s) socket\n", xfer,
90
-	       socket_domain_name ( domain ), socket_type_name ( type ) );
88
+	       socket_semantics_name ( semantics ),
89
+	       socket_family_name ( peer->sa_family ) );
91
 
90
 
92
 	for ( opener = socket_openers; opener < socket_openers_end; opener++ ){
91
 	for ( opener = socket_openers; opener < socket_openers_end; opener++ ){
93
-		if ( ( opener->domain == domain ) &&
94
-		     ( opener->type == type ) ) {
92
+		if ( ( opener->semantics == semantics ) &&
93
+		     ( opener->family == peer->sa_family ) ) {
95
 			return opener->open ( xfer, peer, local );
94
 			return opener->open ( xfer, peer, local );
96
 		}
95
 		}
97
 	}
96
 	}
98
 
97
 
99
 	DBGC ( xfer, "XFER %p attempted to open unsupported socket type "
98
 	DBGC ( xfer, "XFER %p attempted to open unsupported socket type "
100
-	       "(%s,%s)\n", xfer, socket_domain_name ( domain ),
101
-	       socket_type_name ( type ) );
99
+	       "(%s,%s)\n", xfer, socket_semantics_name ( semantics ),
100
+	       socket_family_name ( peer->sa_family ) );
102
 	return -ENOTSUP;
101
 	return -ENOTSUP;
103
 }
102
 }
104
 
103
 
117
 
116
 
118
 		return xfer_open_uri ( xfer, uri_string ); }
117
 		return xfer_open_uri ( xfer, uri_string ); }
119
 	case LOCATION_SOCKET: {
118
 	case LOCATION_SOCKET: {
120
-		int domain = va_arg ( args, int );
121
-		int type = va_arg ( args, int );
119
+		int semantics = va_arg ( args, int );
122
 		struct sockaddr *peer = va_arg ( args, struct sockaddr * );
120
 		struct sockaddr *peer = va_arg ( args, struct sockaddr * );
123
 		struct sockaddr *local = va_arg ( args, struct sockaddr * );
121
 		struct sockaddr *local = va_arg ( args, struct sockaddr * );
124
 
122
 
125
-		return xfer_open_socket ( xfer, domain, type, peer, local ); }
123
+		return xfer_open_socket ( xfer, semantics, peer, local ); }
126
 	default:
124
 	default:
127
 		DBGC ( xfer, "XFER %p attempted to open unsupported location "
125
 		DBGC ( xfer, "XFER %p attempted to open unsupported location "
128
 		       "type %d\n", xfer, type );
126
 		       "type %d\n", xfer, type );

+ 11
- 7
src/include/gpxe/open.h View File

26
 	 *
26
 	 *
27
 	 * Parameter list for open() is:
27
 	 * Parameter list for open() is:
28
 	 *
28
 	 *
29
-	 * 
29
+	 * int semantics;
30
+	 * struct sockaddr *peer;
31
+	 * struct sockaddr *local;
30
 	 */
32
 	 */
31
 	LOCATION_SOCKET,
33
 	LOCATION_SOCKET,
32
 };
34
 };
56
 
58
 
57
 /** A socket opener */
59
 /** A socket opener */
58
 struct socket_opener {
60
 struct socket_opener {
59
-	/** Communication domain (e.g. PF_INET) */
60
-	int domain;
61
 	/** Communication semantics (e.g. SOCK_STREAM) */
61
 	/** Communication semantics (e.g. SOCK_STREAM) */
62
-	int type;
62
+	int semantics;
63
+	/** Address family (e.g. AF_INET) */
64
+	int family;
63
 	/** Open socket
65
 	/** Open socket
64
 	 *
66
 	 *
65
 	 * @v xfer		Data transfer interface
67
 	 * @v xfer		Data transfer interface
76
 
78
 
77
 extern int xfer_open_uri ( struct xfer_interface *xfer,
79
 extern int xfer_open_uri ( struct xfer_interface *xfer,
78
 			   const char *uri_string );
80
 			   const char *uri_string );
79
-extern int xfer_open_socket ( struct xfer_interface *xfer,
80
-			      int domain, int type, struct sockaddr *peer,
81
-			      struct sockaddr *local );
81
+extern int xfer_open_named_socket ( struct xfer_interface *xfer,
82
+				    int semantics, struct sockaddr *peer,
83
+				    const char *name, struct sockaddr *local );
84
+extern int xfer_open_socket ( struct xfer_interface *xfer, int semantics,
85
+			      struct sockaddr *peer, struct sockaddr *local );
82
 extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
86
 extern int xfer_vopen ( struct xfer_interface *xfer, int type, va_list args );
83
 extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
87
 extern int xfer_open ( struct xfer_interface *xfer, int type, ... );
84
 
88
 

+ 21
- 30
src/include/gpxe/socket.h View File

8
  */
8
  */
9
 
9
 
10
 /**
10
 /**
11
- * @defgroup commdomains Communication domains
12
- *
13
- * @{
14
- */
15
-#define PF_INET		1	/**< IPv4 Internet protocols */
16
-#define PF_INET6	2	/**< IPv6 Internet protocols */
17
-/** @} */
18
-
19
-/**
20
- * Name communication domain
21
- *
22
- * @v domain		Communication domain (e.g. PF_INET)
23
- * @ret name		Name of communication domain
24
- */
25
-static inline __attribute__ (( always_inline )) const char *
26
-socket_domain_name ( int domain ) {
27
-	switch ( domain ) {
28
-	case PF_INET:		return "PF_INET";
29
-	case PF_INET6:		return "PF_INET6";
30
-	default:		return "PF_UNKNOWN";
31
-	}
32
-}
33
-
34
-/**
35
- * @defgroup commtypes Communication types
11
+ * @defgroup commtypes Communication semantics
36
  *
12
  *
37
  * @{
13
  * @{
38
  */
14
  */
41
 /** @} */
17
 /** @} */
42
 
18
 
43
 /**
19
 /**
44
- * Name communication type
20
+ * Name communication semantics
45
  *
21
  *
46
- * @v type		Communication type (e.g. SOCK_STREAM)
47
- * @ret name		Name of communication type
22
+ * @v semantics		Communication semantics (e.g. SOCK_STREAM)
23
+ * @ret name		Name of communication semantics
48
  */
24
  */
49
 static inline __attribute__ (( always_inline )) const char *
25
 static inline __attribute__ (( always_inline )) const char *
50
-socket_type_name ( int type ) {
51
-	switch ( type ) {
26
+socket_semantics_name ( int semantics ) {
27
+	switch ( semantics ) {
52
 	case SOCK_STREAM:	return "SOCK_STREAM";
28
 	case SOCK_STREAM:	return "SOCK_STREAM";
53
 	case SOCK_DGRAM:	return "SOCK_DGRAM";
29
 	case SOCK_DGRAM:	return "SOCK_DGRAM";
54
 	default:		return "SOCK_UNKNOWN";
30
 	default:		return "SOCK_UNKNOWN";
64
 #define AF_INET6	2	/**< IPv6 Internet addresses */
40
 #define AF_INET6	2	/**< IPv6 Internet addresses */
65
 /** @} */
41
 /** @} */
66
 
42
 
43
+/**
44
+ * Name address family
45
+ *
46
+ * @v family		Address family (e.g. AF_INET)
47
+ * @ret name		Name of address family
48
+ */
49
+static inline __attribute__ (( always_inline )) const char *
50
+socket_family_name ( int family ) {
51
+	switch ( family ) {
52
+	case AF_INET:		return "AF_INET";
53
+	case AF_INET6:		return "AF_INET6";
54
+	default:		return "AF_UNKNOWN";
55
+	}
56
+}
57
+
67
 /** A socket address family */
58
 /** A socket address family */
68
 typedef uint16_t sa_family_t;
59
 typedef uint16_t sa_family_t;
69
 
60
 

Loading…
Cancel
Save