Exemple #1
0
int
main (int argc, char *argv[])
{
	char   str[256];
	uuid_t uu;

	if (argc > 1)
	{
	     setlocale (LC_ALL, "");
	     bindtextdomain (PACKAGE, SCROLLKEEPERLOCALEDIR);
	     textdomain (PACKAGE);

	     if (strcmp (argv[1], "--help") == 0)
	     {
		  printf (_("Usage: %s\n"), *argv);
		  return 0;
	     }
	     fprintf (stderr, _("Usage: %s\n"), *argv);
	     return 1;
	}
	
	uuid_generate_time(uu);
	
	uuid_unparse(uu, str);

	printf("%s\n", str);

	return 0;
}
Exemple #2
0
/*
 * This is the generic front-end to uuid_generate_random and
 * uuid_generate_time.  It uses uuid_generate_random only if
 * /dev/urandom is available, since otherwise we won't have
 * high-quality randomness.
 */
void uuid_generate(uuid_t out)
{
	if (have_random_source())
		uuid_generate_random(out);
	else
		uuid_generate_time(out);
}
Exemple #3
0
/*
 * This is the generic front-end to uuid_generate_random and
 * uuid_generate_time.  It uses uuid_generate_random only if
 * /dev/urandom is available, since otherwise we won't have
 * high-quality randomness.
 */
void uuid_generate(uuid_t out)
{
	if (get_random_fd() >= 0)
		uuid_generate_random(out);
	else
		uuid_generate_time(out);
}
Exemple #4
0
struct sg_uuid_str sg_uuid_gen(enum sg_uuid_method method, int uppercase)
{
    uuid_t uu;
    struct sg_uuid_str us;

    assert(method >= SGUUIDMETHOD_DEFAULT && method <= SGUUIDMETHOD_TIME_MAC);

    memset(&us, 0, sizeof(struct sg_uuid_str));

    switch (method) {
    case SGUUIDMETHOD_DEFAULT:
        uuid_generate(uu);
        break;
    case SGUUIDMETHOD_RANDOM:
        uuid_generate_random(uu);
        break;
    case SGUUIDMETHOD_TIME_MAC:
        uuid_generate_time(uu);
        break;
    case SGUUIDMETHOD_TIME_MAC_SAFE:
        uuid_generate_time_safe(uu);
        break;
    default:
        sg_log_err("UUID method error.");
        return us;
    }

    if (uppercase == 0)
        uuid_unparse_lower(uu, us.buf);
    else
        uuid_unparse_upper(uu, us.buf);

