summaryrefslogtreecommitdiff
path: root/server/bdump.c
blob: 092a506f33b58a0429badadb5a64f3215b4ce81d (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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/* This file is part of the Project Athena Zephyr Notification System.
 * It contains functions for dumping server state between servers.
 *
 *	Created by:	John T. Kohl
 *
 *	$Source$
 *	$Author$
 *
 *	Copyright (c) 1987 by the Massachusetts Institute of Technology.
 *	For copying and distribution information, see the file
 *	"mit-copyright.h". 
 */

#include <zephyr/mit-copyright.h>

#ifndef lint
#ifndef SABER
static char rcsid_bdump_s_c[] = "$Header$";
#endif SABER
#endif lint

#include "zserver.h"
#include <sys/socket.h>

static void close_bdump(), bdump_ask_for(), bdump_recv_loop();
static void bdump_send_loop(), gbd_loop(), sbd_loop();
static void send_host_register(), send_subs(), send_done(), send_locations();
static void send_list(), send_normal_tcp();
static Code_t get_packet(), extract_sin();

static timer bdump_timer;

/*
 * External functions are:
 *
 * void bdump_offer(who)
 *	strut sockaddr_in *who;
 *
 * void bdump_send()
 *
 * void bdump_get(notice, auth, who, server)
 *	ZNotice_t *notice;
 *	int auth;
 *	struct sockaddr_in *who;
 *	ZServerDesc_t *server;
 *
 * Code_t bdump_send_list_tcp(kind, port, class, inst, opcode,
 *			    sender, recip, lyst, num)
 *	ZNotice_Kind_t kind;
 *	u_short port;
 *	char *class, *inst, *opcode, *sender, *recip;
 *	char *lyst[];
 *	int num;
 */
 
/*
 * Functions for performing a brain dump between servers.
 */

/*
 * offer the brain dump to another server
 */

void
bdump_offer(who)
struct sockaddr_in *who;
{
	Code_t retval;
	char buf[512], *addr, *lyst[2];

	if ((bdump_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0){
		syslog(LOG_ERR,"bdump socket: %m");
		bdump_socket = 0;
		return;
	}
	bzero((caddr_t) &bdump_sin, sizeof(bdump_sin));
	bdump_sin.sin_port = htons((u_short)((getpid()*8)&0xfff)+(((int)random()>>4)&0xf)+1024);
	bdump_sin.sin_addr = my_addr;
	bdump_sin.sin_family = AF_INET;
	do {
		if ((retval = bind(bdump_socket, (struct sockaddr *) &bdump_sin, sizeof(bdump_sin))) < 0) {
			if (errno == EADDRINUSE)
				bdump_sin.sin_port = htons(ntohs(bdump_sin.sin_port) + 1);
			else {
				syslog(LOG_ERR, "bdump bind %d: %m", htons(bdump_sin.sin_port));
				(void) close(bdump_socket);
				bdump_socket = 0;
				return;
			}
		}
	} while (retval < 0);

	(void) listen(bdump_socket, 1);

	bdump_timer = timer_set_rel(20L, close_bdump, (caddr_t) 0);
	FD_SET(bdump_socket, &interesting);
	nfildes = max(bdump_socket, srv_socket) + 1;


	addr = inet_ntoa(bdump_sin.sin_addr);
	(void) sprintf(buf, "%d", ntohs(bdump_sin.sin_port));
	lyst[0] = addr;
	lyst[1] = buf;

	if ((retval = ZSetDestAddr(who)) != ZERR_NONE) {
		syslog(LOG_WARNING, "obd set addr: %s",
		       error_message(retval));
		return;
	}

	/* myname is the hostname */
	send_list(ACKED, sock_sin.sin_port, ZEPHYR_ADMIN_CLASS, "",
		  ADMIN_BDUMP, myname, "", lyst, 2);
	
	return;
}

/*
 * Accept a connection, and send the brain dump to the other server
 */

void
bdump_send()
{
	int sock;
	struct sockaddr_in from;
	ZServerDesc_t *server;
	int fromlen = sizeof(from);

	zdbug((LOG_DEBUG, "bdump_send"));
	/* accept the connection, and send the brain dump */
	sock = accept(bdump_socket, &from, &fromlen);

	from.sin_port = sock_sin.sin_port; /* we don't care what port
					    it came from, and we need to
					    fake out server_which_server() */
	server = server_which_server(&from);
	if (!server) {
		syslog(LOG_ERR,"unknown server?");
		server = limbo_server;
	}
	zdbug((LOG_DEBUG, "sbd connected"));

	/* shut down the listening socket and the timer */
	FD_CLR(bdump_socket, &interesting);
	(void) close(bdump_socket);
	nfildes = srv_socket + 1;
	bdump_socket = 0;
	timer_reset(bdump_timer);


	/* Now begin the brain dump.  Set the Zephyr port to be the
	   TCP connection.  This will work since recvfrom and sendto
	   work even on TCP connections, but the sockaddr_in addresses
	   are ignored */
	(void) ZSetFD(sock);
#ifdef notdef
	/* receive the authenticator */
	/* mutually authenticate */
#endif notdef

	sbd_loop(&from);
	gbd_loop(server);

	zdbug((LOG_DEBUG, "sbd finished"));
	if (server != limbo_server)
		server->zs_state = SERV_UP;

	(void) ZSetFD(srv_socket);
	(void) close(sock);
	return;
}

/*ARGSUSED*/
void
bdump_get(notice, auth, who, server)
ZNotice_t *notice;
int auth;
struct sockaddr_in *who;
ZServerDesc_t *server;
{
	struct sockaddr_in target;
	int sock;
	Code_t retval;

	zdbug((LOG_DEBUG, "bdump avail"));

	if ((retval = extract_sin(notice, &target)) != ZERR_NONE) {
		syslog(LOG_ERR, "gbd sin: %s", error_message(retval));
		return;
	}
	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		syslog(LOG_ERR, "gbd socket: %m");
		return;
	}
	if (connect(sock, &target, sizeof(target))) {
		syslog(LOG_ERR, "gbd connect: %m");
		(void) close(sock);
		return;
	}
	zdbug((LOG_DEBUG, "gbd connected"));

	/* Now begin the brain dump.  Set the Zephyr port to be the
	   TCP connection.  This will work since recvfrom and sendto
	   work even on TCP connections, but the sockaddr_in addresses
	   are ignored */
	(void) ZSetFD(sock);

#ifdef notdef
	/* send the authenticator over */
	/* and receive mutual authent */
#endif notdef
	gbd_loop(server);
	sbd_loop(&target);

	(void) ZSetFD(srv_socket);
	(void) close(sock);
	zdbug((LOG_DEBUG, "gbd done"));
	server->zs_state = SERV_UP;
	return;
}

/*
 * Send a list off as the specified notice
 */

Code_t
bdump_send_list_tcp(kind, port, class, inst, opcode, sender, recip, lyst, num)
ZNotice_Kind_t kind;
u_short port;
char *class, *inst, *opcode, *sender, *recip;
char *lyst[];
int num;
{
	ZNotice_t notice;
	register ZNotice_t *pnotice; /* speed hack */
	ZPacket_t pack;
	int packlen, count;
	Code_t retval;
	u_short length;

	pnotice = &notice;

	pnotice->z_kind = kind;

	pnotice->z_port = port;
	pnotice->z_class = class;
	pnotice->z_class_inst = inst;
	pnotice->z_opcode = opcode;
	pnotice->z_sender = sender;
	pnotice->z_recipient = recip;

	packlen = sizeof(pack);
	
	if ((retval = ZFormatNoticeList(pnotice, lyst, num, pack, packlen, &packlen, ZNOAUTH)) != ZERR_NONE)
		return(retval);
	
	length = htons((u_short) packlen);

	if ((count = write(ZGetFD(), (caddr_t) &length, sizeof(length))) != sizeof(length))
		if (count < 0)
			return(count);
		else {
			syslog(LOG_WARNING, "slt xmit: %d vs %d",sizeof(length),count);
			return(ZSRV_PKSHORT);
		}

	if ((count = write(ZGetFD(), pack, packlen)) != packlen)
		if (count < 0)
			return(count);
		else {
			syslog(LOG_WARNING, "slt xmit: %d vs %d",packlen, count);
			return(ZSRV_PKSHORT);
		}
	return(ZERR_NONE);
}

static void
sbd_loop(from)
struct sockaddr_in *from;
{
	ZNotice_t bd_notice;
	ZPacket_t pack;
	int packlen = sizeof(pack);
	Code_t retval;
	int auth;

	while (1) {
		packlen = sizeof(pack);
		if ((retval = get_packet(pack, packlen, &packlen)) != ZERR_NONE) {
			syslog(LOG_ERR, "sbd notice get: %s",
			       error_message(retval));
			break;
		}
		if ((retval = ZParseNotice(pack, packlen, &bd_notice, &auth, from)) != ZERR_NONE) {
			syslog(LOG_ERR, "sbd notice parse: %s",
			       error_message(retval));
			break;
		}
#ifdef DEBUG
		if (zdebug) {
			char buf[4096];
		
			(void) sprintf(buf, "bdump:%s '%s' '%s' '%s' '%s' '%s'",
				       pktypes[(int) bd_notice.z_kind],
				       bd_notice.z_class,
				       bd_notice.z_class_inst,
				       bd_notice.z_opcode,
				       bd_notice.z_sender,
				       bd_notice.z_recipient);
			syslog(LOG_DEBUG, buf);
		}
#endif DEBUG
		if (!strcmp(bd_notice.z_class_inst, ADMIN_LIMBO)) {
			/* he wants limbo */
			zdbug((LOG_DEBUG, "limbo req"));
			bdump_send_loop(limbo_server);
			continue;
		} else if (!strcmp(bd_notice.z_class_inst, ADMIN_YOU)) {
			/* he wants my state */
			zdbug((LOG_DEBUG, "my state req"));
			bdump_send_loop(me_server);
			break;
		} else if (!strcmp(bd_notice.z_class_inst, ADMIN_DONE)) {
			break;
		} else {
			/* what does he want? */
			zdbug((LOG_DEBUG, "unknown req"));
			break;
		}
	}
	return;
}

static void
gbd_loop(server)
ZServerDesc_t *server;
{
	struct sockaddr_in target;

	/* if we have no hosts in the 'limbo' state (on the limbo server),
	   ask for the other server to send us the limbo state. */
	if (otherservers[limbo_server_idx()].zs_hosts->q_forw ==
	    otherservers[limbo_server_idx()].zs_hosts) {
		bdump_ask_for("LIMBO");
		bdump_recv_loop(&otherservers[limbo_server_idx()], &target);
	}

	bdump_ask_for("YOUR_STATE");
	bdump_recv_loop(server, &target);
}
/*
 * The braindump offer wasn't taken, so we retract it.
 */

/*ARGSUSED*/
static void
close_bdump(arg)
caddr_t arg;
{
	if (bdump_socket) {
		FD_CLR(bdump_socket, &interesting);
		(void) close(bdump_socket);
		nfildes = srv_socket + 1;
		bdump_socket = 0;
		zdbug((LOG_DEBUG, "bdump not used"));
	} else {
		zdbug((LOG_DEBUG, "bdump not open"));
	}
	return;
}

/*
 * Ask the other server to send instruction packets for class instance
 * inst
 */

static void
bdump_ask_for(inst)
char *inst;
{
	/* myname is the hostname */
	send_normal_tcp(ACKED, bdump_sin.sin_port, ZEPHYR_ADMIN_CLASS,
		    inst, ADMIN_BDUMP, myname, "", (char *) NULL, 0);

	return;
}

/*
 * Start receiving instruction notices from the brain dump socket
 */

static void
bdump_recv_loop(server, target)
ZServerDesc_t *server;
struct sockaddr_in *target;
{
	ZNotice_t notice;
	ZPacket_t packet;
	int len, auth;
	Code_t retval;
	ZClient_t *client = NULLZCNT;
	struct sockaddr_in current_who;
	int who_valid = 0;
	register char *cp;

	zdbug((LOG_DEBUG, "bdump recv loop"));
	
	/* XXX do the inverse, registering stuff on the fly */
	while (1) {
		len = sizeof(packet);
		if ((retval = get_packet(packet, len, &len)) != ZERR_NONE) {
			syslog(LOG_ERR, "brl get pkt: %s",
			       error_message(retval));
			break;
		}
		if ((retval = ZParseNotice(packet, len, &notice, &auth, target)) != ZERR_NONE) {
			syslog(LOG_ERR, "brl notice parse: %s",
			       error_message(retval));
			break;
		}
#ifdef DEBUG
		if (zdebug) {
			char buf[4096];
		
			(void) sprintf(buf, "bdump:%s '%s' '%s' '%s' '%s' '%s'",
				       pktypes[(int) notice.z_kind],
				       notice.z_class,
				       notice.z_class_inst,
				       notice.z_opcode,
				       notice.z_sender,
				       notice.z_recipient);
			syslog(LOG_DEBUG, buf);
		}
#endif DEBUG
		if (notice.z_kind == HMCTL) {
			/* host register */
			if ((retval = extract_sin(&notice, &current_who)) !=
			    ZERR_NONE) {
				syslog(LOG_ERR, "brl hmctl sin: %s",
				       error_message(retval));
				break; /* from the while */
			}
			who_valid = 1;
			/* 1 = tell it we are authentic */
			hostm_dispatch(&notice, 1, &current_who, server);
		} else if (!strcmp(notice.z_opcode, ADMIN_DONE)) {
			/* end of brain dump */
			break;
		} else if (!who_valid) {
			syslog(LOG_ERR, "brl: no current host");
			break;
		} else if (!strcmp(notice.z_class, LOGIN_CLASS)) {
			/* 1 = tell it we are authentic */
			ulogin_dispatch(&notice, 1, &current_who, server);
		} else if (!strcmp(notice.z_opcode, ADMIN_NEWCLT)) {
			/* register a new client */
			notice.z_port = ntohs((u_short)atoi(notice.z_message));
			if ((retval = client_register(&notice,
						      &current_who,
						      &client,
						      server)) != ZERR_NONE) {
				syslog(LOG_ERR,"brl register failed: %s",
				       error_message(retval));
				break;
			}
			if (strlen(notice.z_message) + 1 < notice.z_message_len) {
				/* a C_Block is there */
				cp = notice.z_message +
					strlen(notice.z_message) + 1;
				if (ZReadAscii(cp,strlen(cp),client->zct_cblock,sizeof(C_Block)) != ZERR_NONE)
					bzero((caddr_t) client->zct_cblock,
					      sizeof(C_Block));
			}
		} else if (!strcmp(notice.z_opcode, CLIENT_SUBSCRIBE)) { 
			/* a subscription packet */
			if (!client) {
				syslog(LOG_ERR, "brl no client");
				break;
			}
			if ((retval = subscr_subscribe(client, &notice)) != ZERR_NONE) {
				syslog(LOG_WARNING, "brl subscr failed: %s",
				       error_message(retval));
			}
		} else {
			syslog(LOG_ERR, "brl bad opcode %s",notice.z_opcode);
			break;
		}
	}
}

/*
 * Send all the state from server to the peer.
 */

static void
bdump_send_loop(server)
register ZServerDesc_t *server;
{
	register ZHostList_t *host;
	register ZClientList_t *clist;

	zdbug((LOG_DEBUG, "bdump send loop"));

	for (host = server->zs_hosts->q_forw;
	     host != server->zs_hosts;
	     host = host->q_forw) {
		/* for each host */
		send_host_register(host);
		uloc_send_locations(host);
		if (!host->zh_clients)
			continue;
		for (clist = host->zh_clients->q_forw;
		     clist != host->zh_clients;
		     clist = clist->q_forw) {
			/* for each client */
			if (!clist->zclt_client->zct_subs)
				continue;
			subscr_send_subs(clist->zclt_client);
		}
	}
	send_done();
}

/*
 * Send a host boot packet to the other server
 */

static void
send_host_register(host)
ZHostList_t *host;
{
	char buf[512], *addr, *lyst[2];
	Code_t retval;

	zdbug((LOG_DEBUG, "bdump_host_register"));
	addr = inet_ntoa(host->zh_addr.sin_addr);
	(void) sprintf(buf, "%d", ntohs(host->zh_addr.sin_port));
	lyst[0] = addr;
	lyst[1] = buf;

	/* myname is the hostname */
	if ((retval = bdump_send_list_tcp(HMCTL, bdump_sin.sin_port, ZEPHYR_CTL_CLASS, ZEPHYR_CTL_HM, HM_BOOT, myname, "", lyst, 2)) != ZERR_NONE)
		syslog(LOG_ERR, "shr send: %s",error_message(retval));
	return;
}

/*
 * Send a sync indicating end of this host
 */

static void
send_done()
{
	zdbug((LOG_DEBUG, "send_done"));
	send_normal_tcp(SERVACK, bdump_sin.sin_port, ZEPHYR_ADMIN_CLASS,
			"", ADMIN_DONE, myname, "", (char *) NULL, 0);
	return;
}


/*
 * Send a list off as the specified notice
 */

static void
send_list(kind, port, class, inst, opcode, sender, recip, lyst, num)
ZNotice_Kind_t kind;
u_short port;
char *class, *inst, *opcode, *sender, *recip;
char *lyst[];
int num;
{
	ZNotice_t notice;
	register ZNotice_t *pnotice; /* speed hack */
	ZPacket_t pack;
	int packlen;
	Code_t retval;

	pnotice = &notice;

	pnotice->z_kind = kind;

	pnotice->z_port = port;
	pnotice->z_class = class;
	pnotice->z_class_inst = inst;
	pnotice->z_opcode = opcode;
	pnotice->z_sender = sender;
	pnotice->z_recipient = recip;

	packlen = sizeof(pack);
	
	if ((retval = ZFormatNoticeList(pnotice, lyst, num, pack, packlen, &packlen, ZNOAUTH)) != ZERR_NONE) {
		syslog(LOG_WARNING, "sl format: %s", error_message(retval));
		return;
	}
	
	if ((retval = ZSendPacket(pack, packlen)) != ZERR_NONE)
		syslog(LOG_WARNING, "sl xmit: %s", error_message(retval));
	return;
}

/*
 * Send a message off as the specified notice, via TCP
 */

static void
send_normal_tcp(kind, port, class, inst, opcode, sender, recip, message, len)
ZNotice_Kind_t kind;
u_short port;
char *class, *inst, *opcode, *sender, *recip;
char *message;
int len;
{
	ZNotice_t notice;
	register ZNotice_t *pnotice; /* speed hack */
	ZPacket_t pack;
	int packlen, count;
	Code_t retval;
	u_short length;

	pnotice = &notice;

	pnotice->z_kind = kind;

	pnotice->z_port = port;
	pnotice->z_class = class;
	pnotice->z_class_inst = inst;
	pnotice->z_opcode = opcode;
	pnotice->z_sender = sender;
	pnotice->z_recipient = recip;
	pnotice->z_message = message;
	pnotice->z_message_len = len;

	packlen = sizeof(pack);
	
	if ((retval = ZFormatNotice(pnotice, pack, packlen, &packlen, ZNOAUTH)) != ZERR_NONE) {
		syslog(LOG_WARNING, "sn format: %s", error_message(retval));
		return;
	}

	length = htons((u_short) packlen);

	if ((count = write(ZGetFD(), (caddr_t) &length, sizeof(length))) != sizeof(length)) {
		if (count < 0)
			syslog(LOG_WARNING, "snt xmit/len: %m");
		else
			syslog(LOG_WARNING, "snt xmit: %d vs %d",sizeof(length),count);
	}

	if ((count = write(ZGetFD(), pack, packlen)) != packlen)
		if (count < 0)
			syslog(LOG_WARNING, "snt xmit: %m");
		else
			syslog(LOG_WARNING, "snt xmit: %d vs %d",packlen, count);
}

/*
 * get a packet from the TCP socket
 * return 0 if successful, 1 else
 */

static Code_t
get_packet(packet, len, retlen)
caddr_t packet;
int len;
int *retlen;				/* RETURN */
{
	u_short length;
	int result;

	if ((result = read(ZGetFD(), (caddr_t) &length, sizeof(u_short))) < sizeof(short)) {
		if (result < 0)
			return(errno);
		else {
			syslog(LOG_ERR, "get_pkt len: %d vs %d", result, sizeof(short));
			return(ZSRV_PKSHORT);
		}
	}
	
	length = ntohs(length);
	if (len < length)
		return(ZSRV_BUFSHORT);
	if ((result = read(ZGetFD(), packet, (int) length)) < length) {
		if (result < 0)
			return(errno);
		else {
			syslog(LOG_ERR, "get_pkt: %d vs %d",result, length);
			return(ZSRV_PKSHORT);
		}
	}
	*retlen = (int) length;
	return(ZERR_NONE);
}

static Code_t
extract_sin(notice, target)
ZNotice_t *notice;
struct sockaddr_in *target;
{
	register char *cp = notice->z_message;
	char *buf;

	buf = cp;
	if (!notice->z_message_len || *buf == '\0') {
		zdbug((LOG_DEBUG,"no addr"));
		return(ZSRV_PKSHORT);
	}
	target->sin_addr.s_addr = inet_addr(cp);
	cp += (strlen(cp) + 1); /* past the null */
	if ((cp >= notice->z_message + notice->z_message_len)
	    || (*cp == '\0')) {
		zdbug((LOG_DEBUG, "no port"));
		return(ZSRV_PKSHORT);
	}
	target->sin_port = ntohs((u_short) atoi(cp));
	target->sin_family = AF_INET;
	return(ZERR_NONE);
}