Browse Source

sockaddr: print sin6_flowinfo field before sin6_addr

The sin6_flowinfo field comes before sin6_addr in the sockaddr_in6
defintion, but for some reason we switch the order when decoding.
This patch fixes the order of decoding.

* sockaddr.c (print_sockaddr_data_in6): Print sin6_flowinfo field
before sin6_addr.
* NEWS: Mention this fix.
* tests/group_req.c (main): Update expected output.
* tests/net-sockaddr.c (check_in6_linklocal, check_in6): Likewise.
* tests/net-yy-inet6.c (INADDR_STR, SA_FIELDS): Likewise.
* tests/sockaddr_xlat.c (validate_in6): Likewise.
Shankara Pailoor 11 months ago
parent
commit
fa0874ac02
6 changed files with 33 additions and 32 deletions
  1. 1
    0
      NEWS
  2. 1
    1
      sockaddr.c
  3. 2
    2
      tests/group_req.c
  4. 14
    12
      tests/net-sockaddr.c
  5. 3
    2
      tests/net-yy-inet6.c
  6. 12
    15
      tests/sockaddr_xlat.c

+ 1
- 0
NEWS View File

@@ -8,6 +8,7 @@ Noteworthy changes in release ?.?? (????-??-??)
8 8
     constants.
9 9
 
10 10
 * Bug fixes
11
+  * Fixed ordering of sockaddr_in6 fields.
11 12
   * Fixed strace-k test on alpha.
12 13
   * Fixed build on mips o32.
13 14
   * Fixed build on NOMMU architectures.

+ 1
- 1
sockaddr.c View File

@@ -188,7 +188,6 @@ print_sockaddr_data_in6(const void *const buf, const int addrlen)
188 188
 	const struct sockaddr_in6 *const sa_in6 = buf;
189 189
 
190 190
 	PRINT_FIELD_NET_PORT("", *sa_in6, sin6_port);
191
-	PRINT_FIELD_INET_ADDR(", ", *sa_in6, sin6_addr, AF_INET6);
192 191
 	tprints(", sin6_flowinfo=");
193 192
 	if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
194 193
 		print_quoted_string((const char*) &sa_in6->sin6_flowinfo,
@@ -201,6 +200,7 @@ print_sockaddr_data_in6(const void *const buf, const int addrlen)
201 200
 	if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV)
202 201
 		tprintf("htonl(%u)", ntohl(sa_in6->sin6_flowinfo));
203 202
 
203
+	PRINT_FIELD_INET_ADDR(", ", *sa_in6, sin6_addr, AF_INET6);
204 204
 	if (addrlen <= (int) SIN6_MIN_LEN)
205 205
 		return;
206 206
 

+ 2
- 2
tests/group_req.c View File

@@ -76,15 +76,15 @@ main(void)
76 76
 		{
77 77
 			ARG_STR(SOL_IPV6), ARG_STR(MCAST_JOIN_GROUP), greq6,
78 78
 			"gr_group={sa_family=AF_INET6, sin6_port=htons(65535)"
79
-			", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)"
80 79
 			", sin6_flowinfo=htonl(4294967295)"
80
+			", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)"
81 81
 			", sin6_scope_id=4294967295}"
82 82
 		},
83 83
 		{
84 84
 			ARG_STR(SOL_IPV6), ARG_STR(MCAST_LEAVE_GROUP), greq6,
85 85
 			"gr_group={sa_family=AF_INET6, sin6_port=htons(65535)"
86
-			", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)"
87 86
 			", sin6_flowinfo=htonl(4294967295)"
87
+			", inet_pton(AF_INET6, \"" multi6addr "\", &sin6_addr)"
88 88
 			", sin6_scope_id=4294967295}"
89 89
 		}
90 90
 	};

+ 14
- 12
tests/net-sockaddr.c View File

@@ -156,22 +156,22 @@ check_in6_linklocal(struct sockaddr_in6 *const in6, const char *const h_addr)
156 156
 	unsigned int len = sizeof(*in6);
