|
|
1.1 ! root 1: #include "share.h" ! 2: ! 3: char *cmdname[] = {"0?", "nbput", "nbget", "nbupd", "nbread", ! 4: "nbwrt", "nbnami", "nbstat", "nbioctl", "nbtrnc", "10?", "11?"}; ! 5: /* build the responses, and translate into client terms */ ! 6: /* the translation scheme here knows client lengths, which will have to ! 7: * be parameterized for clients that aren't vaxes */ ! 8: ! 9: responce(cmd) ! 10: { unsigned char *p = inbuf, *q; ! 11: int n; ! 12: /* the common header first */ ! 13: hostlong(client.trannum, p); ! 14: p += 4; ! 15: hostshort(client.errno, p); ! 16: p += 2; ! 17: hostchar(client.namiflags, p); ! 18: p += 1; ! 19: p += 1; /* skip */ ! 20: ! 21: q = p; ! 22: p += 4; /* that's the total response len */ ! 23: p += 4; /* skip */ ! 24: switch(cmd) { ! 25: default: ! 26: fatal("respond(%d)\n", cmd); ! 27: case NBWRT: case NBTRNC: case NBUPD: case NBPUT: ! 28: hostlong(16, q); ! 29: break; ! 30: case NBREAD: ! 31: break; ! 32: case NBNAMI: ! 33: hostlong(client.tag, p); ! 34: p += 4; ! 35: hostlong(client.ino, p); ! 36: p += 4; ! 37: hostshort(client.dev, p); ! 38: p += 2; ! 39: hostshort(client.mode, p); ! 40: p += 2; ! 41: hostlong(client.used, p); /* what's with this? */ ! 42: p += 4; ! 43: goto common; ! 44: case NBSTAT: ! 45: hostlong(client.ino, p); ! 46: p += 4; ! 47: hostshort(client.dev, p); ! 48: p += 2; ! 49: hostshort(client.mode, p); ! 50: p += 2; ! 51: common: ! 52: hostshort(client.nlink, p); ! 53: p += 2; ! 54: hostshort(client.uid, p); ! 55: p += 2; ! 56: hostshort(client.gid, p); ! 57: p += 2; ! 58: p += 2; /* skip rdev */ ! 59: hostlong(client.size, p); ! 60: p += 4; ! 61: hostlong(client.ta, p); ! 62: p += 4; ! 63: hostlong(client.tm, p); ! 64: p += 4; ! 65: hostlong(client.tc, p); ! 66: p += 4; ! 67: break; ! 68: } ! 69: if(!client.resplen) ! 70: client.resplen = p - inbuf; ! 71: hostlong(client.resplen, q); ! 72: debug("responding to %s with %d (%d)\n", cmdname[cmd], client.resplen, ! 73: client.errno); ! 74: n = write(cfd, inbuf, (int)client.resplen); ! 75: if(n == client.resplen) ! 76: return; ! 77: if(n < 0) ! 78: fatal("server(%d): write of len %d errno %d\n", cfd, client.resplen, errno); ! 79: fatal("server: write of len %d only sent %d\n", client.resplen, n); ! 80: } ! 81: ! 82: /* convert to client stuff */ ! 83: #ifdef ns32000 ! 84: #define vax 1 ! 85: #endif ! 86: #if vax == 1 ! 87: hostlong(n, p) ! 88: unsigned char *p; ! 89: long n; ! 90: { union { ! 91: long x; ! 92: unsigned char b[4]; ! 93: } u; ! 94: int i; ! 95: ! 96: switch (clienttype) { ! 97: case 'v': ! 98: *(long *)p = n; ! 99: break; ! 100: case 's': ! 101: u.x = n; ! 102: for(i = 0; i < 4; i++) ! 103: *p++ = u.b[3-i]; ! 104: break; ! 105: } ! 106: } ! 107: ! 108: hostshort(n, p) ! 109: unsigned char *p; ! 110: { union { ! 111: short x; ! 112: unsigned char b[2]; ! 113: } u; ! 114: int i; ! 115: ! 116: switch (clienttype) { ! 117: case 'v': ! 118: *(short *)p = n; ! 119: break; ! 120: case 's': ! 121: u.x = n; ! 122: for(i = 0; i < 2; i++) ! 123: *p++ = u.b[1-i]; ! 124: break; ! 125: } ! 126: } ! 127: ! 128: hostchar(n, p) ! 129: unsigned char *p; ! 130: { ! 131: *p = n; ! 132: } ! 133: #endif ! 134: #if cray == 1 ! 135: hostlong(n, p) /* truncates */ ! 136: unsigned char *p; ! 137: { union { ! 138: long x; ! 139: unsigned char b[8]; ! 140: } u; ! 141: int i; ! 142: u.x = n; ! 143: switch (clienttype) { ! 144: case 'v': ! 145: for(i = 0; i < 4; i++) ! 146: *p++ = u.b[7-i]; ! 147: break; ! 148: case 's': ! 149: for(i = 0; i < 4; i++) ! 150: *p++ = u.b[4+i]; ! 151: break; ! 152: } ! 153: } ! 154: hostshort(n, p) /* truncates */ ! 155: unsigned char *p; ! 156: { union { ! 157: int x; ! 158: unsigned char b[8]; ! 159: } u; ! 160: int i; ! 161: u.x = n; ! 162: switch (clienttype) { ! 163: case 'v': ! 164: for(i = 0; i < 2; i++) ! 165: *p++ = u.b[7-i]; ! 166: break; ! 167: case 's': ! 168: for(i = 0; i < 2; i++) ! 169: *p++ = u.b[6+i]; ! 170: break; ! 171: } ! 172: } ! 173: hostchar(n, p) ! 174: unsigned char *p; ! 175: { ! 176: *p = n; ! 177: } ! 178: #endif ! 179: #if sun == 1 ! 180: hostlong(n, p) ! 181: unsigned char *p; ! 182: long n; ! 183: { union { ! 184: long x; ! 185: unsigned char b[4]; ! 186: } u; ! 187: int i; ! 188: ! 189: switch (clienttype) { ! 190: case 'v': ! 191: u.x = n; ! 192: for(i = 0; i < 4; i++) ! 193: *p++ = u.b[3-i]; ! 194: break; ! 195: case 's': ! 196: *(long *)p = n; ! 197: break; ! 198: } ! 199: } ! 200: hostshort(n, p) ! 201: unsigned char *p; ! 202: { union { ! 203: short x; ! 204: unsigned char b[2]; ! 205: } u; ! 206: int i; ! 207: ! 208: switch (clienttype) { ! 209: case 'v': ! 210: u.x = n; ! 211: for(i = 0; i < 2; i++) ! 212: *p++ = u.b[1-i]; ! 213: break; ! 214: case 's': ! 215: *(short *)p = n; ! 216: break; ! 217: } ! 218: } ! 219: hostchar(n, p) ! 220: unsigned char *p; ! 221: { ! 222: *p = n; ! 223: } ! 224: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.