    return us;
}
Exemple #5
0
int main(int argc, char **argv)
{
int result = -1;
int id_count = 1;

struct Namespace namespaces[] =
{   // {"ns-prefix", "ns-name"}
   {"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope"}, // MUST be first
   {"d", "http://schemas.xmlsoap.org/ws/2005/04/discovery"}, 
   {"wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing"}, 
   {"dn", "http://www.onvif.org/ver10/network/wsdl"}, // given by the service description
   {NULL, NULL} // end of table
}; 
	 
	 // Get UUID
	 uuid_t uuid;
	 char szUuid[36] = {0};
	 char szMsgID[50] = {0};
	 
	 uuid_generate_time(uuid);
	 
	 uuid_unparse(uuid, szUuid);
	 
	 snprintf(szMsgID, sizeof(szMsgID), "uuid:%s", szUuid);
	 
struct soap soap;
struct SOAP_ENV__Header header; // the SOAP Header

soap_init(&soap);
soap.send_timeout = 1; // 1s timeout
soap.recv_timeout = 1; // 1s timeout

soap_set_namespaces(&soap, namespaces);

soap_default_SOAP_ENV__Header(&soap, &header); // init SOAP Header
header.wsa__MessageID = szMsgID;
header.wsa__To = "urn:schemas-xmlsoap-org:ws:2005:04:discovery";
header.wsa__Action = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe";

soap.header = &header;

struct d__ProbeMatchType r;
// Send and receive messages over UDP:
if (soap_send_d__Probe(&soap, "soap.udp://239.255.255.250:3702", NULL, "", ""))
{
      soap_print_fault(&soap, stderr);
}

// Send and receive messages over UDP:
if (soap_send_d__ProbeMatches(&soap, "soap.udp://239.255.255.250:3702", NULL, NULL))
{
      soap_print_fault(&soap, stderr);
}

soap_destroy(&soap); // cleanup
soap_end(&soap); // cleanup
soap_done(&soap); // close connection (should not use soap struct after this) 

return 0;
}
Exemple #6
0
static VALUE UUID_generate_time(VALUE self)
{
  uuid_t out;
  
  uuid_generate_time(out);
  
  return uuid2ary(out);
}
Exemple #7
0
int main(void)
{
    uuid_t test;
    uuid_string_t out;

    uuid_generate_time(test);
    uuid_unparse_lower(test, out);
    printf("UUID=%s\n", out);
}
Exemple #8
0
int
main (int argc, char *argv[])
{
	int    c;
	int    do_type = 0;
	char   str[37];
	uuid_t uu;

	static const struct option longopts[] = {
		{"random", no_argument, NULL, 'r'},
		{"time", no_argument, NULL, 't'},
		{"version", no_argument, NULL, 'V'},
		{"help", no_argument, NULL, 'h'},
		{NULL, 0, NULL, 0}
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
		switch (c) {
		case 't':
			do_type = UUID_TYPE_DCE_TIME;
			break;
		case 'r':
			do_type = UUID_TYPE_DCE_RANDOM;
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		case 'h':
			usage(stdout);
		default:
			usage(stderr);
		}

	switch (do_type) {
	case UUID_TYPE_DCE_TIME:
		uuid_generate_time(uu);
		break;
	case UUID_TYPE_DCE_RANDOM:
		uuid_generate_random(uu);
		break;
	default:
		uuid_generate(uu);
		break;
	}

	uuid_unparse(uu, str);

	printf("%s\n", str);

	return EXIT_SUCCESS;
}
Exemple #9
0
void* uuid_thread_time( object_t thread, void* arg )
{
	int i;
	int ithread = (int)(uintptr_t)arg;

	for( i = 0; i < 8192; ++i )
		uuid_thread_store[ithread][i] = uuid_generate_time();
	
	return 0;
}
Exemple #10
0
int main(void) {

  uuid_t u;
  char str[37];
  uuid_generate_time(u);
  uuid_unparse(u, str);

  fprintf(stderr,"%s\n",str);

  return 0;
}
Exemple #11
0
static int Lnew(lua_State *L)			/** new([s]) */
{
 uuid_t c;
 char s[2*sizeof(c)+4+1];
 const char *t=luaL_optstring(L,1,NULL);
 if (t==NULL) uuid_generate(c); else
 if (*t=='r') uuid_generate_random(c); else
 if (*t=='t') uuid_generate_time(c); else uuid_generate(c);
 uuid_unparse(c,s);
 lua_pushlstring(L,s,sizeof(s)-1);
 return 1;
}
Exemple #12
0
int
main (int   argc,
      char**argv)
{
  char  buffer[37];
  uuid_t out;
  uuid_clear         (out);
  uuid_generate_time (out);
  uuid_unparse       (out, buffer);

  return 0;
}
Exemple #13
0
int gen_soap_header(char *buffer, int *len, const char *to, 
				const char* action_pre, const char *action, const char *relates, int http)
{
	static const char wsd_soap_header_start[] =
		"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
		"<soap:Envelope "
			"xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" "
			"xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" "
			"xmlns:wsd=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" "
			"xmlns:wsx=\"http://schemas.xmlsoap.org/ws/2004/09/mex\" "
			"xmlns:wsdp=\"http://schemas.xmlsoap.org/ws/2006/02/devprof\" "
			"xmlns:un0=\"http://schemas.microsoft.com/windows/pnpx/2005/10\" "
			"xmlns:pub=\"http://schemas.microsoft.com/windows/pub/2005/07\">"
		"<soap:Header>"
			"<wsa:To>%s</wsa:To>"
			"<wsa:Action>%s%s</wsa:Action>"
			"<wsa:MessageID>urn:uuid:%s</wsa:MessageID>";
	static const char wsd_soap_header_relates[] =
			"<wsa:RelatesTo>%s</wsa:RelatesTo>";
	static const char wsd_soap_header_seq[] =
			"<wsd:AppSequence InstanceId=\"%d\" SequenceId=\"%s\" MessageNumber=\"%d\" />";
	static const char wsd_soap_header_end[] =
		"</soap:Header>";
			
	char	msg_id[37];
	uuid_t	uu;
	int		ret_len;

	uuid_generate_time(uu);
	uuid_unparse(uu, msg_id);

	ret_len = snprintf(buffer, *len, wsd_soap_header_start, to, action_pre, action, msg_id);
	if (ret_len >= *len)
		return -1;

	if (relates) {
		ret_len += snprintf(buffer+ret_len, (*len)-ret_len, wsd_soap_header_relates, relates);
		if (ret_len >= *len)
			return -1;
	}
	
	if (!http) {
		ret_len += snprintf(buffer+ret_len, (*len)-ret_len, wsd_soap_header_seq,
				instance_id, sequence, msg_no++);
		if (ret_len >= *len)
			return -1;
	}

	ret_len += snprintf(buffer+ret_len, (*len)-ret_len, wsd_soap_header_end);
	*len = ret_len;
	return 0;
}
Exemple #14
0
Fichier : R.c Projet : cran/uuid
SEXP UUID_gen(SEXP sTime) {
    uuid_t u;
    char c[40];
    int use_time = asInteger(sTime);
    if (use_time == TRUE)
	uuid_generate_time(u);
    else if (use_time == FALSE)
	uuid_generate_random(u);
    else
	uuid_generate(u);
    uuid_unparse_lower(u, c);
    return mkString(c);
}
Exemple #15
0
IoObject *IoUUID_uuidTime(IoUUID *self, IoObject *locals, IoMessage *m)
{
	/*doc UUID uuidTime
	Returns a new time and mac uuid (type 1) in string format.
	*/

	uuid_t buf;
	char str[200];

	uuid_generate_time(buf);
	uuid_unparse(buf, str);

	return IOSYMBOL(str);
}
char *registry_get_this_machine_guid(void) {
    static char guid[GUID_LEN + 1] = "";

    if(likely(guid[0]))
        return guid;

    // read it from disk
    int fd = open(registry.machine_guid_filename, O_RDONLY);
    if(fd != -1) {
        char buf[GUID_LEN + 1];
        if(read(fd, buf, GUID_LEN) != GUID_LEN)
            error("Failed to read machine GUID from '%s'", registry.machine_guid_filename);
        else {
            buf[GUID_LEN] = '\0';
            if(regenerate_guid(buf, guid) == -1) {
                error("Failed to validate machine GUID '%s' from '%s'. Ignoring it - this might mean this netdata will appear as duplicate in the registry.",
                        buf, registry.machine_guid_filename);

                guid[0] = '\0';
            }
            else if(is_machine_guid_blacklisted(guid))
                guid[0] = '\0';
        }
        close(fd);
    }

    // generate a new one?
    if(!guid[0]) {
        uuid_t uuid;

        uuid_generate_time(uuid);
        uuid_unparse_lower(uuid, guid);
        guid[GUID_LEN] = '\0';

        // save it
        fd = open(registry.machine_guid_filename, O_WRONLY|O_CREAT|O_TRUNC, 444);
        if(fd == -1)
            fatal("Cannot create unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);

        if(write(fd, guid, GUID_LEN) != GUID_LEN)
            fatal("Cannot write the unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);

        close(fd);
    }

    setenv("NETDATA_REGISTRY_UNIQUE_ID", guid, 1);

    return guid;
}
Exemple #17
0
/* 
** Helper function to generate the desired type of UUID string 
*/
char* uuid_gen(int how)
{
  uuid_t r;
  char *buff = (char *) malloc(BUFFSIZE);
  if (buff == 0)
  {
    return "false";
  }
  else
  {
    (how == CMD_RANDOM) ? uuid_generate(r) : uuid_generate_time(r);
    uuid_unparse(r, buff);
  }

  return buff;
}
Exemple #18
0
/*
 * Creates a new UUID. The uuid will be generated based on high-quality
 * randomness from /dev/urandom, if available by calling uuid_generate_random.
 * If it failed to generate UUID then uuid_generate will call
 * uuid_generate_time.
 */
void
uuid_generate(uuid_t uu)
{
	int fd;

	if (uu == NULL) {
		return;
	}
	fd = open(URANDOM_PATH, O_RDONLY);
	if (fd >= 0) {
		(void) close(fd);
		uuid_generate_random(uu);
	} else {
		(void) uuid_generate_time(uu);
	}
}
/* Set everything up for using the NI compiler. Called from the main thread. */
static void
prepare_ni_compiler(CompilerData *data)
{
    I7_STORY_USE_PRIVATE(data->story, priv);
    GError *err = NULL;

    /* Clear the previous compile output */
    gtk_text_buffer_set_text(priv->progress, "", -1);
    html_load_blank(WEBKIT_WEB_VIEW(data->story->panel[LEFT]->results_tabs[I7_RESULTS_TAB_REPORT]));
    html_load_blank(WEBKIT_WEB_VIEW(data->story->panel[RIGHT]->results_tabs[I7_RESULTS_TAB_REPORT]));

    /* Create the UUID file if needed */
    GFile *uuid_file = g_file_get_child(data->input_file, "uuid.txt");
    if(!g_file_query_exists(uuid_file, NULL)) {
#ifdef E2FS_UUID /* code for e2fsprogs uuid */
        uuid_t uuid;
        gchar uuid_string[37];

        uuid_generate_time(uuid);
        uuid_unparse(uuid, uuid_string);
#else /* code for OSSP UUID */
        gchar *uuid_string = NULL; /* a new buffer is allocated if NULL */
        uuid_t *uuid;

        if(!((uuid_create(&uuid) == UUID_RC_OK)
                && (uuid_make(uuid, UUID_MAKE_V1) == UUID_RC_OK)
                && (uuid_export(uuid, UUID_FMT_STR, (void **)&uuid_string, NULL) == UUID_RC_OK)
                && (uuid_destroy(uuid) == UUID_RC_OK))) {
            error_dialog(GTK_WINDOW(data->story), NULL, _("Error creating UUID."));
            g_object_unref(uuid_file);
            return;
        }
#endif /* UUID conditional */
        if(!g_file_replace_contents(uuid_file, uuid_string, strlen(uuid_string), NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &err)) {
            IO_ERROR_DIALOG(GTK_WINDOW(data->story), uuid_file, err, _("creating UUID file"));
            g_object_unref(uuid_file);
            return;
        }
#ifndef E2FS_UUID /* Only OSSP UUID */
        free(uuid_string);
#endif /* !OSSP_UUID */
    }
    g_object_unref(uuid_file);

    /* Display status message */
    i7_document_display_status_message(I7_DOCUMENT(data->story), _("Compiling Inform 7 to Inform 6"), COMPILE_OPERATIONS);
}
Exemple #20
0
static errcode_t parse_uuid(struct super_set_info *info, char *arg)
{
	unsigned char *	p = (unsigned char *) info->ptr;
	
	if ((strcasecmp(arg, "null") == 0) ||
	    (strcasecmp(arg, "clear") == 0)) {
		uuid_clear(p);
	} else if (strcasecmp(arg, "time") == 0) {
		uuid_generate_time(p);
	} else if (strcasecmp(arg, "random") == 0) {
		uuid_generate(p);
	} else if (uuid_parse(arg, p)) {
		fprintf(stderr, "Invalid UUID format: %s\n", arg);
		return EINVAL;
	}
	return 0;
}
Exemple #21
0
int
main (int argc, char *argv[])
{
	int    c;
	int    do_type = 0;
	char   str[37];
	uuid_t uu;

#ifdef ENABLE_NLS
	setlocale(LC_MESSAGES, "");
	setlocale(LC_CTYPE, "");
	bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
	textdomain(NLS_CAT_NAME);
#endif

	while ((c = getopt (argc, argv, "tr")) != EOF)
		switch (c) {
		case 't':
			do_type = DO_TYPE_TIME;
			break;
		case 'r':
			do_type = DO_TYPE_RANDOM;
			break;
		default:
			usage(argv[0]);
		}
	
	switch (do_type) {
	case DO_TYPE_TIME:
		uuid_generate_time(uu);
		break;
	case DO_TYPE_RANDOM:
		uuid_generate_random(uu);
		break;
	default:
		uuid_generate(uu);
		break;
	}
	
	uuid_unparse(uu, str);

	printf("%s\n", str);

	return 0;
}
Exemple #22
0
static PyObject *
py_uuid_generate_time_safe(void)
{
    uuid_t uuid;
#ifdef HAVE_UUID_GENERATE_TIME_SAFE
    int res;

    res = uuid_generate_time_safe(uuid);
    return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res);
#elif HAVE_UUID_CREATE
    uint32_t status;
    uuid_create(&uuid, &status);
    return Py_BuildValue("y#i", (const char *) &uuid, sizeof(uuid), (int) status);
#else
    uuid_generate_time(uuid);
    return Py_BuildValue("y#O", (const char *) uuid, sizeof(uuid), Py_None);
#endif
}
Exemple #23
0
/**
 * epc_tls_certificate_new:
 * @hostname: the name of the host that will use this certificate
 * @validity: the number of days the certificate will remain valid
 * @key: the private key for signing the certificate
 * @error: return location for a #GError, or %NULL
 *
 * Creates a self signed X.509 certificate. The certificate will mention
 * @hostname as common name and as DNS host name, and it will be valid
 * for @validity days.
 *
 * If the call was successful, the newly created certificate is returned. This
 * certificate can be used with functions of the <citetitle>GNU TLS</citetitle>
 * library. If the call was not successful, it returns %NULL and sets @error.
 * The error domain is #EPC_TLS_ERROR. Error codes are taken from the
 * <citetitle>GNU TLS</citetitle> library.
 *
 * Returns: The newly created certificate object, or %NULL.
 */
gnutls_x509_crt_t
epc_tls_certificate_new (const gchar            *hostname,
                         guint                   validity,
                         gnutls_x509_privkey_t   key,
                         GError                **error)
{
  gint rc = GNUTLS_E_SUCCESS;
  gnutls_x509_crt_t crt = NULL;
  time_t now = time (NULL);
  uuid_t serial;

  g_return_val_if_fail (NULL != key, NULL);
  g_return_val_if_fail (NULL != hostname, NULL);

  if (EPC_DEBUG_LEVEL (1))
    g_debug ("%s: Generating self signed server certificate for `%s'", G_STRLOC, hostname);

  uuid_generate_time (serial);

  epc_tls_check (rc = gnutls_x509_crt_init (&crt));
  epc_tls_check (rc = gnutls_x509_crt_set_version (crt, 1));
  epc_tls_check (rc = gnutls_x509_crt_set_key (crt, key));
  epc_tls_check (rc = gnutls_x509_crt_set_serial (crt, serial, sizeof serial));
  epc_tls_check (rc = gnutls_x509_crt_set_activation_time (crt, now));
  epc_tls_check (rc = gnutls_x509_crt_set_expiration_time (crt, now + validity));
  epc_tls_check (rc = gnutls_x509_crt_set_subject_alternative_name (crt, GNUTLS_SAN_DNSNAME, hostname));
  epc_tls_check (rc = gnutls_x509_crt_set_dn_by_oid (crt, GNUTLS_OID_X520_COMMON_NAME, 0, hostname, strlen (hostname)));
  epc_tls_check (rc = gnutls_x509_crt_sign (crt, crt, key));

out:
  if (GNUTLS_E_SUCCESS != rc)
    {
      g_set_error (error, EPC_TLS_ERROR, rc,
                   _("Cannot create self signed server key for '%s': %s"),
                   hostname, gnutls_strerror (rc));

      if (crt)
        gnutls_x509_crt_deinit (crt);

      crt = NULL;
    }

  return crt;
}
Exemple #24
0
std::string CreateGUID()
{
	std::string guidStr;
#ifdef WIN32
	std::wstring guidWStr;
	guidWStr.resize(50);
	GUID guid;
	CoCreateGuid(&guid);
	StringFromGUID2(guid, (wchar_t*)guidWStr.c_str(), (int)guidWStr.size());
	g_wcstombs(guidStr, guidWStr);
#else
	uuid_t out;
	uuid_generate_time(out);
	for(int i = 0; i < sizeof(out); i++)
	{
	  char num[10] = {0};
	  snprintf(num, 10, "%d", out[i]);
	  guidStr.append(num);
	}
#endif
	return guidStr.c_str();
}
Exemple #25
0
/*
 * Some older clients (Windows 98) only handle the low byte
 * of the max workers value. If the low byte is less than
 * SMB_PI_MAX_WORKERS_MIN set it to SMB_PI_MAX_WORKERS_MIN.
 */
void
smb_load_kconfig(smb_kmod_cfg_t *kcfg)
{
	struct utsname uts;
	int64_t citem;
	int rc;

	bzero(kcfg, sizeof (smb_kmod_cfg_t));

	(void) smb_config_getnum(SMB_CI_MAX_WORKERS, &citem);
	kcfg->skc_maxworkers = (uint32_t)citem;
	if ((kcfg->skc_maxworkers & 0xFF) < SMB_PI_MAX_WORKERS_MIN) {
		kcfg->skc_maxworkers &= ~0xFF;
		kcfg->skc_maxworkers += SMB_PI_MAX_WORKERS_MIN;
	}

	(void) smb_config_getnum(SMB_CI_KEEPALIVE, &citem);
	kcfg->skc_keepalive = (uint32_t)citem;
	if ((kcfg->skc_keepalive != 0) &&
	    (kcfg->skc_keepalive < SMB_PI_KEEP_ALIVE_MIN))
		kcfg->skc_keepalive = SMB_PI_KEEP_ALIVE_MIN;

	(void) smb_config_getnum(SMB_CI_MAX_CONNECTIONS, &citem);
	kcfg->skc_maxconnections = (uint32_t)citem;
	kcfg->skc_restrict_anon = smb_config_getbool(SMB_CI_RESTRICT_ANON);
	kcfg->skc_signing_enable = smb_config_getbool(SMB_CI_SIGNING_ENABLE);
	kcfg->skc_signing_required = smb_config_getbool(SMB_CI_SIGNING_REQD);
	kcfg->skc_netbios_enable = smb_config_getbool(SMB_CI_NETBIOS_ENABLE);
	kcfg->skc_ipv6_enable = smb_config_getbool(SMB_CI_IPV6_ENABLE);
	kcfg->skc_print_enable = smb_config_getbool(SMB_CI_PRINT_ENABLE);
	kcfg->skc_oplock_enable = smb_config_getbool(SMB_CI_OPLOCK_ENABLE);
	kcfg->skc_sync_enable = smb_config_getbool(SMB_CI_SYNC_ENABLE);
	kcfg->skc_traverse_mounts = smb_config_getbool(SMB_CI_TRAVERSE_MOUNTS);
	kcfg->skc_max_protocol = smb_config_get_max_protocol();
	kcfg->skc_secmode = smb_config_get_secmode();

	rc = smb_config_getnum(SMB_CI_MAXIMUM_CREDITS, &citem);
	if (rc != SMBD_SMF_OK)
		citem = SMB_PI_MAX_CREDITS;
	if (citem < SMB_PI_MIN_CREDITS)
		citem = SMB_PI_MIN_CREDITS;
	if (citem > SMB_PI_MAX_CREDITS)
		citem = SMB_PI_MAX_CREDITS;
	kcfg->skc_maximum_credits = (uint16_t)citem;

	rc = smb_config_getnum(SMB_CI_INITIAL_CREDITS, &citem);
	if (rc != SMBD_SMF_OK)
		citem = SMB_PI_MIN_CREDITS;
	if (citem < SMB_PI_MIN_CREDITS)
		citem = SMB_PI_MIN_CREDITS;
	if (citem > kcfg->skc_maximum_credits)
		citem = kcfg->skc_maximum_credits;
	kcfg->skc_initial_credits = (uint16_t)citem;

	(void) smb_getdomainname(kcfg->skc_nbdomain,
	    sizeof (kcfg->skc_nbdomain));
	(void) smb_getfqdomainname(kcfg->skc_fqdn,
	    sizeof (kcfg->skc_fqdn));
	(void) smb_getnetbiosname(kcfg->skc_hostname,
	    sizeof (kcfg->skc_hostname));
	(void) smb_config_getstr(SMB_CI_SYS_CMNT, kcfg->skc_system_comment,
	    sizeof (kcfg->skc_system_comment));
	smb_config_get_version(&kcfg->skc_version);
	kcfg->skc_execflags = smb_config_get_execinfo(NULL, NULL, 0);
	if (smb_config_get_localuuid(kcfg->skc_machine_uuid) < 0) {
		syslog(LOG_ERR, "smb_load_kconfig: no machine_uuid");
		uuid_generate_time(kcfg->skc_machine_uuid);
	}
	/* skc_negtok, skc_negtok_len: see smbd_authsvc.c */

	(void) uname(&uts);
	(void) snprintf(kcfg->skc_native_os, sizeof (kcfg->skc_native_os),
	    "%s %s %s", uts.sysname, uts.release, uts.version);

	(void) strlcpy(kcfg->skc_native_lm, "Native SMB service",
	    sizeof (kcfg->skc_native_lm));
}
Exemple #26
0
DECLARE_TEST( uuid, generate )
{
	int iloop;
	uuid_t uuid, uuid_ref;
	char name_str[] = "com.rampantpixels.foundation.uuid.000000";

	uuid = uuid_null();
	uuid_ref = uuid_null();

	EXPECT_TRUE( uuid_is_null( uuid ) );
	EXPECT_TRUE( uuid_is_null( uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid_ref ) );

	//Random based
	uuid = uuid_generate_random();
	uuid_ref = uuid_null();
	
	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_TRUE( uuid_is_null( uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	uuid = uuid_generate_random();
	uuid_ref = uuid_generate_random();

	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_FALSE( uuid_is_null( uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	uuid = uuid_ref;
	
	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_FALSE( uuid_is_null( uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	for( iloop = 0; iloop < 64000; ++iloop )
	{
		uuid_ref = uuid;
		uuid = uuid_generate_random();
	
		EXPECT_FALSE( uuid_is_null( uuid ) );
		EXPECT_FALSE( uuid_is_null( uuid_ref ) );
		EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
		EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
		EXPECT_TRUE( uuid_equal( uuid, uuid ) );
		EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );
	}
	
	//Time based
	uuid = uuid_generate_time();
	uuid_ref = uuid_null();
	
	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_TRUE( uuid_is_null( uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	uuid = uuid_generate_time();
	uuid_ref = uuid_generate_time();

	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_FALSE( uuid_is_null( uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	uuid = uuid_ref;
	
	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_FALSE( uuid_is_null( uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	for( iloop = 0; iloop < 64000; ++iloop )
	{
		uuid_ref = uuid;
		uuid = uuid_generate_time();
	
		EXPECT_FALSE( uuid_is_null( uuid ) );
		EXPECT_FALSE( uuid_is_null( uuid_ref ) );
		EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
		EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
		EXPECT_TRUE( uuid_equal( uuid, uuid ) );
		EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );
	}
	
	//Name based
	uuid = uuid_generate_name( UUID_DNS, "com.rampantpixels.foundation.uuid" );
	uuid_ref = uuid_null();
	
	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_TRUE( uuid_is_null( uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	uuid = uuid_generate_name( UUID_DNS, "com.rampantpixels.foundation.uuid.1" );
	uuid_ref = uuid_generate_name( UUID_DNS, "com.rampantpixels.foundation.uuid.2" );

	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_FALSE( uuid_is_null( uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	uuid = uuid_generate_name( UUID_DNS, "com.rampantpixels.foundation.uuid.2" );
	
	EXPECT_FALSE( uuid_is_null( uuid ) );
	EXPECT_FALSE( uuid_is_null( uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid_ref ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid, uuid ) );
	EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );

	for( iloop = 0; iloop < 10000; ++iloop )
	{
		string_format_buffer( name_str, 40, "com.rampantpixels.foundation.uuid.%05u", iloop );
		
		uuid_ref = uuid;
		uuid = uuid_generate_name( UUID_DNS, name_str );
	
		EXPECT_FALSE( uuid_is_null( uuid ) );
		EXPECT_FALSE( uuid_is_null( uuid_ref ) );
		EXPECT_FALSE( uuid_equal( uuid, uuid_ref ) );
		EXPECT_FALSE( uuid_equal( uuid_ref, uuid ) );
		EXPECT_TRUE( uuid_equal( uuid, uuid ) );
		EXPECT_TRUE( uuid_equal( uuid_ref, uuid_ref ) );
	}
	
	return 0;
}
/*====================================================*/
void AP_CollectAndOutputAll() {

  /*--------------*/
  /* Get data     */
  /*--------------*/

  ap_settings_t *settings = AP_getSettings();

  ap_sysData_t sysData;
  AP_Sys_GetData(&sysData);

  ap_procData_t procData;
  AP_Proc_GetData(&procData);

  ap_hpmData_t hpmData;
  AP_HPM_GetData(&hpmData);

  ap_mpiData_t mpiData;
  AP_MPI_GetData(&mpiData);
  
  /*------------*/
  /* Open files */
  /*------------*/


  uuid_t jobId;
  if (procData.disabled == 0) {
    jobId = procData.jobId;
  } else {
    uuid_generate_time(&jobId);
    
  }

  int rank;
  if (mpiData.disabled == 0) {
    MPI_Comm_rank(MPI_COMM_WORLD, &rank); // TODO look at alternative to MPI call
  } else {
    rank = mpiData.myRank;
  }
  
  FILE *locFile = NULL;
  if (settings->flags.output_local != 0) {
    locFile = AP_openOutputFile(OUTPUT_LOCAL_DIR, 0, jobId, rank, settings->flags.debug_level);
  }

  FILE *sysFile = NULL;
  if (settings->flags.output_sys != 0) {
    sysFile = AP_openOutputFile(OUTPUT_SYS_DIR, 1, jobId, rank, settings->flags.debug_level);
  }

  /*-------------*/
  /* write data  */
  /*-------------*/

  AP_writeSettings(locFile, settings);
  AP_writeSettings(sysFile, settings);

  AP_writeSysData(locFile, "", &sysData);
  AP_writeSysData(sysFile, "", &sysData);

  AP_writeProcData(locFile, "", &procData);
  AP_writeProcData(sysFile, "", &procData);

  AP_writeHPMData(locFile, "", &hpmData);
  AP_writeHPMData(sysFile, "", &hpmData);

  AP_writeMPIData(locFile, "", &mpiData);
  AP_writeMPIData(sysFile, "", &mpiData);

  /*-------------*/
  /* close files */
  /*-------------*/

  if (locFile != NULL) fclose(locFile);
  if (sysFile != NULL) fclose(sysFile);


  return;
}
Exemple #28
0
static Datum
uuid_generate_internal(int v, unsigned char *ns, char *ptr, int len)
{
	char		strbuf[40];

	switch (v)
	{
		case 0:			/* constant-value uuids */
			strlcpy(strbuf, ptr, 37);
			break;

		case 1:			/* time/node-based uuids */
			{
#ifdef HAVE_UUID_E2FS
				uuid_t		uu;

				uuid_generate_time(uu);
				uuid_unparse(uu, strbuf);

				/*
				 * PTR, if set, replaces the trailing characters of the uuid;
				 * this is to support v1mc, where a random multicast MAC is
				 * used instead of the physical one
				 */
				if (ptr && len <= 36)
					strcpy(strbuf + (36 - len), ptr);
#else							/* BSD */
				uuid_t		uu;
				uint32_t	status = uuid_s_ok;
				char	   *str = NULL;

				uuid_create(&uu, &status);

				if (status == uuid_s_ok)
				{
					uuid_to_string(&uu, &str, &status);
					if (status == uuid_s_ok)
					{
						strlcpy(strbuf, str, 37);

						/*
						 * PTR, if set, replaces the trailing characters of
						 * the uuid; this is to support v1mc, where a random
						 * multicast MAC is used instead of the physical one
						 */
						if (ptr && len <= 36)
							strcpy(strbuf + (36 - len), ptr);
					}
					if (str)
						free(str);
				}

				if (status != uuid_s_ok)
					ereport(ERROR,
							(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
							 errmsg("uuid library failure: %d",
									(int) status)));
#endif
				break;
			}

		case 3:			/* namespace-based MD5 uuids */
		case 5:			/* namespace-based SHA1 uuids */
			{
				dce_uuid_t	uu;
#ifdef HAVE_UUID_BSD
				uint32_t	status = uuid_s_ok;
				char	   *str = NULL;
#endif

				if (v == 3)
				{
					MD5_CTX		ctx;

					MD5Init(&ctx);
					MD5Update(&ctx, ns, sizeof(uu));
					MD5Update(&ctx, (unsigned char *) ptr, len);
					/* we assume sizeof MD5 result is 16, same as UUID size */
					MD5Final((unsigned char *) &uu, &ctx);
				}
				else
				{
					SHA1_CTX	ctx;
					unsigned char sha1result[SHA1_RESULTLEN];

					SHA1Init(&ctx);
					SHA1Update(&ctx, ns, sizeof(uu));
					SHA1Update(&ctx, (unsigned char *) ptr, len);
					SHA1Final(sha1result, &ctx);
					memcpy(&uu, sha1result, sizeof(uu));
				}

				/* the calculated hash is using local order */
				UUID_TO_NETWORK(uu);
				UUID_V3_OR_V5(uu, v);

#ifdef HAVE_UUID_E2FS
				/* uuid_unparse expects local order */
				UUID_TO_LOCAL(uu);
				uuid_unparse((unsigned char *) &uu, strbuf);
#else							/* BSD */
				uuid_to_string(&uu, &str, &status);

				if (status == uuid_s_ok)
					strlcpy(strbuf, str, 37);

				if (str)
					free(str);

				if (status != uuid_s_ok)
					ereport(ERROR,
							(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
							 errmsg("uuid library failure: %d",
									(int) status)));
#endif
				break;
			}

		case 4:			/* random uuid */
		default:
			{
#ifdef HAVE_UUID_E2FS
				uuid_t		uu;

				uuid_generate_random(uu);
				uuid_unparse(uu, strbuf);
#else							/* BSD */
				snprintf(strbuf, sizeof(strbuf),
						 "%08lx-%04x-%04x-%04x-%04x%08lx",
						 (unsigned long) arc4random(),
						 (unsigned) (arc4random() & 0xffff),
						 (unsigned) ((arc4random() & 0xfff) | 0x4000),
						 (unsigned) ((arc4random() & 0x3fff) | 0x8000),
						 (unsigned) (arc4random() & 0xffff),
						 (unsigned long) arc4random());
#endif
				break;
			}
	}

	return DirectFunctionCall1(uuid_in, CStringGetDatum(strbuf));
}
Exemple #29
0
/* Determines the GUID
 * Returns 1 if successful or -1 on error
 */
int guid_generate(
     uint8_t *guid,
     size_t guid_size,
     uint8_t guid_type,
     liberror_error_t **error )
{
#if defined( WINAPI )
	UUID uuid             = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
#endif

	static char *function = "guid_generate";

	if( guid == NULL )
	{
		liberror_error_set(
		 error,
		 LIBERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid GUID.",
		 function );

		return( -1 );
	}
	if( guid_size < GUID_SIZE )
	{
		liberror_error_set(
		 error,
		 LIBERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
		 "%s: GUID too small.",
		 function );

		return( -1 );
	}
	if( guid_size > (size_t) SSIZE_MAX )
	{
		liberror_error_set(
		 error,
		 LIBERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid GUID size value exceeds maximum.",
		 function );

		return( -1 );
	}
	if( ( guid_type != GUID_TYPE_RANDOM )
	 && ( guid_type != GUID_TYPE_TIME ) )
	{
		liberror_error_set(
		 error,
		 LIBERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
		 "%s: unsupported GUID type.",
		 function );

		return( -1 );
	}
	if( guid_type == GUID_TYPE_RANDOM )
	{
#if defined( WINAPI )
		UuidCreate(
		 &uuid );

#elif defined( HAVE_UUID_GENERATE_RANDOM )
		uuid_generate_random(
		 guid );
#endif
	}
	if( guid_type == GUID_TYPE_TIME )
	{
#if defined( __BORLANDC__ ) && __BORLANDC__ <= 0x0520
		/* No support for the time type GUID */

#elif defined( WINAPI ) && _WIN32_WINNT >= 0x0500
		UuidCreateSequential(
		 &uuid );

#elif defined( HAVE_UUID_GENERATE_TIME )
		uuid_generate_time(
		 guid );
#endif
	}
#if defined( WINAPI )
	byte_stream_copy_from_uint32_little_endian(
	 guid,
	 uuid.Data1 );

	guid += 4;

	byte_stream_copy_from_uint16_little_endian(
	 guid,
	 uuid.Data2 );

	guid += 2;

	byte_stream_copy_from_uint16_little_endian(
	 guid,
	 uuid.Data3 );

	guid += 2;

	guid[ 0 ] = uuid.Data4[ 0 ];
	guid[ 1 ] = uuid.Data4[ 1 ];
	guid[ 2 ] = uuid.Data4[ 2 ];
	guid[ 3 ] = uuid.Data4[ 3 ];
	guid[ 4 ] = uuid.Data4[ 4 ];
	guid[ 5 ] = uuid.Data4[ 5 ];
	guid[ 6 ] = uuid.Data4[ 6 ];
	guid[ 7 ] = uuid.Data4[ 7 ];
#endif
	return( 1 );
}
Exemple #30
0
/* main function */
int main(int argc, char *argv[])
{
	int			opt, retval = 0;
	struct sockaddr_in	si, wsd_mcast;
	uuid_t			uuid;
	char 			uuid_str[37];
	struct sigaction	act;
	static const int 	enable = 1;
	int			out_len;
	int			conn, clients, i, activity;
	struct pollfd		fds[MAX_CLIENTS+3];
	char			iface[32] = "";
	struct 			in_addr iface_addr;

	gethostname(cd_name, sizeof(cd_name));
	iface_addr.s_addr = INADDR_ANY;

	/* process command line options */
	while ((opt = getopt(argc, argv, "dhFIn:w:i:")) != -1) {
		switch (opt) {

		case 'd':
			loglevel = LOG_DEBUG;
			asdaemon = 0;
			usesyslog = 0;
			break;

		case 'F':
			asdaemon = 0;
			break;

		case 'I':
			usesyslog = 0;
			break;

		case 'i':
			strncpy(iface, optarg, sizeof(iface));
			break;

		case 'n':
			strncpy(cd_name, optarg, sizeof(cd_name));
			break;

		case 'w':
			strncpy(cd_workgroup, optarg, sizeof(cd_workgroup));
			break;

		case 'h':
			printf("usage: wsdd [-d (debug)] [-I (interactive) [-F (foreground)]\n"
			       "            [-h] [-n hostname] [-w workgroup] [-i ip]\n");
			return(0);
		}
	}

	if (*iface)
		if (inet_aton(iface, &iface_addr) == 0) {
			wsdd_log(LOG_ERR, "Invalid interface address %s", iface);
			return 1;
		}

	/* Set signal handler for graceful shutdown */
	memset(&act, 0, sizeof(act));
 	act.sa_sigaction = &sigterm_handler;
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGTERM, &act, NULL);
	sigaction(SIGINT, &act, NULL);
	
	if (asdaemon)
		daemonize();

	if (usesyslog)
		openlog("wsdd", LOG_PID, LOG_DAEMON);

	/* Generate UUIDs */
	instance_id = time(NULL);
	uuid_generate_time(uuid);
	uuid_unparse(uuid, uuid_str);
	sprintf(endpoint, "urn:uuid:%s", uuid_str);
	uuid_generate_time(uuid);
	uuid_unparse(uuid, uuid_str);
	sprintf(sequence, "urn:uuid:%s", uuid_str);

	memset((char *) &wsd_mcast, 0, sizeof(wsd_mcast));
	wsd_mcast.sin_family = AF_INET;
	wsd_mcast.sin_port = htons(WSD_PORT);
	if (inet_aton(WSD_MCAST_ADDR, &wsd_mcast.sin_addr) == 0) {
		wsdd_log(LOG_ERR, "inet_aton() failed for wsd multicast address");
		return 1;
	}

	/* Prepare LLMNR socket */
	fds[LLMNR_UDP_SOCK].fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (fds[LLMNR_UDP_SOCK].fd == -1) {
		wsdd_log(LOG_ERR, "Failed to create socket, %s", strerror(errno));
		return 1;
	}
	setsockopt(fds[LLMNR_UDP_SOCK].fd, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));

	memset((char *) &si, 0, sizeof(si));
	si.sin_family = AF_INET;
	si.sin_port = htons(LLMNR_PORT);
	si.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(fds[LLMNR_UDP_SOCK].fd, (const struct sockaddr*)&si, sizeof(si)) == -1) {
		wsdd_log(LOG_ERR, "Failed to listen to UDP port %d for LLMNR", ntohs(si.sin_port));
		retval = 1;
		goto llmnr_udp_close;
	}	

	if (set_multicast(fds[LLMNR_UDP_SOCK].fd, LLMNR_MCAST_ADDR, &iface_addr, IP_ADD_MEMBERSHIP)) {
		wsdd_log(LOG_ERR, "Failed to add multicast for LLMNR: %s", strerror(errno));
		retval = 1;
		goto llmnr_drop_multicast;
	}

	fds[WSD_UDP_SOCK].fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (fds[WSD_UDP_SOCK].fd == -1) {
		wsdd_log(LOG_ERR, "Failed to create socket for wsdd");
		retval = 1;
		goto llmnr_drop_multicast;
	}
	setsockopt(fds[WSD_UDP_SOCK].fd, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));

	memset((char *) &si, 0, sizeof(si));
	si.sin_family = AF_INET;
	si.sin_port = htons(WSD_PORT);
	si.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(fds[WSD_UDP_SOCK].fd, (const struct sockaddr*)&si, sizeof(si)) == -1) {
		wsdd_log(LOG_ERR, "Failed to listen to UDP port %d for WSDD", ntohs(si.sin_port));
		retval = 1;
		goto wsd_udp_close;
	}

	if (set_multicast(fds[WSD_UDP_SOCK].fd, WSD_MCAST_ADDR, &iface_addr, IP_ADD_MEMBERSHIP)) {
		wsdd_log(LOG_ERR, "Failed to add multicast for WSDD: %s", strerror(errno));
		retval = 1;
		goto wsd_drop_multicast;
	}

	fds[WSD_HTTP_SOCK].fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (fds[WSD_HTTP_SOCK].fd == -1) {
		wsdd_log(LOG_ERR, "Failed to create http socket");
		retval = 1;
		goto wsd_drop_multicast;
	}	
	setsockopt(fds[WSD_HTTP_SOCK].fd, SOL_SOCKET, SO_REUSEADDR, &enable , sizeof(enable));

	memset((char *) &si, 0, sizeof(si));
	si.sin_family = AF_INET;
	si.sin_port = htons(WSD_HTTP_PORT);
	si.sin_addr = iface_addr;
	if (bind(fds[WSD_HTTP_SOCK].fd, (const struct sockaddr*)&si, sizeof(si)) < 0) {
		wsdd_log(LOG_ERR, "Failed to listen to HTTP port %d", WSD_HTTP_PORT);
		retval = 1;
		goto wsd_http_close;
	}	

	if (listen(fds[WSD_HTTP_SOCK].fd, 5) < 0) {
		wsdd_log(LOG_ERR, "Failed to listen to HTTP port %d", WSD_HTTP_PORT);
		retval = 1;
		goto wsd_http_close;
	}

	/* Send hello message */
	out_len = sizeof(out);
	action_hello(out, &out_len, wsd_device, 0);
	if (udp_send_all(fds[WSD_UDP_SOCK].fd, &iface_addr, (const struct sockaddr*)&wsd_mcast, sizeof(wsd_mcast), out_len) == -1) {
		wsdd_log(LOG_ERR, "Failed to send hello with %d", errno);
		retval = 1;
		goto wsd_http_close;
	}

	clients = 0;
	fds[WSD_HTTP_SOCK].events = POLLIN;
	fds[WSD_UDP_SOCK].events = POLLIN;
	fds[LLMNR_UDP_SOCK].events = POLLIN;
	
	while(!terminate) {
		activity = poll(fds , 3 + clients, -1);
		if (activity == -1) {
			if (errno != EINTR)
				wsdd_log(LOG_ERR, "Select failed");
			continue;
		}
		
		if (fds[WSD_HTTP_SOCK].revents & POLLIN) {
			conn = accept(fds[WSD_HTTP_SOCK].fd, NULL, NULL);
			if (conn < 0)
				continue;
			if (clients < MAX_CLIENTS) {
				fds[3+clients].fd = conn;
				fds[3+clients].events = POLLIN;
				fds[3+clients].revents = 0;
				clients++;
			} else
				close(conn);
			--activity;
			if (!activity)
				continue;
		}

		if (fds[WSD_UDP_SOCK].revents & POLLIN) {
			wsd_udp_request(fds[WSD_UDP_SOCK].fd);
			--activity;
			if (!activity)
				continue;
		}

		if (fds[LLMNR_UDP_SOCK].revents & POLLIN) {
			llmnr_udp_request(fds[LLMNR_UDP_SOCK].fd);
			--activity;
			if (!activity)
				continue;
		}

		i = 0;
		while (i<clients && activity) {
			if (fds[3+i].revents & POLLIN) {
				conn = fds[3+i].fd;
				wsdd_http_request(conn);
				shutdown(conn, SHUT_RDWR);
				close(conn);
				--clients;
				--activity;
				fds[3+i] = fds[3+clients];
			} else
				i++;
		}
	}

	/* Send bye message */
	out_len = sizeof(out);
	action_bye(out, &out_len, wsd_device, 0);
	if (udp_send_all(fds[WSD_UDP_SOCK].fd, &iface_addr, (const struct sockaddr*)&wsd_mcast, sizeof(wsd_mcast), out_len) == -1) {
		wsdd_log(LOG_ERR, "Failed to send bye with %d", errno);
		retval = 1;
	}

wsd_http_close:	
	shutdown(fds[WSD_HTTP_SOCK].fd, SHUT_RDWR);
	close(fds[WSD_HTTP_SOCK].fd);

wsd_drop_multicast:
	set_multicast(fds[WSD_UDP_SOCK].fd, WSD_MCAST_ADDR, &iface_addr, IP_DROP_MEMBERSHIP);

wsd_udp_close:
	shutdown(fds[WSD_UDP_SOCK].fd, SHUT_RDWR);
	close(fds[WSD_UDP_SOCK].fd);
	
llmnr_drop_multicast:
	set_multicast(fds[LLMNR_UDP_SOCK].fd, LLMNR_MCAST_ADDR, &iface_addr, IP_DROP_MEMBERSHIP);

llmnr_udp_close:
	shutdown(fds[LLMNR_UDP_SOCK].fd, SHUT_RDWR);
	close(fds[LLMNR_UDP_SOCK].fd);

	if (asdaemon)
		closelog();

	return retval;
}