# /* in_open.c */ /* EMACS_MODES: c !fill */ /* Internet protocol layer for the MIT network system. The following * routines are included: * in_open Open an internet connection * * Note that use of this package requires the use of the standard I/O * library. */ #include #include #include #include #include in_open (prot, fhost, fsock, lsock) /* Open an internet connection on the specified protocol, to the * specified foreign host, with the specified local and foreign * sockets. Note that any or all of the arguments may be NULL * to indicate that field is to be ignored in packet demultiplexing. * Also get the local net header/trailer sizes for this connection. * Finally, get the maximum fragment size for this connection and, * allocate a packet buffer of the maximum fragment size for * later use in packet fragmentation. * Note that this routine must be called before attempting to * allocate a packet for this connection. * Return the file descriptor, or -1 for error (with the error * specified in the global variable in_err). * * Arguments: */ unshort prot; /* InterNet protocol ID */ in_name fhost; /* foreign host addr */ unshort fsock; /* foreign socket */ unshort lsock; /* local socket */ { struct netdf ndf; /* net connection definition */ reg struct netdf *nf; /* ptr. to ndf */ reg int fd; /* file descriptor */ int ht[2]; /* array for ioctl */ struct { /* for frag. size ioctl */ in_name f_name; /* host addr */ int f_size; /* max. frag size */ } frgsiz; nf = &ndf; nf->nd_prot1 = MITINET; /* set up connection definition */ nf->nd_prot2 = prot; nf->nd_fhost = fhost; nf->nd_fsock = fsock; nf->nd_lsock = lsock; if ((fd = netopen (NETDEV, nf)) < 0) { in_err = errno; return (-1); /* failed to open conn */ } if (!in_inited) { /* init in layer if needed */ in_inited = TRUE; ioctl (fd, NIOCGETHT, ht); /* get header/trailer sizes */ lnhsiz = ht[0]; lntsiz = ht[1]; ioctl (fd, NIOCGETHOST, &mymach); /* get my in addr */ signal (SIGAIO, net_intrpt); } frgsiz.f_name = fhost; ioctl (fd, NIONWRITE, &frgsiz); /* get max. frag size */ in_frgbuf[fd].fg_size = frgsiz.f_size & ~(FRAGGRAIN - 1); in_frgbuf[fd].fg_buf = in_alloc (frgsiz.f_size - sizeof(struct ip), 0); return (fd); }