summaryrefslogtreecommitdiff
path: root/ldap/c-sdk/libraries/libldap/nsprthreadtest.c
blob: f9af68b42323ec3555419d5a7f3818e29d87ce85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 * 
 * The contents of this file are subject to the Mozilla Public License Version 
 * 1.1 (the "License"); you may not use this file except in compliance with 
 * the License. You may obtain a copy of the License at 
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 * 
 * The Original Code is Mozilla Communicator client code, released
 * March 31, 1998.
 * 
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1998-1999
 * the Initial Developer. All Rights Reserved.
 * 
 * Contributor(s):
 * 
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * 
 * ***** END LICENSE BLOCK ***** */
#include <nspr.h>
#include <stdio.h>
#include <ldap.h>

#define NAME		"cn=Directory Manager"
#define PASSWORD	"secret99"
#define BASE		"dc=example,dc=com"

static int simplebind( LDAP *ld, char *msg, int tries );
static void search_thread( void * );
static void modify_thread( void * );
static void add_thread( void * );
static void delete_thread( void * );
static void set_ld_error();
static int  get_ld_error();
static void set_errno();
static int  get_errno();
static void tsd_setup();
static void *my_mutex_alloc( void );
static void my_mutex_free( void * );
static int my_mutex_lock( void * );
static int my_mutex_unlock( void * );
static LDAPHostEnt *my_gethostbyname( const char *name, LDAPHostEnt *result,
	char *buffer, int buflen, int *statusp, void *extradata );
static LDAPHostEnt *my_gethostbyaddr( const char *addr, int length,
	int type, LDAPHostEnt *result, char *buffer, int buflen,
	int *statusp, void *extradata );
static LDAPHostEnt *copyPRHostEnt2LDAPHostEnt( LDAPHostEnt *ldhp,
	PRHostEnt *prhp );

typedef struct ldapmsgwrapper {
    LDAPMessage			*lmw_messagep;
    struct ldapmsgwrapper	*lmw_next;
} ldapmsgwrapper;


#define CONNECTION_ERROR( lderr )	( (lderr) == LDAP_SERVER_DOWN || \
					(lderr) == LDAP_CONNECT_ERROR )


LDAP		*ld;
PRUintn		tsdindex;
#ifdef LDAP_MEMCACHE
LDAPMemCache	*memcache = NULL;
#define MEMCACHE_SIZE		(256*1024)	/* 256K bytes */
#define MEMCACHE_TTL		(15*60)		/* 15 minutes */
#endif


main( int argc, char **argv )
{
	PRThread		*search_tid, *search_tid2, *search_tid3;
	PRThread		*search_tid4, *modify_tid, *add_tid;
	PRThread		*delete_tid;
	struct ldap_thread_fns	tfns;
	struct ldap_dns_fns	dnsfns;
	int			rc;

	if ( argc != 3 ) {
		fprintf( stderr, "usage: %s host port\n", argv[0] );
		exit( 1 );
	}

	PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 0 );
	if ( PR_NewThreadPrivateIndex( &tsdindex, NULL ) != PR_SUCCESS ) {
		perror( "PR_NewThreadPrivateIndex" );
		exit( 1 );
	}
	tsd_setup();	/* for main thread */

	if ( (ld = ldap_init( argv[1], atoi( argv[2] ) )) == NULL ) {
		perror( "ldap_open" );
		exit( 1 );
	}

	/* set thread function pointers */
	memset( &tfns, '\0', sizeof(struct ldap_thread_fns) );
	tfns.ltf_mutex_alloc = my_mutex_alloc;
	tfns.ltf_mutex_free = my_mutex_free;
	tfns.ltf_mutex_lock = my_mutex_lock;
	tfns.ltf_mutex_unlock = my_mutex_unlock;
	tfns.ltf_get_errno = get_errno;
	tfns.ltf_set_errno = set_errno;
	tfns.ltf_get_lderrno = get_ld_error;
	tfns.ltf_set_lderrno = set_ld_error;
	tfns.ltf_lderrno_arg = NULL;
	if ( ldap_set_option( ld, LDAP_OPT_THREAD_FN_PTRS, (void *) &tfns )
	    != 0 ) {
		ldap_perror( ld, "ldap_set_option: thread functions" );
		exit( 1 );
	}

	/* set DNS function pointers */
	memset( &dnsfns, '\0', sizeof(struct ldap_dns_fns) );
	dnsfns.lddnsfn_bufsize = PR_NETDB_BUF_SIZE;
	dnsfns.lddnsfn_gethostbyname = my_gethostbyname;
	dnsfns.lddnsfn_gethostbyaddr = my_gethostbyaddr;
	if ( ldap_set_option( ld, LDAP_OPT_DNS_FN_PTRS, (void *)&dnsfns )
	    != 0 ) {
		ldap_perror( ld, "ldap_set_option: DNS functions" );
		exit( 1 );
	}

