Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:56:28+00:00 2026-06-15T02:56:28+00:00

I’m trying to connect to a Cisco C40 codec via telnet from objective c.

  • 0

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:

However when doing a socket connection there are telnet negotiations that need to be made. Which I am but for some reason I cannot get to the “Password:” prompt above.

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
    NSLog(@"RECEIVE BUFFER %@",data);

    //store read bytes to rawData
    self.rawData = [[NSMutableData alloc] initWithData:data];

    //cast bytes
    const uint8_t *bytes = [self.rawData bytes];

    //go through rawdata format and save it to networkbuffer
    for (int i =0; i < [self.rawData length]; i++)
    {
        if (![[NSString stringWithFormat:@"%02X", bytes[i]]isEqual:@"0D"])
        {
            [self.networkBuffer addObject:[NSString stringWithFormat:@"%02X", bytes[i]]];
        }
    }

    //negotiate any telnet protocal stuff (just accept options )
    //example:
    //FF:FD:18 returns FF:FB:18
    while([[self.networkBuffer objectAtIndex:0]isEqualToString:@"FF"] && [[self.networkBuffer objectAtIndex:1]isEqualToString:@"FD"] ) {
//        NSLog(@"HERE");

        NSData * tempData =[data subdataWithRange:NSMakeRange(0, 3)];

        NSMutableData * tempMutData = [NSMutableData dataWithData:tempData];

        const unsigned char replacement[] = {
                0xFC
            };

        [tempMutData replaceBytesInRange:NSMakeRange(1, 1) withBytes:replacement];

        [self sendCommand:tempMutData];

        data = [data subdataWithRange:NSMakeRange(3, [data length]-3)];

        self.networkBuffer = [NSMutableArray arrayWithArray:[self.networkBuffer subarrayWithRange:NSMakeRange(3, [self.networkBuffer count]-3)]];

//        NSLog(@"network buffer after removal: %@", data);

        if ([self.networkBuffer count]<3) {
            [self.networkBuffer insertObject:@" " atIndex:0];
        }
    }

    //decode from bytes to text
    for ( NSString * component in self.networkBuffer)
    {
        int value = 0;
        sscanf([component cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
        [self.dataString appendFormat:@"%c", (char)value];
        NSLog(@"data byte: %c",(char)value);
    }
    [self telnetResponse:self.dataString];

    [self.networkBuffer removeAllObjects];
    [self.socket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:-1 tag:0];//CRLFData
}

Here is a breakdown of the telnet negotiation options Im receiving and sending:

server sending me:

FF,FD,18 (0x18 = 24dec) (Do terminal type)

FF,FD,20 (0x20 = 32dec) (Do terminal speed)

FF,FD,23 (0x23 = 35dec) (Do X Display Location)

FF,FD,27 (0x27 = 39dec) (Do New Environment Option)

My attempt at a response that doesnt work (no prompt for further input):

FF,FC,18 (0x18 = 24dec) (Wont terminal type)

FF,FC,20 (0x20 = 32dec) (Wont terminal speed)

FF,FC,23 (0x23 = 35dec) (Wont X Display Location)

FF,FC,27 (0x27 = 39dec) (Wont New Environment Option)

If you look at the code you will see that I am checking for FF and if so responding with similar bytes (replacing FD with FC), in hopes that wont accept the options but that does not seem to be working.

Links that helped me:

https://stackoverflow.com/a/2913991/530933

Telnet IAC commands (NSStream socket)

http://www.iprodeveloper.com/forums/aft/52910

UPDATE

I did a wireshark with a command shell and the cisco codec. After which I duplicated those negotiation setting/packets. Now the only problem is that Im only getting the echo. So i will get nothing, send a command, then get back a prompt plus my text. (Example. get nothing – send username “admin” – get back “login: admin”) Hence what I mean by only getting the echo. I should get a prompt “login:” then send “admin” then it should prompt me for the password.

here are the negotiation options Im sending on connect:

//will terminal type
    //will negotiate about window size
    const unsigned char nineteen[] = {
        0xFF, 0xFB, 0x18, 0xFF, 0xFB, 0x1F
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:nineteen length:sizeof(nineteen)];
    [self sendCommand:self.dataToBeSent];

    //wont terminal speed
    //wont X display location
    //will new environment option
    const unsigned char twenty[] = {
        0xFF, 0xFC, 0x20, 0xFF, 0xFC, 0x23, 0xFF, 0xFB, 0x27
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twenty length:sizeof(twenty)];
    [self sendCommand:self.dataToBeSent];

    //Suboption being: negotiate about window size
    //end
    const unsigned char twentyOne[] = {
        //0xFF,0xFC, 0x18
        0xFF, 0xFA, 0x1F, 0x00, 0x50, 0x00, 0x19, 0xFF, 0xF0
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentyOne length:sizeof(twentyOne)];
    [self sendCommand:self.dataToBeSent];

    //new enviroment option
    //end
    const unsigned char twentyThree[] = {
        0xFF,0xFA, 0x27, 0x00, 0xFF, 0xF0
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentyThree length:sizeof(twentyThree)];
    [self sendCommand:self.dataToBeSent];

    //Terminal Type (ANSI)
    //end
    const unsigned char twentySeven[] = {
        0xFF,0xFA, 0x18, 0x00, 0x41, 0x4E, 0x53, 0x49, 0xFF, 0xF0
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentySeven length:sizeof(twentySeven)];
    [self sendCommand:self.dataToBeSent];

    //do suppress go ahead
    const unsigned char twentyEight[] = {
        0xFF, 0xFD, 0x03
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentyEight length:sizeof(twentyEight)];
    [self sendCommand:self.dataToBeSent];

    //will echo
    //dont status
    //wont remote flow control
    const unsigned char twentyFour[] = {
        0xFF, 0xFB, 0x01, 0xFF, 0xFE, 0x05, 0xFF,0xFC, 0x21
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentyFour length:sizeof(twentyFour)];
    [self sendCommand:self.dataToBeSent];

    //wont echo
    const unsigned char twentyFive[] = {
        0xFF, 0xFC, 0x01
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentyFive length:sizeof(twentyFive)];
    [self sendCommand:self.dataToBeSent];

    //Do echo
    const unsigned char twentySix[] = {
        0xFF,0xFD, 0x01
    };
    self.dataToBeSent = [[NSData alloc]initWithBytes:twentySix length:sizeof(twentySix)];
    [self sendCommand:self.dataToBeSent];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:56:32+00:00Added an answer on June 15, 2026 at 2:56 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.