/* ubcx25.c - X.25 abstractions for UBC X25 */
static char *rcsid
= "$Header: /f/osi/compat/RCS/ubcx25.c,v 7.4 91/02/22 09:16:13 mrose Interim $";
* $Header: /f/osi/compat/RCS/ubcx25.c,v 7.4 91/02/22 09:16:13 mrose Interim $
* Contributed by Julian Onions, Nottingham University in the UK
* Revision 7.4 91/02/22 09:16:13 mrose
* Revision 7.3 91/01/14 13:33:53 mrose
* Revision 7.2 90/07/09 14:32:28 mrose
* Revision 7.1 89/12/07 01:08:02 mrose
* Revision 7.0 89/11/23 21:23:47 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
/* \f 4.[23] UNIX: UBC X25 */
int start_x25_client (local
)
local
-> na_stack
= NA_X25
, local
-> na_community
= ts_comm_x25_default
;
if ((sd
= socket (AF_CCITT
, SOCK_STREAM
, 0)) == NOTOK
) {
SLOG (compat_log
, LLOG_EXCEPTIONS
, "failed", ("socket"));
return NOTOK
; /* Error can be found in errno */
if (ioctl(sd
, SIOCSPGRP
, &pgrp
)) {
SLOG (compat_log
, LLOG_EXCEPTIONS
, "failed", ("SIOCSPGRP"));
return NOTOK
; /* Error can be found in errno */
int start_x25_server (local
, backlog
, opt1
, opt2
)
if ((sd
= socket (AF_CCITT
, SOCK_STREAM
, 0)) == NOTOK
) {
SLOG (compat_log
, LLOG_EXCEPTIONS
, "failed", ("socket"));
return NOTOK
; /* Can't get an X.25 socket */
if (ioctl(sd
, SIOCSPGRP
, &pgrp
)) {
SLOG (compat_log
, LLOG_EXCEPTIONS
, "failed", ("SIOCSPGRP"));
return NOTOK
; /* Error can be found in errno */
local
-> na_stack
= NA_X25
, local
-> na_community
= ts_comm_x25_default
;
if (local
-> na_dtelen
== 0) {
(void) strcpy (local
-> na_dte
, x25_local_dte
);
local
-> na_dtelen
= strlen(x25_local_dte
);
if (local
-> na_pidlen
== 0 && *x25_local_pid
)
str2sel (x25_local_pid
, -1, local
-> na_pid
, NPSIZE
);
(void) gen2if (local
, sck
, ADDR_LISTEN
);
if (bind (sd
, sck
, sizeof(CONN_DB
)) == NOTOK
) {
SLOG (compat_log
, LLOG_EXCEPTIONS
, "failed", ("bind"));
(void) close_x25_socket (sd
);
#ifdef notyet /* not sure if these are supported... */
(void) setsockopt (sd
, SOL_SOCKET
, opt1
, NULLCP
, 0);
(void) setsockopt (sd
, SOL_SOCKET
, opt2
, NULLCP
, 0);
(void) setsockopt (sd
, SOL_SOCKET
, opt1
, (char *)&onoff
, sizeof onoff
);
(void) setsockopt (sd
, SOL_SOCKET
, opt2
, (char *)&onoff
, sizeof onoff
);
(void) listen (sd
, backlog
);
int join_x25_client (fd
, remote
)
if((nfd
= accept (fd
, (struct sockaddr
*) &sck
, &len
)) == NOTOK
)
(void) if2gen (remote
, &sck
, ADDR_REMOTE
);
int join_x25_server (fd
, remote
)
if (remote
== NULLNA
|| remote
-> na_stack
!= NA_X25
)
SLOG (compat_log
, LLOG_EXCEPTIONS
, NULLCP
,
("Invalid type na%d", remote
->na_stack
));
(void) gen2if (remote
, sck
, ADDR_REMOTE
);
return connect (fd
, sck
, sizeof (CONN_DB
));
int read_x25_socket (fd
, buffer
, len
)
static struct iovec iov
[2] = {
int cc
, count
= 0, total
= len
;
iov
[1].iov_len
= total
> X25_PACKETSIZE
? X25_PACKETSIZE
: total
;
switch (cc
= readv (fd
, iov
, 2)) {
* for the -1,0 & 1 cases these returns should be ok
* if it's the first time through, then they are valid anyway
* later stages means the M bit is set so there must
* be more data else someone is violating the
SLOG (compat_log
, LLOG_EXCEPTIONS
, NULLCP
,
("strange return from read_x25_socket"));
cc
--; /* discount the info byte */
} while (len
> 0 && (mode
& X25_MBIT
));
DLOG (compat_log
, LLOG_DEBUG
, ("X25 read, total %d/%d", count
, len
));
/* God this all very bizarre - iovecs work on read but not write!! */
* OK, this is due to a bug in UBC implementation. It may or may not
* be fixed in later versions. If writev allows you to write single
* bytes in the first vector then use this version. It's much more
int write_x25_socket (fd
, buffer
, len
)
static struct iovec iov
[2] = {
count
= len
> X25_PACKETSIZE
? X25_PACKETSIZE
: len
;
mode
= len
> X25_PACKETSIZE
? X25_MBIT
: 0;
switch (cc
= writev (fd
, iov
, 2))
SLOG (compat_log
, LLOG_EXCEPTIONS
, NULLCP
,
("strange return from write_x25_socket"));
DLOG (compat_log
, LLOG_DEBUG
, ("X25 write, total %d/%d", total
, len
));
int write_x25_socket (fd
, buffer
, len
)
char mybuffer
[X25_PACKETSIZE
+1];
count
= len
> X25_PACKETSIZE
? X25_PACKETSIZE
: len
;
mybuffer
[0] = len
> X25_PACKETSIZE
? X25_MBIT
: 0;
bcopy (p
, &mybuffer
[1], count
);
switch (cc
= write (fd
, mybuffer
, count
+ 1))
SLOG (compat_log
, LLOG_EXCEPTIONS
, NULLCP
,
("strange return from write_x25_socket"));
DLOG (compat_log
, LLOG_DEBUG
, ("X25 write, total %d/%d", total
, len
));