157 157
 	int ret = connect(-1, (void *) in6, len);
158 158
 	printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
159
-	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
160 159
 	       ", sin6_flowinfo=htonl(%u)"
160
+	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
161 161
 	       ", sin6_scope_id=%u}, %u)"
162 162
 	       " = %d EBADF (%m)\n",
163
-	       ntohs(in6->sin6_port), h_addr,
164
-	       ntohl(in6->sin6_flowinfo), in6->sin6_scope_id, len, ret);
163
+	       ntohs(in6->sin6_port), ntohl(in6->sin6_flowinfo),
164
+	       h_addr, in6->sin6_scope_id, len, ret);
165 165
 
166 166
 	in6->sin6_scope_id = ifindex_lo();
167 167
 	if (in6->sin6_scope_id) {
168 168
 		ret = connect(-1, (void *) in6, len);
169 169
 		printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
170
-		       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
171 170
 		       ", sin6_flowinfo=htonl(%u)"
171
+		       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
172 172
 		       ", sin6_scope_id=%s}, %u)"
173 173
 		       " = %d EBADF (%m)\n",
174
-		       ntohs(in6->sin6_port), h_addr, ntohl(in6->sin6_flowinfo),
174
+		       ntohs(in6->sin6_port), ntohl(in6->sin6_flowinfo), h_addr,
175 175
 		       IFINDEX_LO_STR, len, ret);
176 176
 	}
177 177
 }
@@ -192,10 +192,11 @@ check_in6(void)
192 192
 	unsigned int len = sizeof(*in6);
193 193
 	int ret = connect(-1, (void *) in6, len);
194 194
 	printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
195
+	       ", sin6_flowinfo=htonl(%u)"
195 196
 	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
196
-	       ", sin6_flowinfo=htonl(%u), sin6_scope_id=%u}, %u)"
197
+	       ", sin6_scope_id=%u}, %u)"
197 198
 	       " = %d EBADF (%m)\n",
198
-	       h_port, h_addr, h_flowinfo, in6->sin6_scope_id, len, ret);
199
+	       h_port, h_flowinfo, h_addr, in6->sin6_scope_id, len, ret);
199 200
 
200 201
 	check_in6_linklocal(in6, "fe80::");
201 202
 	check_in6_linklocal(in6, "ff42::");
@@ -209,10 +210,11 @@ check_in6(void)
209 210
 	len = sizeof(*in6) + 4;
210 211
 	ret = connect(-1, (void *) in6, len);
211 212
 	printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
213
+	       ", sin6_flowinfo=htonl(%u)"
212 214
 	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
213
-	       ", sin6_flowinfo=htonl(%u), sin6_scope_id=%u}, %u)"
215
+	       ", sin6_scope_id=%u}, %u)"
214 216
 	       " = %d EBADF (%m)\n",
215
-	       h_port, h_addr, h_flowinfo, in6->sin6_scope_id, len, ret);
217
+	       h_port, h_flowinfo, h_addr, in6->sin6_scope_id, len, ret);
216 218
 
217 219
 	in6 = ((void *) in6) + 4 + sizeof(in6->sin6_scope_id);
218 220
 	in6->sin6_family = AF_INET6;
@@ -222,10 +224,10 @@ check_in6(void)
222 224
 	len = sizeof(*in6) - sizeof(in6->sin6_scope_id);
223 225
 	ret = connect(-1, (void *) in6, len);
224 226
 	printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
225
-	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
226
-	       ", sin6_flowinfo=htonl(%u)}, %u)"
227
+	       ", sin6_flowinfo=htonl(%u)"
228
+	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}, %u)"
227 229
 	       " = %d EBADF (%m)\n",
228
-	       h_port, h_addr, h_flowinfo, len, ret);
230
+	       h_port, h_flowinfo, h_addr, len, ret);
229 231
 
230 232
 	in6 = ((void *) in6) + 4;
231 233
 	in6->sin6_family = AF_INET6;

+ 3
- 2
tests/net-yy-inet6.c View File

