Changeset 1815 for pjproject/trunk
- Timestamp:
- Feb 21, 2008 9:36:34 PM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/guid.h
r1417 r1815 50 50 * dependent on the algorithm used internally to generate the GUID string. 51 51 * If real GUID generator is used, then the length will be between 32 and 52 * 36 bytes. If shadow GUID generator is used, then the length 53 * will be 20 bytes. Application should not assume which algorithm will 52 * 36 bytes. Application should not assume which algorithm will 54 53 * be used by GUID generator. 55 54 * -
pjproject/trunk/pjlib/src/pj/guid_simple.c
r1417 r1815 18 18 */ 19 19 #include <pj/guid.h> 20 #include <pj/assert.h> 21 #include <pj/rand.h> 20 22 #include <pj/os.h> 21 #include <pj/rand.h>22 23 #include <pj/string.h> 23 24 24 PJ_DEF_DATA(const unsigned) PJ_GUID_STRING_LENGTH=20; 25 PJ_DEF_DATA(const unsigned) PJ_GUID_STRING_LENGTH=32; 26 27 static char guid_chars[64]; 25 28 26 29 PJ_DEF(unsigned) pj_GUID_STRING_LENGTH() … … 29 32 } 30 33 31 static void init_ mac_address(unsigned char mac_addr[16])34 static void init_guid_chars(void) 32 35 { 33 unsigned long *ulval1 = (unsigned long*) &mac_addr[0];34 unsigned short *usval1 = (unsigned short*) &mac_addr[4];36 char *p = guid_chars; 37 unsigned i; 35 38 36 *ulval1 = pj_rand(); 37 *usval1 = (unsigned short) pj_rand(); 39 for (i=0; i<10; ++i) 40 *p++ = '0'+i; 41 42 for (i=0; i<26; ++i) { 43 *p++ = 'a'+i; 44 *p++ = 'A'+i; 45 } 46 47 *p++ = '-'; 48 *p++ = '.'; 38 49 } 39 50 40 51 PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str) 41 52 { 42 static int guid_initialized; 43 static unsigned pid; 44 static char str_pid[32]; 45 static unsigned char mac_addr[32]; 46 static char str_mac_addr[32]; 47 static unsigned clock_seq; 53 char *p, *end; 48 54 49 55 PJ_CHECK_STACK(); 50 56 51 if (guid_initialized == 0) { 52 pid = pj_getpid(); 53 init_mac_address(mac_addr); 54 clock_seq = 0; 55 56 sprintf(str_pid, "%04x", pid); 57 sprintf(str_mac_addr, "%02x%02x%02x%02x%02x%02x", 58 mac_addr[0], mac_addr[1], mac_addr[2], 59 mac_addr[3], mac_addr[4], mac_addr[5]); 60 61 guid_initialized = 1; 57 if (guid_chars[0] == '\0') { 58 pj_enter_critical_section(); 59 if (guid_chars[0] == '\0') { 60 init_guid_chars(); 61 } 62 pj_enter_critical_section(); 62 63 } 63 64 64 strcpy(str->ptr, str_pid); 65 sprintf(str->ptr+4, "%08x", clock_seq++); 66 pj_memcpy(str->ptr+12, str_mac_addr, 8); 67 str->slen = 20; 65 /* This would only work if PJ_GUID_STRING_LENGTH is multiple of 2 bytes */ 66 pj_assert(PJ_GUID_STRING_LENGTH % 2 == 0); 68 67 68 for (p=str->ptr, end=p+PJ_GUID_STRING_LENGTH; p<end; ) { 69 /* Assumes rand() only has 16bit randomness */ 70 unsigned short val = pj_rand(); 71 *p++ = guid_chars[(val >> 8) & 63]; 72 *p++ = guid_chars[(val & 0xFF) & 63]; 73 } 74 75 str->slen = PJ_GUID_STRING_LENGTH; 69 76 return str; 70 77 } -
pjproject/trunk/pjnath/build/Makefile
r1495 r1815 72 72 # $(TARGET) is defined in os-$(OS_NAME).mak file in current directory. 73 73 # 74 TARGETS := pjnath pjnath-test pjstun-client pjstun-srv-test 74 TARGETS := pjnath pjnath-test 75 #pjstun-client pjstun-srv-test 75 76 76 77 all: $(TARGETS) -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r1735 r1815 512 512 513 513 514 /* Init random seed */ 515 static void init_random_seed(void) 516 { 517 pj_sockaddr addr; 518 const pj_str_t *hostname; 519 pj_uint32_t pid; 520 pj_time_val t; 521 unsigned seed=0; 522 523 /* Add hostname */ 524 hostname = pj_gethostname(); 525 seed = pj_hash_calc(seed, hostname->ptr, (int)hostname->slen); 526 527 /* Add primary IP address */ 528 if (pj_gethostip(pj_AF_INET(), &addr)==PJ_SUCCESS) 529 seed = pj_hash_calc(seed, &addr.ipv4.sin_addr, 4); 530 531 /* Get timeofday */ 532 pj_gettimeofday(&t); 533 seed = pj_hash_calc(seed, &t, sizeof(t)); 534 535 /* Add PID */ 536 pid = pj_getpid(); 537 seed = pj_hash_calc(seed, &pid, sizeof(pid)); 538 539 /* Init random seed */ 540 pj_srand(seed); 541 } 542 514 543 /* 515 544 * Instantiate pjsua application. … … 529 558 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 530 559 560 /* Init random seed */ 561 init_random_seed(); 531 562 532 563 /* Init PJLIB-UTIL: */
Note: See TracChangeset
for help on using the changeset viewer.