aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2021-06-14 13:37:37 +0200
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2021-06-24 09:25:40 +0200
commit4c5b811c7d105aafb847f9006fd1e5235206e5cd (patch)
treec185256c1cb0c0fc23b5c32b042a531201adcbce
parent1c37763975af0a6c89a9089aa606155227e67d41 (diff)
[HICN-707] Add function for IP addr to string conversion
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: Ie9226963a6459661918678a3b1723bf87a2b15ab
-rw-r--r--hicn-light/src/hicn/core/address.c11
-rw-r--r--hicn-light/src/hicn/core/address.h9
-rw-r--r--hicn-light/src/hicn/core/connection.c12
-rw-r--r--hicn-light/src/hicn/core/listener.c13
-rw-r--r--hicn-light/src/hicn/io/tcp.c20
5 files changed, 46 insertions, 19 deletions
diff --git a/hicn-light/src/hicn/core/address.c b/hicn-light/src/hicn/core/address.c
index 07aa4a8bd..cc86b7875 100644
--- a/hicn-light/src/hicn/core/address.c
+++ b/hicn-light/src/hicn/core/address.c
@@ -41,3 +41,14 @@ const char * _address_family_str[] = {
[AF_INET] = "AF_INET",
[AF_INET6] = "AF_INET6",
};
+
+int address_to_string(const address_t *address, char *buffer) {
+ struct sockaddr_storage addr = *address;
+ socklen_t addr_len = sizeof(addr);
+ int err=getnameinfo((struct sockaddr*) &addr, addr_len, buffer, INET6_ADDRSTRLEN, 0, 0, NI_NUMERICHOST);
+
+ if (err != 0) {
+ strncpy(buffer, "N/A", INET6_ADDRSTRLEN);
+ }
+ return err;
+} \ No newline at end of file
diff --git a/hicn-light/src/hicn/core/address.h b/hicn-light/src/hicn/core/address.h
index 35d0f63ea..1cee29df3 100644
--- a/hicn-light/src/hicn/core/address.h
+++ b/hicn-light/src/hicn/core/address.h
@@ -84,5 +84,14 @@ extern const char * _address_family_str[];
#define address6_empty(address) (memcmp(address6_ip(address).s6_addr, &in6addr_any, sizeof(struct in6_addr)) == 0)
#define address_empty(address) (address_family(address) == AF_INET ? address4_empty(address) : address6_empty(address))
+/**
+ * @brief Return the string representation of the IP address provided.
+ *
+ * @param[in] address Address to obtain the string representation from.
+ * @param[in, out] buffer String to store the string representation of the address. It contains "N/A" in case of failure (see return value).
+ * @return int 0 if success, failure otherwise.
+ */
+int address_to_string(const address_t *address, char *buffer);
+
#endif /* HICNLIGHT_ADDRESS_H */
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c
index 3921eb582..fcca364e9 100644
--- a/hicn-light/src/hicn/core/connection.c
+++ b/hicn-light/src/hicn/core/connection.c
@@ -286,13 +286,15 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
goto ERR_REGISTER_FD;
#endif
- // XXX TODO
- //char *str = pair_ToString(udp->pair);
+ char addr_str[INET6_ADDRSTRLEN];
+ if (local)
+ address_to_string(&(pair->local), addr_str);
+ else
+ address_to_string(&(pair->remote), addr_str);
DEBUG("%s connection %p created for address %s (local=%s)",
- face_type_str(connection->type), connection, "N/A",
+ face_type_str(connection->type), connection, addr_str,
connection_is_local(connection) ? "true" : "false");
- //free(str);
- //
+
return 0;
#if 0
diff --git a/hicn-light/src/hicn/core/listener.c b/hicn-light/src/hicn/core/listener.c
index 66b5c09ee..7c3ba5235 100644
--- a/hicn-light/src/hicn/core/listener.c
+++ b/hicn-light/src/hicn/core/listener.c
@@ -63,7 +63,7 @@ listener_initialize(listener_t * listener, face_type_t type, const char * name,
.type = type,
.interface_name = strdup(interface_name),
//.interface_index = ,
- //.family = ,
+ .family = address->ss_family,
.fd = 0,
.address = *address,
.forwarder = forwarder,
@@ -103,12 +103,10 @@ listener_initialize(listener_t * listener, face_type_t type, const char * name,
goto ERR_REGISTER_FD;
}
- // XXX TODO
- //char *str = addressToString(listener->local_addr);
+ char addr_str[INET6_ADDRSTRLEN];
+ address_to_string(address, addr_str);
DEBUG("%s UdpListener %p created for address %s",
- face_type_str(listener->type), listener, "N/A");
- //free(str);
-
+ face_type_str(listener->type), listener, addr_str);
return 0;
ERR_REGISTER_FD:
@@ -282,6 +280,9 @@ listener_read_batch(listener_t * listener)
total_size += processed_size;
}
+ // TODO: free only if not used by cs or pit
+ for (unsigned i = 0; i < MAX_MSG; i++)
+ msgbuf_pool_put(msgbuf_pool, msgbuf[i]);
} while(r == MAX_MSG); /* backpressure based on queue size ? */
/*
diff --git a/hicn-light/src/hicn/io/tcp.c b/hicn-light/src/hicn/io/tcp.c
index 7c9d19729..1e36f78ea 100644
--- a/hicn-light/src/hicn/io/tcp.c
+++ b/hicn-light/src/hicn/io/tcp.c
@@ -143,12 +143,14 @@ connection_tcp_accept(connection_t * connection, forwarder_t *forwarder, int fd,
.closed = false,
};
- // XXX this new connection needs to be registered
- //char *str = pair_ToString(udp->pair);
+ char addr_str[INET6_ADDRSTRLEN];
+ if (local)
+ address_to_string(&(pair->local), addr_str);
+ else
+ address_to_string(&(pair->remote), addr_str);
INFO("%s connection %p created for address %s (local=%s)",
- face_type_str(connection->type), connection, "N/A",
+ face_type_str(connection->type), connection, addr_str,
connection_is_local(connection) ? "true" : "false");
- //free(str);
return 0;
}
@@ -232,10 +234,12 @@ connection_tcp_initialize(connection_t * connection)
return -1;
}
- //char *pair_str = address_pair_ToString(pair);
- INFO("%s connection %p connect for address pair %s",
- face_type_str(connection->type), connection, "N/A");
- //free(pair_str);
+ char local_addr_str[INET6_ADDRSTRLEN];
+ address_to_string(&(connection->pair.local), local_addr_str);
+ char remote_addr_str[INET6_ADDRSTRLEN];
+ address_to_string(&(connection->pair.remote), remote_addr_str);
+ INFO("%s connection %p connect for address pair %s - %s",
+ face_type_str(connection->type), connection,local_addr_str, remote_addr_str);
return 0;
}