-static int
-create_hostlist_adv_message (struct GNUNET_HOSTLIST_ADV_Message *adv_msg)
-{
- int length = 0;
- int size = 0;
- unsigned long long port;
-
- char *uri;
- char hostname[HOST_NAME_MAX];
- char *protocol = "http://";
- char *port_s = GNUNET_malloc(6 * sizeof(char));
-
- if (0 != gethostname (hostname, sizeof (hostname) - 1))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "Could not get system's hostname, unable to create advertisement message");
- return GNUNET_NO;
- }
- if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg,
- "HOSTLIST",
- "HTTPPORT",
- &port))
- return GNUNET_SYSERR;
-
- sprintf(port_s, "%llu", port);
- length = strlen(hostname)+strlen(protocol)+strlen(port_s)+2;
- size = (length+1) * sizeof (char);
- uri = GNUNET_malloc(size);
- uri = strcpy(uri, protocol);
- uri = strcat(uri, hostname);
- uri = strcat(uri, ":");
- uri = strcat(uri, port_s);
- uri = strcat(uri, "/");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Address to obtain hostlist: %s\n", uri);
-
-
- adv_msg = GNUNET_malloc ( sizeof(struct GNUNET_HOSTLIST_ADV_Message) + size);
- if ( NULL == adv_msg)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "Could not allocate memory for the message");
- return GNUNET_NO;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "size ADV_Message: %u\n",sizeof(struct GNUNET_HOSTLIST_ADV_Message));
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "size uri: %u\n", (length + 1) * sizeof (char));
-
-
- if ( ( size + sizeof( struct GNUNET_HOSTLIST_ADV_Message )) > GNUNET_SERVER_MAX_MESSAGE_SIZE)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "Advertisement message is bigger than GNUNET allows");
- return GNUNET_NO;
- }
-
- adv_msg->header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT);
- adv_msg->header.size = htons (sizeof (struct GNUNET_HOSTLIST_ADV_Message) + size);
- memcpy(&adv_msg[1],uri,size);