Beispiel #1
0
void
do_child(void)
{
	int				listenfd, qlen, junk;
	struct t_bind	tbind, tbindret;

	Close(pipefd[1]);

	Read(cfd, &qlen, sizeof(int));	/* wait for parent */
	while (qlen >= 0) {
		listenfd = T_open(XTI_TCP, O_RDWR, NULL);

		tbind.addr.maxlen = sizeof(serv);
		tbind.addr.len = sizeof(serv);
		tbind.addr.buf = &serv;
		tbind.qlen = qlen;

		tbindret.addr.maxlen = 0;
		tbindret.addr.len = 0;

		T_bind(listenfd, &tbind, &tbindret);
		printf("returned qlen = %d, ", tbindret.qlen);
		fflush(stdout);

		Write(cfd, &junk, sizeof(int));	/* tell parent */

		Read(cfd, &qlen, sizeof(int));	/* just wait for parent */
		T_close(listenfd);	/* closes all queued connections too */
	}
}
Beispiel #2
0
int
main(int argc, char **argv)
{
	int					fd;
	struct t_opthdr		*topt;
	struct t_optmgmt	*req, *ret;

	if (argc != 3)
		err_quit("usage: setbufs <device> <bufsiz>");

	fd = T_open(argv[1], O_RDWR, NULL);
	printf("Device = %s\n", argv[1]);
	T_bind(fd, NULL, NULL);

	req = T_alloc(fd, T_OPTMGMT, T_ALL);
	ret = T_alloc(fd, T_OPTMGMT, T_ALL);

	topt = (struct t_opthdr *) req->opt.buf;
	topt->level = XTI_GENERIC;
	topt->name = XTI_RCVBUF;
	topt->len = sizeof(struct t_opthdr) + sizeof(u_long);
	topt->status = 0;	/* ??? */
	req->opt.len = topt->len;
	*((u_long *) (topt + 1)) = atol(argv[2]);

#ifdef	notdef
	topt = OPT_NEXTHDR(req->opt.buf, req->opt.maxlen, topt);
	topt->level = XTI_GENERIC;
	topt->name = XTI_SNDBUF;
	topt->len = sizeof(struct t_opthdr) + sizeof(u_long);
	*((u_long *) (topt + 1)) = atol(argv[2]);
	req->opt.len += topt->len;
#endif

	req->flags = T_NEGOTIATE;
	T_optmgmt(fd, req, ret);
	printf("returned flags = %ld, len = %d\n", ret->flags, ret->opt.len);

	for (topt = (struct t_opthdr *) ret->opt.buf; topt != NULL;
		 topt = OPT_NEXTHDR(ret->opt.buf, ret->opt.len, topt)) {

		if (topt->level == XTI_GENERIC && topt->name == XTI_RCVBUF) {
			printf("RCVBUF = %ld, status = %ld\n",
				   *((u_long *) (topt + 1)), topt->status);

		} else if (topt->level == XTI_GENERIC && topt->name == XTI_SNDBUF) {
			printf("SNDBUF = %ld, status = %ld\n",
				   *((u_long *) (topt + 1)), topt->status);

		} else {
			printf("unexpected option: len = %ld, level = %ld, name = %ld\n",
				   topt->len, topt->level, topt->name);
		}
	}
	exit(0);
}
Beispiel #3
0
int main(int argc, char** argv)
{
    int fd;
    struct t_call* tcall;

    fd = T_open(XTI_TCP, O_RDWR, NULL);

    tcall = T_alloc(fd, T_CALL, T_ALL);
    printf("first t_alloc OK\n");

    tcall = T_alloc(fd, T_CALL, T_ADDR | T_OPT | T_UDATA);
    printf("second t_alloc OK\n");

    exit(0);
}
int
udp_client(const char *host, const char *serv, void **vptr, socklen_t *lenp)
{
	int					tfd;
	void				*handle;
	struct netconfig	*ncp;
	struct nd_hostserv	hs;
	struct nd_addrlist	*alp;
	struct netbuf		*np;
	struct t_unitdata	*tudptr;

	handle = Setnetpath();

	hs.h_host = (char *) host;
	hs.h_serv = (char *) serv;

	while ( (ncp = getnetpath(handle)) != NULL) {
		if (strcmp(ncp->nc_proto, "udp") != 0)
			continue;

		if (netdir_getbyname(ncp, &hs, &alp) != 0)
			continue;

		tfd = T_open(ncp->nc_device, O_RDWR, NULL);
	
		T_bind(tfd, NULL, NULL);

		tudptr = T_alloc(tfd, T_UNITDATA, T_ADDR);

		np = alp->n_addrs;				/* use first server address */
		tudptr->addr.len = min(tudptr->addr.maxlen, np->len);
		memcpy(tudptr->addr.buf, np->buf, tudptr->addr.len);
	
		endnetpath(handle);
		netdir_free(alp, ND_ADDRLIST);

		*vptr = tudptr;				/* return pointer to t_unitdata{} */
		*lenp = tudptr->addr.maxlen;/* and size of addresses */
		return(tfd);
	}
	endnetpath(handle);
	return(-1);
}
Beispiel #5
0
int
udp_server(const char *host, const char *serv, socklen_t *addrlenp)
{
	int					tfd;
	void				*handle;
	struct t_bind		tbind;
	struct t_info		tinfo;
	struct netconfig	*ncp;
	struct nd_hostserv	hs;
	struct nd_addrlist	*alp;
	struct netbuf		*np;

	handle = Setnetconfig();

	hs.h_host = (host == NULL) ? HOST_SELF : (char *) host;
	hs.h_serv = (char *) serv;

	while ( (ncp = getnetconfig(handle)) != NULL &&
		   strcmp(ncp->nc_proto, "udp") != 0)
			;

	if (ncp == NULL)
		return(-1);

	if (netdir_getbyname(ncp, &hs, &alp) != 0)
		return(-2);
	np = alp->n_addrs;		/* use first address */

	tfd = T_open(ncp->nc_device, O_RDWR, &tinfo);

	tbind.addr = *np;		/* copy entire netbuf{} */
	tbind.qlen = 0;			/* not used for connectionless server */
	T_bind(tfd, &tbind, NULL);

	endnetconfig(handle);
	netdir_free(alp, ND_ADDRLIST);

	if (addrlenp)
		*addrlenp = tinfo.addr;	/* size of protocol addresses */
	return(tfd);
}
Beispiel #6
0
/* include qlen */
void
do_parent(void)
{
	int				qlen, j, k, junk, fd[MAXBACKLOG + 1];
	struct t_call	tcall;

	Close(cfd);
	Signal(SIGALRM, parent_alrm);

	for (qlen = 0; qlen <= 14; qlen++) {
		printf("qlen = %d: ", qlen);
		Write(pfd, &qlen, sizeof(int));	/* tell child value */
		Read(pfd, &junk, sizeof(int));	/* wait for child */

		for (j = 0; j <= MAXBACKLOG; j++) {
			fd[j] = T_open(XTI_TCP, O_RDWR, NULL);
			T_bind(fd[j], NULL, NULL);

			tcall.addr.maxlen = sizeof(serv);
			tcall.addr.len = sizeof(serv);
			tcall.addr.buf = &serv;
			tcall.opt.len = 0;
			tcall.udata.len = 0;

			alarm(2);
			if (t_connect(fd[j], &tcall, NULL) < 0) {
				if (errno != EINTR)
					err_xti("t_connect error, j = %d", j);
				printf("timeout, %d connections completed\n", j-1);
				for (k = 1; k < j; k++)
					T_close(fd[k]);
				break;	/* next value of qlen */
			}
			alarm(0);
		}
		if (j > MAXBACKLOG)
			printf("%d connections?\n", MAXBACKLOG);
	}
	qlen = -1;		/* tell child we're all done */
	Write(pfd, &qlen, sizeof(int));
}
int
main(int argc, char **argv)
{
	int					fd;

	if (argc != 2)
		err_quit("usage: checkopts <device>");

	fd = T_open(argv[1], O_RDWR, NULL);
	T_bind(fd, NULL, NULL);

	req = T_alloc(fd, T_OPTMGMT, T_ALL);
	ret = T_alloc(fd, T_OPTMGMT, T_ALL);

	xti_def_uchar_opt(fd, "T_IP_TOS", T_INET_IP, T_IP_TOS);
	xti_def_uchar_opt(fd, "T_IP_TTL", T_INET_IP, T_IP_TTL);

	xti_def_uscalar_opt(fd, "T_TCP_MAXSEG", T_INET_TCP, T_TCP_MAXSEG);
	xti_def_uscalar_opt(fd, "T_TCP_NODELAY", T_INET_TCP, T_TCP_NODELAY);

	exit(0);
}
Beispiel #8
0
int
main(int argc, char **argv)
{
	int					fd;

	if (argc != 2)
		err_quit("usage: checkopts <device>");

	fd = T_open(argv[1], O_RDWR, NULL);
	T_bind(fd, NULL, NULL);

	req = T_alloc(fd, T_OPTMGMT, T_ALL);
	ret = T_alloc(fd, T_OPTMGMT, T_ALL);

	xti_set_uchar_opt(fd, "T_IP_TOS", T_INET_IP, T_IP_TOS,
									SET_TOS(T_ROUTINE, T_LDELAY));
	xti_set_uchar_opt(fd, "T_IP_TTL", T_INET_IP, T_IP_TTL, 23);

	/* xti_def_ulong_opt(fd, "TCP_MAXSEG", INET_TCP, TCP_MAXSEG); */
	/* xti_def_ulong_opt(fd, "TCP_NODELAY", INET_TCP, TCP_NODELAY); */

	exit(0);
}
Beispiel #9
0
int
main(int argc, char *argv[])
{
	int					fd, i, nmods;
	struct str_list		list;

	if (argc != 2)
		err_quit("usage: a.out <pathname>");

	fd = T_open(argv[1], O_RDWR, NULL);
	if (isastream(fd) == 0)
		err_quit("%s is not a stream", argv[1]);

	list.sl_nmods = nmods = Ioctl(fd, I_LIST, (void *) 0);
	printf("%d modules\n", nmods);
	list.sl_modlist = Calloc(nmods, sizeof(struct str_mlist));

	Ioctl(fd, I_LIST, &list);

	for (i = 1; i <= nmods; i++)
		printf("  %s: %s\n", (i == nmods) ? "driver" : "module",
								list.sl_modlist++);
	exit(0);
}
Beispiel #10
0
int
main(int argc, char **argv)
{
	int					tfd, n, flags;
	char				recvline[MAXLINE + 1];
	struct sockaddr_in	servaddr;
	struct t_call		tcall;
	struct t_discon		tdiscon;

	if (argc != 2)
		err_quit("usage: daytimecli01 <IPaddress>");

	tfd = T_open(XTI_TCP, O_RDWR, NULL);

	T_bind(tfd, NULL, NULL);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port   = htons(13);	/* daytime server */
	Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

	tcall.addr.maxlen = sizeof(servaddr);
	tcall.addr.len = sizeof(servaddr);
	tcall.addr.buf = &servaddr;

	tcall.opt.len = 0;		/* no options with connect */
	tcall.udata.len = 0;	/* no user data with connect */

	if (t_connect(tfd, &tcall, NULL) < 0) {
		if (t_errno == TLOOK) {
			if ( (n = T_look(tfd)) == T_DISCONNECT) {
				tdiscon.udata.maxlen = 0;
				T_rcvdis(tfd, &tdiscon);
				errno = tdiscon.reason;
				err_sys("t_connect error");
			} else
				err_quit("unexpected event after t_connect: %d", n);
		} else
			err_xti("t_connect error");
	}
/* end daytimecli1 */
/* include daytimecli2 */
	for ( ; ; ) {
		if ( (n = t_rcv(tfd, recvline, MAXLINE, &flags)) < 0) {
			if (t_errno == TLOOK) {
				if ( (n = T_look(tfd)) == T_ORDREL) {
					T_rcvrel(tfd);
					break;
				} else if (n == T_DISCONNECT) {
					tdiscon.udata.maxlen = 0;
					T_rcvdis(tfd, &tdiscon);
					errno = tdiscon.reason; /* probably ECONNRESET */
					err_sys("server terminated prematurely");
				} else
					err_quit("unexpected event after t_rcv: %d", n);
			} else
				err_xti("t_rcv error");
		}
		recvline[n] = 0;	/* null terminate */
		fputs(recvline, stdout);
	}
	exit(0);
}
int
tcp_connect(const char *host, const char *serv)
{
	int					tfd, i;
	void				*handle;
	struct t_call		tcall;
	struct t_discon		tdiscon;
	struct netconfig	*ncp;
	struct nd_hostserv	hs;
	struct nd_addrlist	*alp;
	struct netbuf		*np;
	struct t_opthdr		*topt;

	handle = Setnetpath();

	hs.h_host = (char *) host;
	hs.h_serv = (char *) serv;

	while ( (ncp = getnetpath(handle)) != NULL) {
		if (strcmp(ncp->nc_proto, "tcp") != 0)
			continue;

		if (netdir_getbyname(ncp, &hs, &alp) != 0)
			continue;

				/* try each server address */
		for (i = 0, np = alp->n_addrs; i < alp->n_cnt; i++, np++) {
			tfd = T_open(ncp->nc_device, O_RDWR, NULL);
		
			T_bind(tfd, NULL, NULL);

			tcall.addr.len  = np->len;
			tcall.addr.buf  = np->buf;	/* pointer copy */
			tcall.opt.len   = 0;		/* no options */
			tcall.udata.len = 0;		/* no user data with connect */
		
			if (t_connect(tfd, &tcall, NULL) == 0) {
				endnetpath(handle);		/* success, connected to server */
				netdir_free(alp, ND_ADDRLIST);

				req = T_alloc(fd, T_OPTMGMT, T_ALL);
				ret = T_alloc(fd, T_OPTMGMT, T_ALL);

				topt = (struct t_opthdr *) req->opt.buf;
				topt->level = T_INET_TCP;
				topt->name = T_TCP_MAXSEG;
				topt->len = sizeof(struct t_opthdr) + sizeof(u_long);
				req->opt.len = topt->len;

				topt = OPT_NEXTHDR(req->opt.buf, req->opt.maxlen, topt);
				topt->level = XTI_GENERIC;
				topt->name = XTI_SNDBUF;
				topt->len = sizeof(struct t_opthdr) + sizeof(u_long);
				req->opt.len += topt->len;

				return(tfd);
			}

			if (t_errno == TLOOK && t_look(tfd) == T_DISCONNECT) {
				t_rcvdis(tfd, &tdiscon);
				errno = tdiscon.reason;
			}
			t_close(tfd);
		}
		netdir_free(alp, ND_ADDRLIST);
	}
	endnetpath(handle);
	return(-1);
}