Browse code

core: socket_str enclose IPv6 addresses in betwen [ ]

- string representation of socket string takes in consideration IPv6
addresses

Daniel-Constantin Mierla authored on 25/05/2010 19:10:32
Showing 2 changed files
... ...
@@ -328,6 +328,9 @@ int socket2str(char* s, int* len, struct socket_info* si)
328 328
 	proto.len = strlen(proto.s);
329 329
 	
330 330
 	l = proto.len + si->address_str.len + si->port_no_str.len + 2;
331
+
332
+	if(si->address.af==AF_INET6)
333
+		l += 2;
331 334
 	
332 335
 	if (*len < l) {
333 336
 		ERR("socket2str: Destionation buffer too short\n");
... ...
@@ -338,8 +341,14 @@ int socket2str(char* s, int* len, struct socket_info* si)
338 341
 	memcpy(s, proto.s, proto.len);
339 342
 	s += proto.len;
340 343
 	*s = ':'; s++;
344
+	if(si->address.af==AF_INET6) {
345
+		*s = '['; s++;
346
+	}
341 347
 	memcpy(s, si->address_str.s, si->address_str.len);
342 348
 	s += si->address_str.len;
349
+	if(si->address.af==AF_INET6) {
350
+		*s = ']'; s++;
351
+	}
343 352
 	*s = ':'; s++;
344 353
 	memcpy(s, si->port_no_str.s, si->port_no_str.len);
345 354
 	s += si->port_no_str.len;
... ...
@@ -47,7 +47,7 @@
47 47
  * the text description of any socket, not counting the terminating zero added
48 48
  * by socket2str */
49 49
 #define MAX_SOCKET_STR (sizeof("unknown") - 1 + IP_ADDR_MAX_STR_SIZE + \
50
-	INT2STR_MAX_LEN + 2)
50
+	INT2STR_MAX_LEN + 2 + 2)
51 51
 
52 52
 int socket2str(char* s, int* len, struct socket_info* si);
53 53