* Copyright (c) 1988, 1991 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1988, 1991 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)xi_src.c 7.5 (Berkeley) 5/7/91";
* This is a test program to be a source for X.25 connections.
#include <netccitt/x25.h>
#define dbprintf if(verbose)printf
#define try(a,b,c) {x = (a b);dbprintf("%s%s returns %d\n",c,"a",x);\
if (x < 0) {perror("a"); exit(1);}}
fd_set readfds
, writefds
, exceptfds
;
int verbose
= 1, selectp
, type
= SOCK_STREAM
, nobuffs
, errno
, playtag
= 0;
char your_it
[] = "You're it!";
char *port
, *conndata
, data_msg
[2048];
struct iovec iov
[1] = {data_msg
};
char cmdata
[128 - sizeof (struct cmsghdr
)];
struct msghdr msg
= { 0, 0, iov
, 1, 0, 0, 0};
register char **av
= argv
;
if (strcmp(*av
,"dest")==0) {
} else if (strcmp(*av
,"count")==0) {
sscanf(*av
,"%ld",&count
);
} else if (strcmp(*av
,"size")==0) {
int x
, s
, pid
, on
= 1, flags
= 8, n
;
try(socket
, (AF_CCITT
, type
, 0),"");
/*try(setsockopt, (s, SOL_SOCKET, SO_DEBUG, &on, sizeof (on)), "");*/
to
.x25_opts
.op_flags
|= X25_MQBIT
;
try(connect
, (s
, (struct sockaddr
*) &to
, to
.x25_len
), "");
FD_ZERO(&writefds
); FD_SET(s
, &writefds
);
select(1, &writefds
, 0, 0, 0);
if (size
<= 0 && get_record(&flags
) == EOF
)
n
= put_record(s
, flags
);
if (n
==-1 && errno
== 55) {
fprintf(stderr
, "wrote %d < %d, count %d,",
iov
->iov_len
= sizeof your_it
;
sendmsg(s
, &msg
, MSG_EOR
);
sendmsg(s
, &msg
, MSG_EOR
);
iov
->iov_base
= data_msg
;
iov
->iov_len
= sizeof data_msg
;
try(recvmsg
, (s
, &msg
, flags
), " playtag ");
printf("looped %d times waiting for bufs\n", nobuffs
);
unsigned short *zp
, *zlim
;
if (msg
.msg_controllen
) {
zp
= (unsigned short *)&(cm
.cm
.cmhdr
.cmsg_len
);
printf("(CMessage Type is %x) ", cm
.cm
.cmhdr
.cmsg_type
);
zlim
= zp
+ ((x
+ 1) / 2);
while (zp
< zlim
) printf("%x ", *zp
++);
(flags
& MSG_OOB
? "(OOB Data)" : ""),
(flags
& MSG_EOR
? "(Record Mark)" : ""));
zp
= (unsigned short *)data_msg
;
zlim
= zp
+ ((x
+ 1) / 2);
while (zp
< zlim
) printf("%x ", *zp
++);
bcopy(iov
->iov_base
, dupbuf
, buflen
);
try(sendmsg
, (s
, &msg
, flags
), " put_record ");
while (verify
&& buflen
> 0) {
try(recvmsg
, (s
, &msg
, flags
), " put_record ");
printf("verify got %d\n", x
);
int *datasize
= &iov
->iov_len
;
get_control_data(type
, level
)
datasize
= (int *)&msg
.msg_controllen
;
cplim
= cp
+ sizeof(cm
.cm
.cmdata
);
cm
.cm
.cmhdr
.cmsg_level
= level
;
cm
.cm
.cmhdr
.cmsg_type
= type
;
msg
.msg_control
= cm
.data
;
static repeatcount
, repeatsize
;
datasize
= &iov
->iov_len
;
cplim
= data_msg
+ sizeof(data_msg
);
x
= scanf("%s", workbuf
);
if (strcmp(workbuf
, "oob") == 0)
else if (strcmp(workbuf
, "qbit") == 0)
else if (strcmp(workbuf
, "mbit") == 0)
else if (strcmp(workbuf
, "eom") == 0)
else if (strcmp(workbuf
, "factor") == 0) {
x
= scanf("%d", &factor
);
if (factor
<= 0) factor
= 1;
} else if (strcmp(workbuf
, "repeat") == 0) {
x
= scanf("%d", &repeatcount
);
if (repeatcount
<= 0) repeatcount
= 1;
int len
= strlen(workbuf
);
if (datasize
!= &iov
->iov_len
) {
*datasize
+= sizeof(cm
.cm
.cmhdr
);
repeatsize
= cm
.cm
.cmhdr
.cmsg_len
= *datasize
;