|
|
Power 6/32 Unix version 1.21
#include "ctl.h"
#include <stdio.h>
#include <errno.h>
#include <sgtty.h>
#include <sys/ioctl.h>
int debug;
/*---------------------------------------------
This module converts from local format to VAX format in which:
- data fields are compacted. No gaps between fields.
- byte ordering is right to left.
--------------------------------------------*/
/*---------------------------------------------------------
convert requests from net to local format.
Changes should work with VAX implementations that don't do byte ordering.
--------------------------------------------------------*/
/*------------------------------------------------------------
Convert requests from local to net format.
Changes should work with VAX that don't byte order its messages.
----------------------------------------------------------*/
tonetmsg(msg, netmsg, swap)
CTL_MSG *msg;
NETCTL_MSG *netmsg;
int swap;
{
netmsg->mtype = msg->ctlm_type;
bcopy(msg->ctlm_l_name, netmsg->ml_name, sizeof(netmsg->ml_name));
bcopy(msg->ctlm_r_name, netmsg->mr_name, sizeof(netmsg->mr_name));
bcopy((char *)&msg->ctlm_id_num, netmsg->mid_num,
sizeof(netmsg->mid_num));
bcopy((char *)&msg->ctlm_pid, netmsg->mpid, sizeof(netmsg->mpid));
bcopy(msg->ctlm_r_tty, netmsg->mr_tty, sizeof(netmsg->mr_tty));
bcopy((char *)&msg->ctlm_addr, netmsg->maddr, sizeof(netmsg->maddr));
bcopy((char *)&msg->ctlm_ctl_addr, netmsg->mctl_addr,
sizeof(netmsg->mctl_addr));
if (swap)
swapnetmsg(netmsg);
}
/*------------------------------------------------------------
Convert messages from local to net format.
Should work with VAX versions which do not byte order messages.
----------------------------------------------------------*/
int
frnetmsg(netmsg, msg)
NETCTL_MSG *netmsg;
CTL_MSG *msg;
{
int swapped;
swapped = swapmsg(netmsg);
msg->ctlm_type = netmsg->mtype ;
bcopy(netmsg->ml_name, msg->ctlm_l_name, sizeof(netmsg->ml_name));
bcopy(netmsg->mr_name, msg->ctlm_r_name, sizeof(netmsg->mr_name));
bcopy(netmsg->mid_num, (char *)&msg->ctlm_id_num,
sizeof(netmsg->mid_num));
bcopy(netmsg->mpid, (char *)&msg->ctlm_pid, sizeof(netmsg->mpid));
bcopy(netmsg->mr_tty, msg->ctlm_r_tty, sizeof(netmsg->mr_tty));
bcopy(netmsg->maddr, (char *)&msg->ctlm_addr, sizeof(netmsg->maddr));
bcopy(netmsg->mctl_addr, (char *)&msg->ctlm_ctl_addr,
sizeof(netmsg->mctl_addr));
return(swapped);
}
/*------------------------------------------------------------
Convert responses from net to local format
Changes should work with VAX that don't byte order its messages.
----------------------------------------------------------*/
int
frnetresp(netresp, resp)
NETCTL_RESPONSE *netresp;
CTL_RESPONSE *resp;
{
int swapped;
swapped = swapresp(netresp);
resp->ctlr_type = netresp->rtype;
resp->ctlr_answer = netresp->ranswer;
bcopy(netresp->rid_num, (char *)&resp->ctlr_id_num,
sizeof(netresp->rid_num));
bcopy(netresp->raddr, (char *)&resp->ctlr_addr,
sizeof(netresp->raddr));
return(swapped);
}
/*------------------------------------------------------------
Convert responses from local to net format.
Changes should work with VAX that don't byte order its messages
----------------------------------------------------------*/
tonetresp(resp, netresp, swap)
CTL_RESPONSE *resp;
NETCTL_RESPONSE *netresp;
int swap;
{
netresp->rtype = resp->ctlr_type ;
netresp->ranswer = resp->ctlr_answer;
bcopy( (char *)&resp->ctlr_id_num, netresp->rid_num,
sizeof(netresp->rid_num));
bcopy((char *)&resp->ctlr_addr,netresp->raddr,sizeof(netresp->raddr));
if (swap)
swapnetresp(netresp);
}
#define swapbyte(A,B) { \
char t; \
t=(A);(A)=(B);(B)=t; \
}
#define swaplong(X) { \
char t; \
swapbyte((X)[0], (X)[3]); \
swapbyte((X)[1], (X)[2]); \
}
#define swapshort(X) { \
swapbyte((X)[0], (X)[1]); \
}
#define swapaddr(X) { \
swapshort((X)) /* swap family */ \
/*swapshort(((char *)(X)+2))*/ /* swap port */ \
/*swaplong(((char *)(X)+4))*/ /* swap inet addr */ \
/*swaplong(((char *)(X)+8))*/ /* swap "junk" */ \
}
/*------------------------------------------------------------
swapmsg
perform some heuristic test to see if packet has to
be re-byte-ordered. If so, byte order and return 1, else
return 0.
----------------------------------------------------------*/
swapmsg(netmsg)
NETCTL_MSG *netmsg;
{
union t {
struct sockaddr_in addr;
char saddr[sizeof(struct sockaddr_in)];
} u;
bcopy(netmsg->mctl_addr, u.saddr, sizeof(u.saddr));
swapaddr(u.saddr);
if (u.addr.sin_family == AF_INET) {
swapnetmsg(netmsg);
return(1);
}
else
return(0);
}
/*------------------------------------------------------------
swapresp
perform some heuristic test to see if packet has to
be re-byte-ordered. If so, byte order and return 1, else
return 0.
----------------------------------------------------------*/
swapresp(netresp)
NETCTL_RESPONSE *netresp;
{
union t {
struct sockaddr_in addr;
char saddr[sizeof(struct sockaddr_in)];
} u;
bcopy(netresp->raddr, u.saddr, sizeof(u.saddr));
swapaddr(u.saddr);
if (u.addr.sin_family == AF_INET) {
swapnetresp(netresp);
return(1);
}
else
return(0);
}
/*------------------------------------------------------------
swapnetmsg
----------------------------------------------------------*/
swapnetmsg(netmsg)
NETCTL_MSG *netmsg;
{
char t;
if (debug)
printf("swapnetmsg\n");
swaplong(netmsg->mid_num)
swaplong(netmsg->mpid)
swapaddr(netmsg->maddr)
swapaddr(netmsg->mctl_addr)
}
/*------------------------------------------------------------
swapnetresp
----------------------------------------------------------*/
swapnetresp(netresp)
NETCTL_RESPONSE *netresp;
{
char t;
swaplong(netresp->rid_num);
if (debug) {
int i;
printf("before swapnetresp:");
for (i=0; i<sizeof(netresp->raddr); i++)
printf("%x ",netresp->raddr[i] & 0xff);
printf("\n");
}
swapaddr(netresp->raddr);
if (debug) {
int i;
printf("swapnetresp:");
for (i=0; i<sizeof(netresp->raddr); i++)
printf("%x ",netresp->raddr[i] & 0xff);
printf("\n");
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.