Bläddra i källkod

Ensure that struct sockaddr is long enough...

tags/v0.9.3
Michael Brown 18 år sedan
förälder
incheckning
8ffbbebf11
2 ändrade filer med 12 tillägg och 4 borttagningar
  1. 10
    0
      src/include/gpxe/socket.h
  2. 2
    4
      src/include/gpxe/tcpip.h

+ 10
- 0
src/include/gpxe/socket.h Visa fil

@@ -14,6 +14,9 @@
14 14
 /** A socket address family */
15 15
 typedef uint16_t sa_family_t;
16 16
 
17
+/** Length of a @c struct @c sockaddr */
18
+#define SA_LEN 32
19
+
17 20
 /**
18 21
  * Generalized socket address structure
19 22
  *
@@ -26,6 +29,13 @@ struct sockaddr {
26 29
 	 * This is an AF_XXX constant.
27 30
 	 */
28 31
         sa_family_t sa_family;
32
+	/** Padding
33
+	 *
34
+	 * This ensures that a struct @c sockaddr_tcpip is large
35
+	 * enough to hold a socket address for any TCP/IP address
36
+	 * family.
37
+	 */
38
+	char pad[ SA_LEN - sizeof ( sa_family_t ) ];
29 39
 };
30 40
 
31 41
 #endif /* _GPXE_SOCKET_H */

+ 2
- 4
src/include/gpxe/tcpip.h Visa fil

@@ -21,9 +21,6 @@ struct net_device;
21 21
  */
22 22
 #define TCPIP_EMPTY_CSUM 0xffff
23 23
 
24
-/** Length of a @c struct @c sockaddr_tcpip */
25
-#define SA_TCPIP_LEN 32
26
-
27 24
 /**
28 25
  * TCP/IP socket address
29 26
  *
@@ -41,7 +38,8 @@ struct sockaddr_tcpip {
41 38
 	 * enough to hold a socket address for any TCP/IP address
42 39
 	 * family.
43 40
 	 */
44
-	char pad[SA_TCPIP_LEN - sizeof ( sa_family_t ) - sizeof ( uint16_t )];
41
+	char pad[ sizeof ( struct sockaddr ) -
42
+		  ( sizeof ( sa_family_t ) + sizeof ( uint16_t ) ) ];
45 43
 };
46 44
 
47 45
 /** 

Laddar…
Avbryt
Spara