Client Identification problem:-(

Posted by Baron on Sun 25 Sep 2005 12:04 AM — 2 posts, 14,325 views.

#0
Below is some mxp and client ident code that I am trying to get to work. The mxp code works fine, but when a client that can id iteself logs in, i never get its name. I can not figure out why it isnt entering the

if((*(t->buf+i+2))==(char)TERMINAL_TYPE) if. When I use a client which does not identify itself, the code works perfectly-I think anyways. However, the clients that do seem to stop at this if..

Is there any possible way you can take a moment and glance at this. Please do not laugh too hard, Im pretty new at this and have been stuck on this for over a week already.

Thanks in advance for any help or advice offered




if((*(t->buf+i))==(char)IAC)
{
if((*(t->buf+i+1))==(char)DO)
{
if((*(t->buf+i+2))==(char)TELOPT_MXP)
{
init_mxp(t);
i += 2;
}
if((*(t->buf+i+2))==(char)TERMINAL_TYPE)
{
write_to_descriptor(t->descriptor,req_ttype_str);
i += 2;
}
}
else
{
if((*(t->buf+i+1))==(char)DONT)
{
if((*(t->buf+i+2))==(char)TELOPT_MXP)
{
shutdown_mxp(t);
i += 2;
}
if((*(t->buf+i+2))==(char)TERMINAL_TYPE)
{
if (t->client)
{
free(t->client);
}
t->client=strdup("Wintin.Net");
i += 2;
}

}
}
else
{
if((*(t->buf+i+1))==(char)SB)
{
if((*(t->buf+i+2))==(char)TERMINAL_TYPE)
{
if((*(t->buf+i+3))==(char)IS)
{
sprintf(tempbuf,"%s",t->buf+4);
tempbuf[strlen(tempbuf)-2]=0;
if(t->client)
{
free(t->client);
}
t->client=strdup(tempbuf);
i+=(4+strlen(tempbuf));
}
}
}
}
}
}



NEW_DESCR

#ifdef MXP
/* telnet negotiation to see if they support MXP */
SEND_TO_Q(mxp_do, newd);
SEND_TO_Q(do_ttype_str, newd );
#endif


INIT_DESC
#ifdef MXP
newd->mxp = 0;
newd->client=strdup("Unknown");
#endif

DESCRIPT_DATA
#ifdef MXP
bool mxp;
char *client;
#endif



/* telnet negotiating */
char mxp_will [] = { IAC, WILL, TELOPT_MXP, '\0' };
char mxp_do [] = { IAC, DO, TELOPT_MXP, '\0' };
char mxp_dont [] = { IAC, DONT, TELOPT_MXP, '\0' };
char will_ttype_str [] = { IAC, WILL, TERMINAL_TYPE, '\0' };
char wont_ttype_str [] = { IAC, WONT, TERMINAL_TYPE, '\0' };
char do_ttype_str [] = { IAC, DO, TERMINAL_TYPE, '\0' };
char dont_ttype_str [] = { IAC, DONT, TERMINAL_TYPE, '\0' };
char term_call_back_str [] = { IAC, SB, TERMINAL_TYPE, IS };
char req_ttype_str [] = { IAC, SB, TERMINAL_TYPE, SEND, IAC, SE, '\0' };


#ifdef MXP
/* MXP defs */
#define MXP_SAFE 1
#define MXP_ALL 2
#define MXP_NONE 3
#define TELOPT_MXP 91
#define IS '\x00'
#define TERMINAL_TYPE '\x18'
#define SEND '\x01'
#define SE '\xF0'


#define DO 253 /* please, you use option */
#define IAC 255
#define WONT 252
#define WILL 251
#define TELOPT_ECHO 1
#define SB 250 /* interpret as subnegotiation */
#define DONT 254 /* Stop using that option */


/* global strings */
extern char mxp_do[];
extern char mxp_dont[];
extern char mxp_will[];
extern char will_ttype_str [];
extern char wont_ttype_str [];
extern char do_ttype_str [];
extern char dont_ttype_str [];
extern char req_ttype_str [];
extern char term_call_back_str [];
Canada #1
If you can enclose the above code in the code tags, it will keep the formatting and make it easier to read.

With formatting it looks like this:
	if((*(t->buf+i))==(char)IAC)
	{
		if((*(t->buf+i+1))==(char)DO)
		{
			if((*(t->buf+i+2))==(char)TELOPT_MXP)
			{
				init_mxp(t);
				i += 2;
			}

			if((*(t->buf+i+2))==(char)TERMINAL_TYPE)
			{
				write_to_descriptor(t->descriptor,req_ttype_str);
				i += 2;
			}
		}
		else
		{
			if((*(t->buf+i+1))==(char)DONT)
			{
				if((*(t->buf+i+2))==(char)TELOPT_MXP)
				{
					shutdown_mxp(t);
					i += 2;
				}
				if((*(t->buf+i+2))==(char)TERMINAL_TYPE)
				{
					if (t->client)
					{
						free(t->client);
					}
					t->client=strdup("Wintin.Net");
					i += 2;
				}
			}	
		}
		else
		{
			if((*(t->buf+i+1))==(char)SB)
			{
				if((*(t->buf+i+2))==(char)TERMINAL_TYPE)
				{
					if((*(t->buf+i+3))==(char)IS)
					{
						sprintf(tempbuf,"%s",t->buf+4);
						tempbuf[strlen(tempbuf)-2]=0;
						if(t->client)
						{
							free(t->client);
						}
						t->client=strdup(tempbuf);
						i+=(4+strlen(tempbuf));
					}
				}
			}	
		}
	}
}


Looking at this, I see a few things right away: you have to else statements to 1 if statement, as I have bolded above.
In the sequence of checks will never get to the second else statement. I am suprised that your compiler didn't complain about it.

I don't know which check your refering to, as the one you quoted is in several places. Which one is it catching on?

I also notice that there is an extra closing brace at the bottom, not sure if this means there is a missing open brace, or if you just copied on line to far.