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 338
 	memcpy(s, proto.s, proto.len);
339 339
 	s += proto.len;
340 340
 	*s = ':'; s++;
341
+	if(si->address.af==AF_INET6) {
342
+		*s = '['; s++;
343
+	}
341 344
 	memcpy(s, si->address_str.s, si->address_str.len);
342 345
 	s += si->address_str.len;
346
+	if(si->address.af==AF_INET6) {
347
+		*s = ']'; s++;
348
+	}
343 349
 	*s = ':'; s++;
344 350
 	memcpy(s, si->port_no_str.s, si->port_no_str.len);
345 351
 	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