diff --git a/src/connection.ts b/src/connection.ts index d810acb16..75e32252b 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -873,6 +873,7 @@ export interface ConnectionOptions { interface RoutingData { server: string; port: number; + instance: string; } /** @@ -2484,7 +2485,7 @@ class Connection extends EventEmitter { } payload.hostname = this.config.options.workstationId || os.hostname(); - payload.serverName = this.routingData ? this.routingData.server : this.config.server; + payload.serverName = this.routingData ? `${this.routingData.server}\\${this.routingData.instance}` : this.config.server; payload.appName = this.config.options.appName || 'Tedious'; payload.libraryName = libraryName; payload.language = this.config.options.language; diff --git a/src/login7-payload.ts b/src/login7-payload.ts index 01b85f94c..899d0b583 100644 --- a/src/login7-payload.ts +++ b/src/login7-payload.ts @@ -251,15 +251,12 @@ class Login7Payload { } // (ibUnused / ibExtension): 2-byte - offset = fixedData.writeUInt16LE(dataOffset, offset); + const extensionOffsetHeaderOffset = offset; + offset = fixedData.writeUInt16LE(0, offset); + // (cchUnused / cbExtension): 2-byte - const extensions = this.buildFeatureExt(); offset = fixedData.writeUInt16LE(4, offset); - const extensionOffset = Buffer.alloc(4); - extensionOffset.writeUInt32LE(dataOffset += 4, 0); - dataOffset += extensions.length; - buffers.push(extensionOffset, extensions); // ibCltIntName: 2-byte offset = fixedData.writeUInt16LE(dataOffset, offset); @@ -365,6 +362,13 @@ class Login7Payload { fixedData.writeUInt32LE(0, offset); } + fixedData.writeUInt16LE(dataOffset, extensionOffsetHeaderOffset); + + const extensions = this.buildFeatureExt(); + const extensionOffset = Buffer.alloc(4); + extensionOffset.writeUInt32LE(dataOffset + 4, 0); + buffers.push(extensionOffset, extensions); + const data = Buffer.concat(buffers); data.writeUInt32LE(data.length, 0); return data; diff --git a/src/token/handler.ts b/src/token/handler.ts index 0c259a723..832e5bd4c 100644 --- a/src/token/handler.ts +++ b/src/token/handler.ts @@ -246,7 +246,7 @@ export class Login7TokenHandler extends TokenHandler { declare connection: Connection; declare fedAuthInfoToken: FedAuthInfoToken | undefined; - declare routingData: { server: string, port: number } | undefined; + declare routingData: { server: string, port: number, instance: string } | undefined; declare loginAckReceived: boolean; @@ -337,10 +337,10 @@ export class Login7TokenHandler extends TokenHandler { onRoutingChange(token: RoutingEnvChangeToken) { // Removes instance name attached to the redirect url. E.g., redirect.db.net\instance1 --> redirect.db.net - const [ server ] = token.newValue.server.split('\\'); + const [ server, instance ] = token.newValue.server.split('\\'); this.routingData = { - server, port: token.newValue.port + server, port: token.newValue.port, instance }; }