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 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
|
/* $NCDId: @(#)nameaddr.c,v 1.2 1994/05/02 17:42:06 greg Exp $ */
/* $XConsortium: nameaddr.c,v 1.5 91/09/12 13:41:04 rws Exp $ */
/* nameaddr.c - included by Astreams.c */
/* Used for System V Release 4.0 networking code */
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
* Copyright 1991 Massachusetts Institute of Technology
* Copyright 1988, 1989 AT&T, Inc.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of
* AT&T, USL, or MIT not be used in advertising or publicity
* pertaining to distribution of the software without specific,
* written prior permission. AT&T, USL, and MIT make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* AT&T, USL, AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL AT&T, USL, OR MIT BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef AuSTREAMS_COMPILE /* magic symbol to avoid lint problems */
static void *handlep = NULL;
static int family = 0;
static char tcphalf[4];
static int *tcpfamilyp = NULL;
static char **tcpremoteaddrp = NULL;
static int *tcpremoteaddrlenp = NULL;
static int SetupNetworkStream();
static int BindAndListen();
static int BindAndConnect();
static int addentry();
/* Routines for handling TLI streams */
static int
InitializeNetPath()
{
if(handlep == NULL && (handlep = setnetpath()) == NULL)
{
nc_perror("Cannot set network selection path\n");
return(-1);
}
return(1);
}
_AusSetupTliStream(display, dummy)
char *display;
void *dummy;
{
int i, n;
int fd, type;
struct utsname machine;
struct listenCall *tmp;
int nameserver();
static int firstime=1;
PRMSG("Calling SetupTliStream()\n",0,0);
if(InitializeNetPath() < 0)
return(-1);
dispno = display;
if(uname(&machine) < 0){
perror("Cannot get nodename");
return(-2);
}
bind_req.addr.buf = req_buf;
/* pcc */
if (firstime) {
Network._nnets = Au_TLI_STREAM;
firstime = 0;
}
/* type = Network._nnets; */
bind_ret.addr.buf = ret_buf;
call.addr.buf = call_buf;
bind_req.addr.maxlen = MAXLEN;
bind_ret.addr.maxlen = MAXLEN;
call.addr.maxlen = MAXLEN;
fd = SetupNetworkStream(
machine.nodename,
atoi(display),
BindAndListen,
&type,
handlep
);
if( fd < 0)
{
PRMSG("SetupNetworkStream failed\n",0,0);
return(-1);
}
_AusTypeOfStream[fd] = type;
/*
* set up call save list for general network listen service
*/
for (i = 0; i < LISTEN_QUE_SIZE; ++i)
{
if((tmp = (struct listenCall *) malloc(sizeof(struct listenCall))) == NULL)
{
PRMSG( "malloc failed\n",0,0);
exit(1);
}
if((tmp->CurrentCall = (struct t_call *) t_alloc(fd,T_CALL,T_ALL)) == NULL)
{
PRMSG( "t_alloc failed\n",0,0);
exit(1);
}
Que(&Network.FreeList[type], tmp, CLEAR);
}
if(Network._npeers > 0 && Network._peer == NULL)
{
register i;
register char *ptr;
int n;
n = (Network._npeers + 1) *
(sizeof(int) + sizeof(char *) + (1 + UNAME_LENGTH));
PRMSG("Allocating %d chars for %d peeers names",
n, Network._npeers);
if((ptr = malloc(n)) == NULL){
fprintf(stderr,"Cannot malloc space for peers names\n");
exit(1);
}
Network._peerlen = (int *) ptr;
ptr += Network._npeers * sizeof(int);
Network._peer = (char **) ptr;
ptr += Network._npeers * sizeof(char *);
for(i= 0; i< Network._npeers; i++)
{
Network._peerlen[i] = 0;
Network._peer[i] = ptr;
#ifdef DEBUG
/*
fprintf(stderr, "peer[%d] is %u; peerlen[%d] is %u\n",
i, Network._peer[i], i, &Network._peerlen[i]);
*/
#endif
ptr += (1 + UNAME_LENGTH);
}
}
PRMSG("SetupTliStream () (success) fd = %d\n", fd,0);
return(fd);
}
int
_AusCallTliServer(host, idisplay)
char *host;
int idisplay;
{
int fd, type;
int nameserver ();
static char firsttime = 1;
PRMSG("Calling CallTliServer()\n",0,0);
if(firsttime == 1)
{
firsttime = 0;
SetupNetworkInfo();
Network._nnets = Au_TLI_STREAM;
}
sprintf(_dispno, "%d", idisplay);
dispno = _dispno;
if((fd = SetupNetworkStream(
host,
idisplay,
BindAndConnect,
&type,
handlep)) < 0)
{
PRMSG("SetupNetworkStream failed\n",0,0);
return(-1);
}
if(ioctl(fd, I_POP, "timod") < 0)
{
PRMSG("failed to pop timod\n",0,0);
}
if(ioctl(fd, I_PUSH, "tirdwr") < 0)
{
t_close(fd);
return(-1);
}
PRMSG("A Connection has been established to %s ... \n", host,0);
_AusTypeOfStream[fd] = type;
if (_AusInputBuffer[fd].DataBuffer == NULL)
if ((_AusInputBuffer[fd].DataBuffer = (char *) malloc(BUFFERSIZE)) == NULL)
{
errno = ENOMEM;
perror("Client can't connect to remote server");
return (-1);
}
_AusInputBuffer[fd].LastBytePtr = 0;
_AusInputBuffer[fd].FirstBytePtr = 0;
PRMSG("CallTliServer() returns success\n",0,0);
return(fd);
}
int _AuMakeStreamsConnection (name, iserverp, xname, retries,
familyp, serveraddrlenp, serveraddrp)
char *name;
int *iserverp; /* can be RETURN */
AuBool xname;
int retries;
int *familyp; /* return */
int *serveraddrlenp; /* return */
char **serveraddrp; /* return */
{
char netype[128], sysname[128], nodname[128];
char *procname = "Aulib/_AuMakeStreamsConnection";
struct utsname machine;
int fd;
int idisplay;
PRMSG("GetConnectionType(%s)\n", name, 0);
if(uname(&machine) < 0){
perror("Cannot get nodename");
return(-1);
}
if(
name == NULL ||
strcmp(name, "") == 0 ||
strcmp(name, "unix") == 0 ||
strcmp(name, "local") == 0 ||
strcmp(name, machine.nodename) == 0
)
{
fd = ((*_AusStream[Au_NAMED_STREAM].CallTheListener)
("unix", *iserverp, "local"));
if (fd >= 0) {
*familyp = FamilyLocal;
*serveraddrlenp = strlen (machine.nodename);
*serveraddrp = (char *) Aumalloc ((*serveraddrlenp) + 1);
if (!*serveraddrp) {
*serveraddrlenp = 0;
} else {
strcpy (*serveraddrp, machine.nodename);
}
}
return fd;
}
if((handlep = setnetpath()) == NULL)
{
nc_perror("Cannot set network selection path\n");
return(-1);
}
/* For backward compatibility, we have to pass authorization
data in global variables. Ugh. */
tcpfamilyp = familyp;
tcpremoteaddrp = serveraddrp;
tcpremoteaddrlenp = serveraddrlenp;
if (xname) /* name came from X */
*iserverp += AU_DEFAULT_TCP_PORT;
fd = (*_AusStream[Au_TLI_STREAM].CallTheListener)(name, *iserverp);
return(fd);
}
static int
SetupNetworkStream(host, dispno, action, typtr, handlep)
char *host;
int dispno;
int (*action)();
int *typtr;
void *handlep;
{
int i;
char service[MAX_AUTO_BUF_LEN];
int fd, type;
struct nd_hostserv nd_hostserv;
struct netconfig *netconfigp = NULL;
struct nd_addrlist *nd_addrlistp = NULL;
struct netbuf *netbufp = NULL;
#ifdef DEBUG
fprintf(stderr, "Calling SetupNetworkStream(%s, %d)\n", host, dispno);
#endif
sprintf(service , "auserver%d", dispno);
nd_hostserv.h_host = host;
nd_hostserv.h_serv = service;
#ifdef DEBUG
fprintf(stderr, "Trying to get the binding address for service %s on %s\n",
service, host);
#endif
while((netconfigp = getnetpath(handlep)) != NULL)
{
#ifdef DEBUG
fprintf(stderr, "Trying to bind using %s\n", netconfigp->nc_device);
#endif
if(netdir_getbyname(netconfigp, &nd_hostserv, &nd_addrlistp) == 0)
{
#ifdef DEBUG
fprintf(stderr, "There are %d ways\n", nd_addrlistp->n_cnt);
#endif
netbufp = nd_addrlistp->n_addrs;
for(i=0; i< nd_addrlistp->n_cnt; i++)
{
#ifdef DEBUG
fprintf(stderr, "Address: len %d maxlen %d \n",
netbufp->len, netbufp->maxlen);
#endif
if( strcmp(netconfigp->nc_netid, "starlan") == 0 )
{
register char *from, *to;
int i, len;
from = to = netbufp->buf;
len = 0;
for(i=0; i< netbufp->len; i++, from++)
if(*from != '.')
{
*to++ = *from;
len++;
}
*to = '\0';
netbufp->len = len;
}
#ifdef DEBUG
fprintf(stderr, "Address: maxlen %d buf ", netbufp->maxlen);
dumpBytes(netbufp->len, netbufp->buf);
#endif
if((fd = (*action)(netconfigp->nc_device, netbufp)) < 0)
{
netbufp++;
continue;
}
if(
strcmp(netconfigp->nc_protofmly, "inet") == 0 &&
strcmp(netconfigp->nc_proto , "tcp") == 0
)
{
memcpy(tcphalf, netbufp->buf, 4);
if (tcpfamilyp != NULL) {
*tcpfamilyp = AuNetworkInternet;
*tcpremoteaddrlenp = 4;
*tcpremoteaddrp = Aumalloc(*tcpremoteaddrlenp);
/* This is a kludge. What is the right way to get
this info out? */
memcpy(*tcpremoteaddrp, netbufp->buf+4,
*tcpremoteaddrlenp);
#ifdef DEBUG
fprintf(stderr, "tcp remote addr = %0x\n",
*(long *)*tcpremoteaddrp);
#endif
}
}
type = 0;
for(i=Au_TLI_STREAM; i< Network._nnets; i++)
if(strcmp(Network._net[i]->nc_netid, netconfigp->nc_netid) == 0)
{
type = i;
break;
}
if(type == 0)
{
Network._net[Network._nnets] = netconfigp;
type = Network._nnets++;
}
*typtr = type;
/* free(netconfigp) the right way */
(void) netdir_free((char *)nd_addrlistp, ND_ADDRLIST);
return(fd);
}
/* free(nd_addrlistp) the right way */
(void) netdir_free((char *)nd_addrlistp, ND_ADDRLIST);
}
#ifdef DEBUG
else netdir_perror("netdir_getbyname() failed");
#endif
}
return(-1);
}
static int
BindAndListen(clonedev, netbufp)
char *clonedev;
struct netbuf *netbufp;
{
int fd;
struct t_bind bindbuf;
bindbuf.addr.buf = netbufp->buf;
bindbuf.addr.len = netbufp->len;
bindbuf.addr.maxlen = netbufp->maxlen;
if ((fd = t_open(clonedev, O_RDWR, NULL)) < 0)
{
fprintf(stderr, "Cannot open %s\n", clonedev);
return(-1);
}
#ifdef DEBUG
fprintf(stderr, "opening device %s\n", clonedev);
#endif
bindbuf.qlen = 8;
if(t_bind (fd, &bindbuf, NULL) < 0)
{
t_error("t_bind failed");
close(fd);
return(-1);
}
return(fd);
}
static int
BindAndConnect(clonedev, netbufp)
char *clonedev;
struct netbuf *netbufp;
{
int fd;
struct t_call callbuf;
callbuf.addr.buf = netbufp->buf;
callbuf.addr.len = netbufp->len;
callbuf.addr.maxlen = netbufp->maxlen;
callbuf.opt.buf = NULL;
callbuf.opt.len = 0;
callbuf.opt.maxlen = 0;
callbuf.udata.buf = NULL;
callbuf.udata.len = 0;
callbuf.udata.maxlen = 0;
if ((fd = t_open(clonedev, O_RDWR, NULL)) < 0)
{
fprintf(stderr, "Cannot open %s\n", clonedev);
return(-1);
}
#ifdef DEBUG
fprintf(stderr, "Connecting to <%s> through device %s\n",
callbuf.addr.buf, clonedev);
#endif
if(t_bind(fd, NULL, NULL) < 0)
{
t_error("t_bind failed");
t_close(fd);
return(-1);
}
if(t_connect(fd, &callbuf, NULL) < 0)
{
t_error("t_connect failed");
checkNewEvent(fd);
t_close(fd);
return(-1);
}
return(fd);
}
/*extern char *calloc(), *realloc();*/
extern char *program;
static int network;
static int nextentry;
static char *makePacket();
static char *staticalloc();
static char *TheEnd;
static char *inbuf;
static int inlen;
static int nhosts;
static int nHosts;
static int flags = 0;
static struct netconfig *netconfigp = NULL;
static int
CallTheNameServer(service, nettype, arg1, arg2, arg3)
int service;
struct netconfig *nettype;
char **arg1, **arg2;
int *arg3;
{
int n,m, len;
char *ptr, *net;
int *iptr;
flags = service;
netconfigp = nettype;
ptr = *arg1;
iptr = (int *) ptr;
inlen = iptr[0];
#ifdef DEBUG
fprintf(stderr,"inlen = %d\n", inlen);
#endif
ptr += sizeof(int);
nhosts = iptr[1];
#ifdef DEBUG
fprintf(stderr,"nhosts = %d\n", nhosts);
#endif
inbuf = ptr + sizeof(int);
TheEnd = &inbuf[inlen];
#ifdef DEBUG
write(2, inbuf, inlen);
#endif
nextentry = ((xHostEntry *) inbuf)->length;
*arg2 = (char *) makePacket(&len);
if(arg3 != NULL)
*arg3 = nHosts;
#ifdef DEBUG
fprintf(stderr, "CallTheNameserver return %d\n", len);
#endif
return(len);
}
static int bufsize = 512;
static char *getnextentry();
static struct nd_addrlist *
GetHostServiceByName(host, dispno)
char *host;
int dispno;
{
struct nd_hostserv nd_hostserv;
struct nd_addrlist *nd_addrlistp = NULL;
struct netbuf *netbufp = NULL;
char service[MAX_AUTO_BUF_LEN];
sprintf(service , "auserver%d", dispno);
nd_hostserv.h_host = host;
nd_hostserv.h_serv = service;
if(netdir_getbyname(netconfigp, &nd_hostserv, &nd_addrlistp) == 0)
return(nd_addrlistp);
else return(NULL);
}
static int
ConvertName(pktptr, n, entry, len)
char **pktptr, *entry;
int n, len;
{
struct hostent *hp;
unsigned long address;
int port;
char *ptr;
int rndlen;
struct nd_addrlist *nd_addrlistp = NULL;
struct netbuf *netbufp;
char *addr;
#ifdef DEBUG
fprintf(stderr, "in ConvertName %s\n", entry);
#endif
if((nd_addrlistp = GetHostServiceByName(entry, atoi(dispno))) == NULL)
return(n);
netbufp = nd_addrlistp->n_addrs; /* the netbufs */
/*
xhost needs only the last four bytes of the address
over TCP/IP.
*/
if(
strcmp(netconfigp->nc_protofmly, "inet") == 0 &&
strcmp(netconfigp->nc_proto , "tcp") == 0
){
addr = &netbufp->buf[4];
len = 4;
family = 1;
}
else
{
family = 0;
addr = netbufp->buf;
len = netbufp->len;
}
rndlen = ((sizeof(xHostEntry) + len + 3) >> 2) << 2;
if((*pktptr = staticalloc(*pktptr, n+rndlen)) == NULL)
{
(void) netdir_free((char *)nd_addrlistp, ND_ADDRLIST);
return(-1);
}
ptr = &(*pktptr)[n];
((xHostEntry *)ptr)->family = family;
((xHostEntry *)ptr)->length = len;
ptr += sizeof(xHostEntry);
memcpy(ptr, addr, len);
netdir_free((char *)nd_addrlistp, ND_ADDRLIST);
#ifdef DEBUG
ptr[len] = '\0';
fprintf(stderr, "creating address for host %s address<%d>\n", entry, ptr);
#endif
return(n+rndlen);
}
static struct nd_hostservlist *
GetHostServiceByAddr(addr, len)
char *addr;
int len;
{
struct nd_hostservlist *nd_hostservlist;
struct netbuf netbuf;
netbuf.buf = addr;
netbuf.len = len;
netbuf.maxlen = len;
if(netdir_getbyaddr(netconfigp, &nd_hostservlist, &netbuf) == 0)
return(nd_hostservlist);
else return(NULL);
}
static int
ConvertCallToName(pktptr, n, entry, len)
char **pktptr, *entry;
int n, len;
{
int l, rl;
char *ptr;
struct nd_hostservlist *nd_hostservlist;
if((nd_hostservlist = GetHostServiceByAddr(entry, len)) == NULL)
return(n);
l = strlen(nd_hostservlist->h_hostservs->h_host);
rl = ((sizeof(xHostEntry) + l + 3) >> 2) << 2;
if((*pktptr = staticalloc(*pktptr, n+rl)) == NULL)
{
(void) netdir_free((char *)nd_hostservlist, ND_HOSTSERVLIST);
return(-1);
}
ptr = &(*pktptr)[n];
((xHostEntry *)ptr)->family = 0;
((xHostEntry *)ptr)->length = l;
ptr += sizeof(xHostEntry);
sprintf(ptr, nd_hostservlist->h_hostservs->h_host);
(void) netdir_free((char *)nd_hostservlist, ND_HOSTSERVLIST);
#ifdef DEBUG
fprintf(stderr, "getting the name for host %s\n", ptr);
#endif
return(rl+n);
}
static int
ConvertAddress(pktptr, n, entry, len)
char **pktptr, *entry;
int n, len;
{
register i;
char *ptr;
int l, rl;
struct nd_hostservlist *nd_hostservlist;
char *name;
char tcpaddr[8], *addr;
char addrbuf[MAX_AUTO_BUF_LEN];
#ifdef DEBUG
entry[len] = '\0';
fprintf(stderr, "Converting address %s in %s format\n",
entry, netconfigp->nc_netid);
#endif
if(
strcmp(netconfigp->nc_protofmly, "inet") == 0 &&
strcmp(netconfigp->nc_proto , "tcp") == 0
){
addr = tcpaddr;
memcpy(tcpaddr, tcphalf, 4);
memcpy(&tcpaddr[4], entry, 4);
len = 8;
#ifdef DEBUG
fprintf(stderr, "port %d, family %d\n",
*(short *) &tcpaddr[2], *(short *) tcpaddr);
#endif
}
else
{
addr = entry;
}
if((nd_hostservlist = GetHostServiceByAddr(addr, len)) == NULL)
{
int i;
for(i=0; i< len; i++)
if(entry[i] < ' ' || entry[i] > 0177)
break;
if(i < len)
{
sprintf(addrbuf, "%d", *(int *) entry);
name = addrbuf;
len = strlen(name);
}
else name = entry;
entry[len] = '\0';
l = len + 1;
}
else
{
name = nd_hostservlist->h_hostservs->h_host;
l = strlen(name) +1;
}
rl = ((sizeof(xHostEntry) + l + 3) >> 2) << 2;
if((*pktptr = staticalloc(*pktptr, n+rl)) == NULL)
{
if(nd_hostservlist != NULL)
(void) netdir_free((char *)nd_hostservlist, ND_HOSTSERVLIST);
return(-1);
}
ptr = &(*pktptr)[n];
((xHostEntry *)ptr)->family = 0;
((xHostEntry *)ptr)->length = l;
ptr += sizeof(xHostEntry);
memcpy(ptr, name, l);
if(nd_hostservlist != NULL)
(void) netdir_free((char *)nd_hostservlist, ND_HOSTSERVLIST);
#ifdef DEBUG
fprintf(stderr, "getting the name for host %s\n", name);
#endif
return(n+rl);
}
static char *
getnextentry(plen)
int *plen;
{
char *ptr;
int n = nextentry;
#ifdef DEBUG
fprintf(stderr,"In getnextentry()\n");
#endif
if(inbuf >= TheEnd)
{
#ifdef DEBUG
fprintf(stderr,"In getnextentry() end of buffer\n");
#endif
*plen = -1;
return(NULL);
}
*plen = nextentry;
family = ((xHostEntry *) inbuf)->family;
ptr = inbuf + sizeof(xHostEntry);
inbuf += ((sizeof(xHostEntry) + *plen + 3) >> 2) << 2;
nextentry = ((xHostEntry *) inbuf)->length;
ptr[*plen] = '\0';
return(ptr);
}
static char *
makePacket(plen)
int *plen;
{
char *pktptr = NULL, *ptr;
int len;
int n = 0, m;
#ifdef DEBUG
fprintf(stderr,"In makePacket()\n");
#endif
for(nHosts = 0; nHosts < nhosts;)
{
ptr = getnextentry(&len);
if(len < 0)
break;
if(len == 0 || ptr == NULL)
continue;
m = addentry(&pktptr, n, ptr, len);
if(m > n){
nHosts++;
n = m;
}
}
#ifdef DEBUG
fprintf(stderr, "packet size is %d\n", n);
#endif
*plen = n;
return(pktptr);
}
static int
addentry(pktptr, n, entry, len)
char **pktptr, *entry;
int n, len;
{
#ifdef DEBUG
fprintf(stderr, "in addEntry %s\n", entry);
#endif
switch(flags)
{
case ConvertNameToNetAddr:
return(ConvertName(pktptr, n, entry, len));
case ConvertNetAddrToName:
return(ConvertAddress(pktptr, n, entry, len));
case ConvertTliCallToName:
return(ConvertCallToName(pktptr, n, entry, len));
}
return(-1);
}
static char *
staticalloc(ptr, size)
char *ptr;
int size;
{
if(ptr == NULL)
{
if(bufsize < size)
bufsize = size;
ptr = malloc(bufsize);
}
if(bufsize < size)
{
bufsize = size + 512;
ptr = realloc(ptr, bufsize);
}
return(ptr);
}
static int
OpenVirtualCircuit(lfd)
int lfd;
{
char *clonedev;
int fd;
clonedev = Network._net[_AusTypeOfStream[lfd]]->nc_device;
if ((fd = t_open(clonedev, O_RDWR, NULL)) < 0)
{
fprintf(stderr, "Cannot open %s\n", clonedev);
return(-1);
}
if(t_bind(fd, NULL, NULL) < 0)
{
t_error("t_bind failed");
t_close(fd);
return(-1);
}
return(fd);
}
#endif /* AuSTREAMS_COMPILE */
|