* Copyright (c) 1984-1987 by the Regents of the
* University of California and by Gregory Glenn Minshall.
* Permission to use, copy, modify, and distribute these
* programs and their documentation for any purpose and
* without fee is hereby granted, provided that this
* copyright and permission appear on all copies and
* supporting documentation, the name of the Regents of
* the University of California not be used in advertising
* or publicity pertaining to distribution of the programs
* without specific prior permission, and notice be given in
* supporting documentation that copying and distribution is
* by permission of the Regents of the University of California
* and by Gregory Glenn Minshall. Neither the Regents of the
* University of California nor Gregory Glenn Minshall make
* representations about the suitability of this software
* for any purpose. It is provided "as is" without
* express or implied warranty.
static char sccsid
[] = "@(#)api_bsd.c 1.9 (Berkeley) %G%";
if (api_exch_outcommand(EXCH_CMD_DISASSOCIATE
) == -1) {
} else if (api_exch_flush() == -1) {
char *string
; /* if non-zero, where to connect to */
struct sockaddr_in server
;
struct storage_descriptor sd
;
string
= getenv("API3270"); /* Get API */
"API3270 environmental variable not set - no API.\n");
if (sscanf(string
, "%[^:]:%d:%s", thehostname
, &port
, keyname
) != 3) {
fprintf(stderr
, "API3270 environmental variable has bad format.\n");
/* Now, try to connect */
sock
= socket(AF_INET
, SOCK_STREAM
, 0);
perror("opening API socket");
server
.sin_family
= AF_INET
;
hp
= gethostbyname(thehostname
);
fprintf(stderr
, "%s specifies bad host name.\n", string
);
bcopy(hp
->h_addr
, &server
.sin_addr
, hp
->h_length
);
server
.sin_port
= htons(port
);
if (connect(sock
, &server
, sizeof server
) < 0) {
perror("connecting to API server");
/* Now, try application level connection */
if (api_exch_init(sock
, "client") == -1) {
if (api_exch_outcommand(EXCH_CMD_ASSOCIATE
) == -1) {
keyfile
= fopen(keyname
, "r");
if (fscanf(keyfile
, "%s\n", inkey
) != 1) {
sd
.length
= strlen(inkey
)+1;
if (api_exch_outtype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
) == -1) {
if (api_exch_outtype(EXCH_TYPE_BYTES
, sd
.length
, inkey
) == -1) {
while ((i
= api_exch_nextcommand()) != EXCH_CMD_ASSOCIATED
) {
char *passwd
, *getpass();
if (api_exch_intype(EXCH_TYPE_STORE_DESC
,
sizeof sd
, (char *)&sd
) == -1) {
if (api_exch_intype(EXCH_TYPE_BYTES
, sd
.length
, buffer
) == -1) {
fprintf(stderr
, "%s\n", buffer
);
if (api_exch_outcommand(EXCH_CMD_ASSOCIATE
) == -1) {
if (api_exch_intype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
) == -1) {
if (api_exch_intype(EXCH_TYPE_BYTES
, sd
.length
, buffer
) == -1) {
passwd
= getpass(buffer
); /* Go to terminal */
passwd_length
= strlen(passwd
);
if (api_exch_intype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
) == -1) {
if (api_exch_intype(EXCH_TYPE_BYTES
, sd
.length
, buffer
) == -1) {
sd
.length
= passwd_length
;
if (api_exch_outcommand(EXCH_CMD_AUTH
) == -1) {
if (api_exch_outtype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
) == -1) {
if (api_exch_outtype(EXCH_TYPE_BYTES
, passwd_length
, passwd
) == -1) {
"Waiting for connection indicator, received 0x%x.\n", i
);
return 0; /* Happiness! */
api_exch_api(regs
, sregs
, parms
, length
)
struct storage_descriptor sd
;
if (api_exch_outcommand(EXCH_CMD_REQUEST
) == -1) {
if (api_exch_outtype(EXCH_TYPE_REGS
, sizeof *regs
, (char *)regs
) == -1) {
if (api_exch_outtype(EXCH_TYPE_SREGS
, sizeof *sregs
, (char *)sregs
) == -1) {
sd
.location
= (long) parms
;
if (api_exch_outtype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
) == -1) {
if (api_exch_outtype(EXCH_TYPE_BYTES
, length
, parms
) == -1) {
while ((i
= api_exch_nextcommand()) != EXCH_CMD_REPLY
) {
if (api_exch_intype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
)
/*XXX validity check GIMME? */
if (api_exch_outcommand(EXCH_CMD_HEREIS
) == -1) {
if (api_exch_outtype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
)
if (api_exch_outtype(EXCH_TYPE_BYTES
, sd
.length
,
if (api_exch_intype(EXCH_TYPE_STORE_DESC
, sizeof sd
, (char *)&sd
)
/* XXX Validty check HEREIS? */
if (api_exch_intype(EXCH_TYPE_BYTES
, sd
.length
,
fprintf(stderr
, "Waiting for reply command, we got command %d.\n",
if (api_exch_intype(EXCH_TYPE_REGS
, sizeof *regs
, (char *)regs
) == -1) {
if (api_exch_intype(EXCH_TYPE_SREGS
, sizeof *sregs
, (char *)sregs
) == -1) {
return 0; /* Happiness! */