#ifdef LDAP_MEMCACHE
	/* create the in-memory cache */
	if (( rc = ldap_memcache_init( MEMCACHE_TTL, MEMCACHE_SIZE, NULL,
	    &tfns, &memcache )) != LDAP_SUCCESS ) {
		fprintf( stderr, "ldap_memcache_init failed - %s\n",
		    ldap_err2string( rc ));
		exit( 1 );
	}
	if (( rc = ldap_memcache_set( ld, memcache )) != LDAP_SUCCESS ) {
		fprintf( stderr, "ldap_memcache_set failed - %s\n",
		    ldap_err2string( rc ));
		exit( 1 );
	}
#endif

	/*
	 * set option so that the next call to ldap_simple_bind_s() after
	 * the server connection is lost will attempt to reconnect.
	 */
	if ( ldap_set_option( ld, LDAP_OPT_RECONNECT, LDAP_OPT_ON ) != 0 ) {
		ldap_perror( ld, "ldap_set_option: reconnect" );
		exit( 1 );
	}

	/* initial bind */
	if ( simplebind( ld, "ldap_simple_bind_s/main", 1 ) != LDAP_SUCCESS ) {
		exit( 1 );
	}

	/* create the operation threads */
	if ( (search_tid = PR_CreateThread( PR_USER_THREAD, search_thread,
	    "1", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread search_thread" );
		exit( 1 );
	}
	if ( (modify_tid = PR_CreateThread( PR_USER_THREAD, modify_thread,
	    "2", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread modify_thread" );
		exit( 1 );
	}
	if ( (search_tid2 = PR_CreateThread( PR_USER_THREAD, search_thread,
	    "3", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread search_thread 2" );
		exit( 1 );
	}
	if ( (add_tid = PR_CreateThread( PR_USER_THREAD, add_thread,
	    "4", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread add_thread" );
		exit( 1 );
	}
	if ( (search_tid3 = PR_CreateThread( PR_USER_THREAD, search_thread,
	    "5", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread search_thread 3" );
		exit( 1 );
	}
	if ( (delete_tid = PR_CreateThread( PR_USER_THREAD, delete_thread,
	    "6", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread delete_thread" );
		exit( 1 );
	}
	if ( (search_tid4 = PR_CreateThread( PR_USER_THREAD, search_thread,
	    "7", PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD,
	    0 )) == NULL ) {
		perror( "PR_CreateThread search_thread 4" );
		exit( 1 );
	}

	PR_Cleanup();
	return( 0 );
}


static int
simplebind( LDAP *ld, char *msg, int tries )
{
	int	rc;

	while ( tries-- > 0 ) {
		rc = ldap_simple_bind_s( ld, NAME, PASSWORD );
		if ( rc != LDAP_SUCCESS ) {
			ldap_perror( ld, msg );
		}
		if ( tries == 0 || !CONNECTION_ERROR( rc )) {
			return( rc );
		}
		fprintf( stderr,
		    "%s: sleeping for 5 secs - will try %d more time(s)...\n",
		    msg, tries );
		sleep( 5 );
	}

	return( rc );
}


static void
search_thread( void *arg1 )
{
	LDAPMessage	*res;
	LDAPMessage	*e;
	char		*a;
	char		**v;
	char		*dn;
	BerElement	*ber;
	int		i, rc, msgid;
	void		*tsd;
	char		*id = arg1;

	printf( "search_thread\n" );
	tsd_setup();
	for ( ;; ) {
		printf( "%sSearching...\n", id );
		if ( (msgid = ldap_search( ld, BASE, LDAP_SCOPE_SUBTREE,
		    "(objectclass=*)", NULL, 0 )) == -1 ) {
			ldap_perror( ld, "ldap_search_s" );
			rc =  ldap_get_lderrno( ld, NULL, NULL );
			if ( CONNECTION_ERROR( rc ) && simplebind( ld,
			    "bind-search_thread", 5 ) != LDAP_SUCCESS ) {
				return;
			}
			continue;
		}
		while ( (rc = ldap_result( ld, msgid, 0, NULL, &res ))
		    == LDAP_RES_SEARCH_ENTRY ) {
			for ( e = ldap_first_entry( ld, res ); e != NULL;
			    e = ldap_next_entry( ld, e ) ) {
				dn = ldap_get_dn( ld, e );
				/* printf( "%sdn: %s\n", id, dn ); */
				free( dn );
				for ( a = ldap_first_attribute( ld, e, &ber );
				    a != NULL; a = ldap_next_attribute( ld, e,
				    ber ) ) {
					v = ldap_get_values( ld, e, a );
					for ( i = 0; v && v[i] != 0; i++ ) {
						/*
						printf( "%s%s: %s\n", id, a,
						    v[i] );
						*/
					}
					ldap_value_free( v );
					ldap_memfree( a );
				}
				if ( ber != NULL ) {
					ber_free( ber, 0 );
				}
			}
			ldap_msgfree( res );
			/* printf( "%s\n", id ); */
		}

		if ( rc == -1 || ldap_result2error( ld, res, 0 ) !=
		    LDAP_SUCCESS ) {
			ldap_perror( ld, "ldap_search" );
		} else {
			printf( "%sDone with one round\n", id );
		}

		if ( rc == -1 ) {
			rc = ldap_get_lderrno( ld, NULL, NULL );
			if ( CONNECTION_ERROR( rc ) && simplebind( ld,
			    "bind-search_thread", 5 ) != LDAP_SUCCESS ) {
				return;
			}
		}
	}
}

static void
modify_thread( void *arg1 )
{
	LDAPMessage	*res;
	LDAPMessage	*e;
	int		i, modentry, entries, msgid, rc;
	LDAPMod		mod;
	LDAPMod		*mods[2];
	char		*vals[2];
	char		*dn;
	char		*id = arg1;
	ldapmsgwrapper	*list, *lmwp, *lastlmwp;

	printf( "modify_thread\n" );
	tsd_setup();
	if ( (msgid = ldap_search( ld, BASE, LDAP_SCOPE_SUBTREE,
	    "(objectclass=*)", NULL, 0 )) == -1 ) {
		ldap_perror( ld, "ldap_search_s" );
		exit( 1 );
	}
	entries = 0;
	list = lastlmwp = NULL;
	while ( (rc = ldap_result( ld, msgid, 0, NULL, &res ))
	    == LDAP_RES_SEARCH_ENTRY ) {
		entries++;
		if (( lmwp = (ldapmsgwrapper *)
			malloc( sizeof( ldapmsgwrapper ))) == NULL ) {
			perror( "modify_thread: malloc" );
			exit( 1 );
		}
		lmwp->lmw_messagep = res;
		lmwp->lmw_next = NULL;
		if ( lastlmwp == NULL ) {
			list = lastlmwp = lmwp;
		} else {
			lastlmwp->lmw_next = lmwp;
		}
		lastlmwp = lmwp;
	}
	if ( rc == -1 || ldap_result2error( ld, res, 0 ) != LDAP_SUCCESS ) {
		ldap_perror( ld, "modify_thread: ldap_search" );
		exit( 1 );
	} else {
		entries++;
		printf( "%sModify got %d entries\n", id, entries );
	}

	mods[0] = &mod;
	mods[1] = NULL;
	vals[0] = "bar";
	vals[1] = NULL;
	for ( ;; ) {
		modentry = rand() % entries;
		for ( i = 0, lmwp = list; lmwp != NULL && i < modentry;
		    i++, lmwp = lmwp->lmw_next ) {
			/* NULL */
		}

		if ( lmwp == NULL ) {
			fprintf( stderr,
			    "%sModify could not find entry %d of %d\n",
			    id, modentry, entries );
			continue;
		}
		e = lmwp->lmw_messagep;
		printf( "%sPicked entry %d of %d\n", id, i, entries );
		dn = ldap_get_dn( ld, e );
		mod.mod_op = LDAP_MOD_REPLACE;
		mod.mod_type = "description";
		mod.mod_values = vals;
		printf( "%sModifying (%s)\n", id, dn );
		if (( rc = ldap_modify_s( ld, dn, mods )) != LDAP_SUCCESS ) {
			ldap_perror( ld, "ldap_modify_s" );
			if ( CONNECTION_ERROR( rc ) && simplebind( ld,
			    "bind-modify_thread", 5 ) != LDAP_SUCCESS ) {
				return;
			}
		}
		free( dn );
	}
}

static void
add_thread( void *arg1 )
{
	LDAPMod	mod[5];
	LDAPMod	*mods[6];
	char	dn[BUFSIZ], name[40];
	char	*cnvals[2], *snvals[2], *ocvals[2];
	int	i, rc;
	char	*id = arg1;

	printf( "add_thread\n" );
	tsd_setup();
	for ( i = 0; i < 5; i++ ) {
		mods[i] = &mod[i];
	}
	mods[5] = NULL;
	mod[0].mod_op = 0;
	mod[0].mod_type = "cn";
	mod[0].mod_values = cnvals;
	cnvals[1] = NULL;
	mod[1].mod_op = 0;
	mod[1].mod_type = "sn";
	mod[1].mod_values = snvals;
	snvals[1] = NULL;
	mod[2].mod_op = 0;
	mod[2].mod_type = "objectclass";
	mod[2].mod_values = ocvals;
	ocvals[0] = "person";
	ocvals[1] = NULL;
	mods[3] = NULL;

	for ( ;; ) {
		sprintf( name, "%d", rand() );
		sprintf( dn, "cn=%s, " BASE, name );
		cnvals[0] = name;
		snvals[0] = name;

		printf( "%sAdding entry (%s)\n", id, dn );
		if (( rc = ldap_add_s( ld, dn, mods )) != LDAP_SUCCESS ) {
			ldap_perror( ld, "ldap_add_s" );
			if ( CONNECTION_ERROR( rc ) && simplebind( ld,
			    "bind-add_thread", 5 ) != LDAP_SUCCESS ) {
				return;
			}
		}
	}
}

static void
delete_thread( void *arg1 )
{
	LDAPMessage	*res;
	char		dn[BUFSIZ], name[40];
	int		entries, msgid, rc;
	char		*id = arg1;

	printf( "delete_thread\n" );
	tsd_setup();
	if ( (msgid = ldap_search( ld, BASE, LDAP_SCOPE_SUBTREE,
	    "(objectclass=*)", NULL, 0 )) == -1 ) {
		ldap_perror( ld, "delete_thread: ldap_search_s" );
		exit( 1 );
	}
	entries = 0;
	while ( (rc = ldap_result( ld, msgid, 0, NULL, &res ))
	    == LDAP_RES_SEARCH_ENTRY ) {
		entries++;
		ldap_msgfree( res );
	}
	entries++;
	if ( rc == -1 || ldap_result2error( ld, res, 1 ) != LDAP_SUCCESS ) {
		ldap_perror( ld, "delete_thread: ldap_search" );
	} else {
		printf( "%sDelete got %d entries\n", id, entries );
	}

	for ( ;; ) {
		sprintf( name, "%d", rand() );
		sprintf( dn, "cn=%s, " BASE, name );

		printf( "%sDeleting entry (%s)\n", id, dn );
		if (( rc = ldap_delete_s( ld, dn )) != LDAP_SUCCESS ) {
			ldap_perror( ld, "ldap_delete_s" );
			if ( CONNECTION_ERROR( rc ) && simplebind( ld,
			    "bind-delete_thread", 5 ) != LDAP_SUCCESS ) {
				return;
			}
		}
	}
}

struct ldap_error {
	int	le_errno;
	char	*le_matched;
	char	*le_errmsg;
};

static void
tsd_setup()
{
	void	*tsd;

	tsd = (void *) PR_GetThreadPrivate( tsdindex );
	if ( tsd != NULL ) {
		fprintf( stderr, "tsd non-null!\n" );
		exit( 1 );
	}
	tsd = (void *) calloc( 1, sizeof(struct ldap_error) );
	if ( PR_SetThreadPrivate( tsdindex, tsd ) != 0 ) {
		perror( "PR_SetThreadPrivate" );
		exit( 1 );
	}
}

static void
set_ld_error( int err, char *matched, char *errmsg, void *dummy )
{
	struct ldap_error *le;

	le = (void *) PR_GetThreadPrivate( tsdindex );
	le->le_errno = err;
	if ( le->le_matched != NULL ) {
		ldap_memfree( le->le_matched );
	}
	le->le_matched = matched;
	if ( le->le_errmsg != NULL ) {
		ldap_memfree( le->le_errmsg );
	}
	le->le_errmsg = errmsg;
}

static int
get_ld_error( char **matchedp, char **errmsgp, void *dummy )
{
	struct ldap_error *le;

	le = PR_GetThreadPrivate( tsdindex );
	if ( matchedp != NULL ) {
		*matchedp = le->le_matched;
	}
	if ( errmsgp != NULL ) {
		*errmsgp = le->le_errmsg;
	}
	return( le->le_errno );
}

static void
set_errno( int oserrno )
{
	/* XXXmcs: should this be PR_SetError( oserrno, 0 )? */
	PR_SetError( PR_UNKNOWN_ERROR, oserrno );
}

static int
get_errno( void )
{
	/* XXXmcs: should this be PR_GetError()? */
	return( PR_GetOSError());
}

static void *
my_mutex_alloc( void )
{
	return( (void *)PR_NewLock());
}

static void
my_mutex_free( void *mutex )
{
	PR_DestroyLock( (PRLock *)mutex );
}

static int
my_mutex_lock( void *mutex )
{
	PR_Lock( (PRLock *)mutex );
	return( 0 );
}

static int
my_mutex_unlock( void *mutex )
{
	if ( PR_Unlock( (PRLock *)mutex ) == PR_FAILURE ) {
		return( -1 );
	}

	return( 0 );
}

static LDAPHostEnt *
my_gethostbyname( const char *name, LDAPHostEnt *result,
	char *buffer, int buflen, int *statusp, void *extradata )
{
	PRHostEnt	prhent;

	if ( PR_GetHostByName( name, buffer, buflen,
	    &prhent ) != PR_SUCCESS ) {
		return( NULL );
	}

	return( copyPRHostEnt2LDAPHostEnt( result, &prhent ));
}

static LDAPHostEnt *
my_gethostbyaddr( const char *addr, int length, int type, LDAPHostEnt *result,
	char *buffer, int buflen, int *statusp, void *extradata )
{
	PRHostEnt	prhent;

	if ( PR_GetHostByAddr( (PRNetAddr *)addr, buffer, buflen,
	    &prhent ) != PR_SUCCESS ) {
		return( NULL );
	}

	return( copyPRHostEnt2LDAPHostEnt( result, &prhent ));
}

static LDAPHostEnt *
copyPRHostEnt2LDAPHostEnt( LDAPHostEnt *ldhp, PRHostEnt *prhp )
{
	ldhp->ldaphe_name = prhp->h_name;
	ldhp->ldaphe_aliases = prhp->h_aliases;
	ldhp->ldaphe_addrtype = prhp->h_addrtype;
	ldhp->ldaphe_length =  prhp->h_length;
	ldhp->ldaphe_addr_list =  prhp->h_addr_list;
	return( ldhp );
}