Telnet over a socket with GCDAsyncSocket

前端 未结 1 1376
庸人自扰
庸人自扰 2021-01-18 06:29

I\'m trying to connect to a Cisco C40 codec via telnet from objective c. When using the terminal on my computer I get:

Password:

<
相关标签:
1条回答
  • 2021-01-18 07:06

    So a big problem came from the fact that the prompts (login: or password:) do no end the line with CR NL (0D:0A). And I was doing

    [self.socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];

    so I was never reading the data that held the prompt (a big problem also was that wireshark wasnt working (fixed that myself too)). Once I figured this out I changed the line above to:

    [self.socket readDataWithTimeout:-1 tag:0];
    

    Which successfully gave me my prompt. Below are the negotiations Im sending to get to this point and what the original questions entailed (same as above in the update):

    will terminal type - 0xFF, 0xFB, 0x18

    will negotiate about window size - 0xFF, 0xFB, 0x1F

    wont terminal speed - 0xFF, 0xFC, 0x20

    wont X display location - 0xFF, 0xFC, 0x23

    will new environment option - 0xFF, 0xFB, 0x27

    Suboptions

     negotiate about window size - 0xFF, 0xFA, 0x1F, 0x00, 0x50, 0x00, 0x19
     end - 0xFF, 0xF0
    
     new enviroment option - 0xFF,0xFA, 0x27, 0x00, 
     end - 0xFF, 0xF0
    
     Terminal Type (ANSI) -  0xFF,0xFA, 0x18, 0x00, 0x41, 0x4E, 0x53, 0x49, 
     end - 0xFF, 0xF0
    

    do suppress go ahead - 0xFF, 0xFD, 0x03

    will echo - 0xFF, 0xFB, 0x01

    dont status - 0xFF, 0xFE, 0x05

    wont remote flow control - 0xFF,0xFC, 0x21

    wont echo - 0xFF, 0xFC, 0x01

    Do echo - 0xFF,0xFD, 0x01

    This might also help. It removes the negotiation bytes from the stream so when your encoding to make the string it doesnt include negotiation bytes.

    while([[self.networkBuffer objectAtIndex:0]isEqualToString:@"FF"])
        {
            if ([[self.networkBuffer objectAtIndex:1]isEqualToString:@"FD"] || [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FB"] || [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FE"] || [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FA"]) {
    
                //most negotiation options are 3 bytes long
                int indexToRemoveFromBuffer = 3;
    
                //if FA then they are longer then 3 bytes
                if ([[self.networkBuffer objectAtIndex:1]isEqualToString:@"FA"]) {
                    //look for indicator of END (F0)
                    indexToRemoveFromBuffer = [self.networkBuffer indexOfObject:@"F0"]+1;
    
                }
    
                //remove these bytes from networkbuffer
                self.networkBuffer = [NSMutableArray arrayWithArray:[self.networkBuffer subarrayWithRange:NSMakeRange(indexToRemoveFromBuffer, [self.networkBuffer count]-indexToRemoveFromBuffer)]];
    
                if ([self.networkBuffer count] == 0) {
                    if (self.isLoggedIn) {
                        [self.socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];//CRLFData
                    }else{
                        [self.socket readDataWithTimeout:-1 tag:0];
                    }
                    return;
                }
            }else{
                break;
            }
    }
    
    0 讨论(0)
提交回复
热议问题