+ const struct IPv4HttpAddress *t4;
+ const struct IPv6HttpAddress *t6;
+ struct sockaddr_in a4;
+ struct sockaddr_in6 a6;
+ char * address;
+ char * ret;
+ uint16_t port;
+ unsigned int res;
+
+ if (addrlen == sizeof (struct IPv6HttpAddress))
+ {
+ address = GNUNET_malloc (INET6_ADDRSTRLEN);
+ t6 = addr;
+ a6.sin6_addr = t6->ipv6_addr;
+ inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN);
+ port = ntohs(t6->u6_port);
+ }
+ else if (addrlen == sizeof (struct IPv4HttpAddress))
+ {
+ address = GNUNET_malloc (INET_ADDRSTRLEN);
+ t4 = addr;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN);
+ port = ntohs(t4->u_port);
+ }
+ else
+ {
+ /* invalid address */
+ return NULL;
+ }
+ res = GNUNET_asprintf(&ret,"%s:%u",address,port);
+ GNUNET_free (address);
+ GNUNET_assert(res != 0);
+ return ret;
+}
+
+/**
+ * Add the IP of our network interface to the list of
+ * our external IP addresses.
+ *
+ * @param cls the 'struct Plugin*'
+ * @param name name of the interface
+ * @param isDefault do we think this may be our default interface
+ * @param addr address of the interface
+ * @param addrlen number of bytes in addr
+ * @return GNUNET_OK to continue iterating
+ */
+static int
+process_interfaces (void *cls,
+ const char *name,
+ int isDefault,
+ const struct sockaddr *addr, socklen_t addrlen)
+{
+ struct Plugin *plugin = cls;
+ struct IPv4HttpAddress * t4;
+ struct IPv6HttpAddress * t6;
+ int af;
+
+ GNUNET_assert(cls !=NULL);
+ af = addr->sa_family;
+ if (af == AF_INET)
+ {
+ t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
+ if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr))
+ {
+ /* skip loopback addresses */
+ return GNUNET_OK;
+ }
+ t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
+ t4->u_port = htons (plugin->port_inbound);
+ plugin->env->notify_address(plugin->env->cls,"http",t4, sizeof (struct IPv4HttpAddress), GNUNET_TIME_UNIT_FOREVER_REL);
+
+ }
+ else if (af == AF_INET6)
+ {
+ t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
+ if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ {
+ /* skip link local addresses */
+ return GNUNET_OK;
+ }
+ if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ {
+ /* skip loopback addresses */
+ return GNUNET_OK;
+ }
+ memcpy (&t6->ipv6_addr,
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
+ t6->u6_port = htons (plugin->port_inbound);
+ plugin->env->notify_address(plugin->env->cls,"http",t6,sizeof (struct IPv6HttpAddress) , GNUNET_TIME_UNIT_FOREVER_REL);
+ }
+ return GNUNET_OK;
+}
+
+int remove_peer_context_Iterator (void *cls, const GNUNET_HashCode *key, void *value)
+{
+ struct HTTP_PeerContext * pc = value;
+ struct Session * ps = pc->head;
+ struct Session * tmp = NULL;
+ struct HTTP_Message * msg = NULL;
+ struct HTTP_Message * msg_tmp = NULL;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing context for peer `%s'\n",GNUNET_i2s(&pc->identity));
+
+ while (ps!=NULL)
+ {
+ tmp = ps->next;
+
+ GNUNET_free_non_null (ps->addr);
+ GNUNET_free(ps->url);
+ if (ps->msgtok != NULL)
+ GNUNET_SERVER_mst_destroy (ps->msgtok);
+
+ msg = ps->pending_msgs_head;
+ while (msg!=NULL)
+ {
+ msg_tmp = msg->next;
+ GNUNET_free(msg);
+ msg = msg_tmp;
+ }
+ if (ps->direction==OUTBOUND)
+ {
+ if (ps->send_endpoint!=NULL)
+ curl_easy_cleanup(ps->send_endpoint);
+ if (ps->recv_endpoint!=NULL)
+ curl_easy_cleanup(ps->recv_endpoint);
+ }
+
+ GNUNET_free(ps);
+ ps=tmp;
+ }
+ GNUNET_free(pc);
+ return GNUNET_YES;