@@ -14,7 +14,8 @@
14 14
 #define TCP_STR "TCPv6"
15 15
 #define INPORT sin6_port
16 16
 #define INPORT_STR "sin6_port"
17
-#define INADDR_STR "inet_pton(AF_INET6, \"::1\", &sin6_addr)"
18
-#define SA_FIELDS ", sin6_flowinfo=htonl(0), sin6_scope_id=0"
17
+#define INADDR_STR "sin6_flowinfo=htonl(0)" \
18
+	", inet_pton(AF_INET6, \"::1\", &sin6_addr)"
19
+#define SA_FIELDS ", sin6_scope_id=0"
19 20
 
20 21
 #include "net-yy-inet.c"

+ 12
- 15
tests/sockaddr_xlat.c View File

@@ -125,36 +125,33 @@ validate_in6(struct sockaddr_in6 *const in6, const char *const h_addr)
125 125
 #if XLAT_RAW
126 126
 	printf("connect(-1, {sa_family=%#x, sin6_port=", AF_INET6);
127 127
 	print_quoted_hex(&in6->sin6_port, sizeof(in6->sin6_port));
128
-	printf(", sin6_addr=");
129
-	print_quoted_hex(&in6->sin6_addr, sizeof(struct in6_addr));
130 128
 	printf(", sin6_flowinfo=");
131 129
 	print_quoted_hex(&in6->sin6_flowinfo, sizeof(in6->sin6_flowinfo));
132
-	printf(", sin6_scope_id=%u}, %u)"
133
-	       " = %s\n", in6->sin6_scope_id, len, errstr);
130
+	printf(", sin6_addr=");
131
+	print_quoted_hex(&in6->sin6_addr, sizeof(struct in6_addr));
132
+	printf(", sin6_scope_id=%u}, %u) = %s\n",
133
+	       in6->sin6_scope_id, len, errstr);
134 134
 #elif XLAT_VERBOSE
135 135
 	printf("connect(-1, {sa_family=%#x /* AF_INET6 */", AF_INET6);
136 136
 	printf(", sin6_port=");
137 137
 	print_quoted_hex(&in6->sin6_port, sizeof(in6->sin6_port));
138 138
 	printf(" /* htons(%hu) */", ntohs(in6->sin6_port));
139
+	printf(", sin6_flowinfo=");
140
+	print_quoted_hex(&in6->sin6_flowinfo, sizeof(in6->sin6_flowinfo));
141
+	printf(" /* htonl(%u) */", ntohl(in6->sin6_flowinfo));
139 142
 	printf(", sin6_addr=");
140 143
 	print_quoted_hex(&in6->sin6_addr, sizeof(struct in6_addr));
141 144
 	printf(" /* inet_pton(AF_INET6, \"%s\") */", h_addr);
142
-	printf(", sin6_flowinfo=");
143
-	print_quoted_hex(&in6->sin6_flowinfo, sizeof(in6->sin6_flowinfo));
144
-	printf(" /* htonl(%u) */"
145
-	       ", sin6_scope_id=%u}, %u)"
146
-	       " = %s\n",
147
-	       ntohl(in6->sin6_flowinfo), in6->sin6_scope_id,
148
-		     len, errstr);
145
+	printf(", sin6_scope_id=%u}, %u) = %s\n",
146
+	       in6->sin6_scope_id, len, errstr);
149 147
 #else
150 148
 	printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
151
-	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
152 149
 	       ", sin6_flowinfo=htonl(%u)"
150
+	       ", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
153 151
 	       ", sin6_scope_id=%u}, %u)"
154 152
 	       " = %s\n",
155
-	       ntohs(in6->sin6_port), h_addr,
156
-	       ntohl(in6->sin6_flowinfo), in6->sin6_scope_id,
157
-		     len, errstr);
153
+	       ntohs(in6->sin6_port), ntohl(in6->sin6_flowinfo),
154
+	       h_addr, in6->sin6_scope_id, len, errstr);
158 155
 #endif
159 156
 }
160 157
 

Loading…
Cancel
Save