|
|
1.1 root 1:
2: #include "ctl.h"
3:
4:
5: #include <stdio.h>
6: #include <errno.h>
7: #include <sgtty.h>
8: #include <sys/ioctl.h>
9:
10: int debug;
11: /*---------------------------------------------
12: This module converts from local format to VAX format in which:
13:
14: - data fields are compacted. No gaps between fields.
15: - byte ordering is right to left.
16:
17: --------------------------------------------*/
18:
19: /*---------------------------------------------------------
20: convert requests from net to local format.
21: Changes should work with VAX implementations that don't do byte ordering.
22: --------------------------------------------------------*/
23: /*------------------------------------------------------------
24: Convert requests from local to net format.
25: Changes should work with VAX that don't byte order its messages.
26: ----------------------------------------------------------*/
27: tonetmsg(msg, netmsg, swap)
28: CTL_MSG *msg;
29: NETCTL_MSG *netmsg;
30: int swap;
31: {
32:
33:
34: netmsg->mtype = msg->ctlm_type;
35: bcopy(msg->ctlm_l_name, netmsg->ml_name, sizeof(netmsg->ml_name));
36: bcopy(msg->ctlm_r_name, netmsg->mr_name, sizeof(netmsg->mr_name));
37: bcopy((char *)&msg->ctlm_id_num, netmsg->mid_num,
38: sizeof(netmsg->mid_num));
39: bcopy((char *)&msg->ctlm_pid, netmsg->mpid, sizeof(netmsg->mpid));
40: bcopy(msg->ctlm_r_tty, netmsg->mr_tty, sizeof(netmsg->mr_tty));
41: bcopy((char *)&msg->ctlm_addr, netmsg->maddr, sizeof(netmsg->maddr));
42: bcopy((char *)&msg->ctlm_ctl_addr, netmsg->mctl_addr,
43: sizeof(netmsg->mctl_addr));
44:
45: if (swap)
46: swapnetmsg(netmsg);
47: }
48:
49:
50: /*------------------------------------------------------------
51: Convert messages from local to net format.
52: Should work with VAX versions which do not byte order messages.
53: ----------------------------------------------------------*/
54: int
55: frnetmsg(netmsg, msg)
56: NETCTL_MSG *netmsg;
57: CTL_MSG *msg;
58: {
59: int swapped;
60:
61: swapped = swapmsg(netmsg);
62:
63: msg->ctlm_type = netmsg->mtype ;
64: bcopy(netmsg->ml_name, msg->ctlm_l_name, sizeof(netmsg->ml_name));
65: bcopy(netmsg->mr_name, msg->ctlm_r_name, sizeof(netmsg->mr_name));
66: bcopy(netmsg->mid_num, (char *)&msg->ctlm_id_num,
67: sizeof(netmsg->mid_num));
68: bcopy(netmsg->mpid, (char *)&msg->ctlm_pid, sizeof(netmsg->mpid));
69: bcopy(netmsg->mr_tty, msg->ctlm_r_tty, sizeof(netmsg->mr_tty));
70: bcopy(netmsg->maddr, (char *)&msg->ctlm_addr, sizeof(netmsg->maddr));
71: bcopy(netmsg->mctl_addr, (char *)&msg->ctlm_ctl_addr,
72: sizeof(netmsg->mctl_addr));
73:
74: return(swapped);
75: }
76: /*------------------------------------------------------------
77: Convert responses from net to local format
78: Changes should work with VAX that don't byte order its messages.
79: ----------------------------------------------------------*/
80: int
81: frnetresp(netresp, resp)
82: NETCTL_RESPONSE *netresp;
83: CTL_RESPONSE *resp;
84: {
85: int swapped;
86:
87: swapped = swapresp(netresp);
88:
89: resp->ctlr_type = netresp->rtype;
90: resp->ctlr_answer = netresp->ranswer;
91: bcopy(netresp->rid_num, (char *)&resp->ctlr_id_num,
92: sizeof(netresp->rid_num));
93: bcopy(netresp->raddr, (char *)&resp->ctlr_addr,
94: sizeof(netresp->raddr));
95:
96: return(swapped);
97: }
98: /*------------------------------------------------------------
99: Convert responses from local to net format.
100: Changes should work with VAX that don't byte order its messages
101: ----------------------------------------------------------*/
102:
103: tonetresp(resp, netresp, swap)
104: CTL_RESPONSE *resp;
105: NETCTL_RESPONSE *netresp;
106: int swap;
107: {
108:
109: netresp->rtype = resp->ctlr_type ;
110: netresp->ranswer = resp->ctlr_answer;
111: bcopy( (char *)&resp->ctlr_id_num, netresp->rid_num,
112: sizeof(netresp->rid_num));
113: bcopy((char *)&resp->ctlr_addr,netresp->raddr,sizeof(netresp->raddr));
114:
115: if (swap)
116: swapnetresp(netresp);
117:
118: }
119:
120: #define swapbyte(A,B) { \
121: char t; \
122: t=(A);(A)=(B);(B)=t; \
123: }
124: #define swaplong(X) { \
125: char t; \
126: swapbyte((X)[0], (X)[3]); \
127: swapbyte((X)[1], (X)[2]); \
128: }
129: #define swapshort(X) { \
130: swapbyte((X)[0], (X)[1]); \
131: }
132: #define swapaddr(X) { \
133: swapshort((X)) /* swap family */ \
134: /*swapshort(((char *)(X)+2))*/ /* swap port */ \
135: /*swaplong(((char *)(X)+4))*/ /* swap inet addr */ \
136: /*swaplong(((char *)(X)+8))*/ /* swap "junk" */ \
137: }
138: /*------------------------------------------------------------
139: swapmsg
140: perform some heuristic test to see if packet has to
141: be re-byte-ordered. If so, byte order and return 1, else
142: return 0.
143: ----------------------------------------------------------*/
144: swapmsg(netmsg)
145: NETCTL_MSG *netmsg;
146: {
147: union t {
148: struct sockaddr_in addr;
149: char saddr[sizeof(struct sockaddr_in)];
150: } u;
151:
152: bcopy(netmsg->mctl_addr, u.saddr, sizeof(u.saddr));
153: swapaddr(u.saddr);
154: if (u.addr.sin_family == AF_INET) {
155: swapnetmsg(netmsg);
156: return(1);
157: }
158: else
159: return(0);
160: }
161:
162: /*------------------------------------------------------------
163: swapresp
164: perform some heuristic test to see if packet has to
165: be re-byte-ordered. If so, byte order and return 1, else
166: return 0.
167: ----------------------------------------------------------*/
168: swapresp(netresp)
169: NETCTL_RESPONSE *netresp;
170: {
171: union t {
172: struct sockaddr_in addr;
173: char saddr[sizeof(struct sockaddr_in)];
174: } u;
175:
176: bcopy(netresp->raddr, u.saddr, sizeof(u.saddr));
177: swapaddr(u.saddr);
178: if (u.addr.sin_family == AF_INET) {
179: swapnetresp(netresp);
180: return(1);
181: }
182: else
183: return(0);
184: }
185:
186: /*------------------------------------------------------------
187: swapnetmsg
188: ----------------------------------------------------------*/
189: swapnetmsg(netmsg)
190: NETCTL_MSG *netmsg;
191: {
192: char t;
193:
194: if (debug)
195: printf("swapnetmsg\n");
196: swaplong(netmsg->mid_num)
197: swaplong(netmsg->mpid)
198: swapaddr(netmsg->maddr)
199: swapaddr(netmsg->mctl_addr)
200: }
201: /*------------------------------------------------------------
202: swapnetresp
203: ----------------------------------------------------------*/
204: swapnetresp(netresp)
205: NETCTL_RESPONSE *netresp;
206: {
207: char t;
208:
209: swaplong(netresp->rid_num);
210: if (debug) {
211: int i;
212:
213: printf("before swapnetresp:");
214: for (i=0; i<sizeof(netresp->raddr); i++)
215: printf("%x ",netresp->raddr[i] & 0xff);
216: printf("\n");
217: }
218: swapaddr(netresp->raddr);
219: if (debug) {
220: int i;
221:
222: printf("swapnetresp:");
223: for (i=0; i<sizeof(netresp->raddr); i++)
224: printf("%x ",netresp->raddr[i] & 0xff);
225: printf("\n");
226: }
227: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.