[BACK]Return to telnet.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / telnet

Diff for /src/usr.bin/telnet/telnet.c between version 1.18 and 1.18.2.1

version 1.18, 2003/11/08 19:17:29 version 1.18.2.1, 2005/03/29 20:20:10
Line 446 
Line 446 
 #endif  #endif
   
             case TELOPT_XDISPLOC:       /* X Display location */              case TELOPT_XDISPLOC:       /* X Display location */
                 if (env_getvalue((unsigned char *)"DISPLAY"))                  if (env_getvalue((unsigned char *)"DISPLAY", 0))
                     new_state_ok = 1;                      new_state_ok = 1;
                 break;                  break;
   
Line 682 
Line 682 
                 resettermname = 0;                  resettermname = 0;
                 if (tnamep && tnamep != unknown)                  if (tnamep && tnamep != unknown)
                         free(tnamep);                          free(tnamep);
                 if ((tname = (char *)env_getvalue((unsigned char *)"TERM")) &&                  if ((tname = (char *)env_getvalue((unsigned char *)"TERM", 0)) &&
                                 (setupterm(tname, 1, &errret) == OK)) {                                  (setupterm(tname, 1, &errret) == OK)) {
                         tnamep = mklist(ttytype, tname);                          tnamep = mklist(ttytype, tname);
                 } else {                  } else {
Line 859 
Line 859 
             unsigned char temp[50], *dp;              unsigned char temp[50], *dp;
             int len;              int len;
   
             if ((dp = env_getvalue((unsigned char *)"DISPLAY")) == NULL) {              if ((dp = env_getvalue((unsigned char *)"DISPLAY", 0)) == NULL) {
                 /*                  /*
                  * Something happened, we no longer have a DISPLAY                   * Something happened, we no longer have a DISPLAY
                  * variable.  So, turn off the option.                   * variable.  So, turn off the option.
Line 1331 
Line 1331 
 }  }
   
   
 unsigned char slc_reply[128];  static unsigned char slc_reply[2 * SUBBUFSIZE];
 unsigned char *slc_replyp;  static unsigned char *slc_replyp;
   
           unsigned char
   slc_add(unsigned char ch)
   {
           if (slc_replyp == slc_reply + sizeof(slc_reply))
                   return ch;
           return *slc_replyp++ = ch;
   }
   
         void          void
 slc_start_reply()  slc_start_reply()
 {  {
         slc_replyp = slc_reply;          slc_replyp = slc_reply;
         *slc_replyp++ = IAC;          slc_add(IAC);
         *slc_replyp++ = SB;          slc_add(SB);
         *slc_replyp++ = TELOPT_LINEMODE;          slc_add(TELOPT_LINEMODE);
         *slc_replyp++ = LM_SLC;          slc_add(LM_SLC);
 }  }
   
         void          void
Line 1350 
Line 1358 
         unsigned char flags;          unsigned char flags;
         cc_t value;          cc_t value;
 {  {
         if ((*slc_replyp++ = func) == IAC)          if (slc_replyp + 6 >= slc_reply + sizeof(slc_reply)) {
                 *slc_replyp++ = IAC;                  printf("slc_add_reply: not enough room\n");
         if ((*slc_replyp++ = flags) == IAC)                  return;
                 *slc_replyp++ = IAC;          }
         if ((*slc_replyp++ = (unsigned char)value) == IAC)          if (slc_add(func) == IAC)
                 *slc_replyp++ = IAC;                  slc_add(IAC);
           if (slc_add(flags) == IAC)
                   slc_add(IAC);
           if (slc_add((unsigned char)value) == IAC)
                   slc_add(IAC);
 }  }
   
     void      void
Line 1363 
Line 1375 
 {  {
     int len;      int len;
   
     *slc_replyp++ = IAC;      if (slc_replyp + 2 >= slc_reply + sizeof(slc_reply)) {
     *slc_replyp++ = SE;          printf("slc_end_reply: not enough room\n");
           return;
       }
   
       slc_add(IAC);
       slc_add(SE);
     len = slc_replyp - slc_reply;      len = slc_replyp - slc_reply;
     if (len <= 6)      if (len <= 6)
         return;          return;
Line 1482 
Line 1499 
         }          }
 }  }
   
 #define OPT_REPLY_SIZE  256  #define OPT_REPLY_SIZE  (2 * SUBBUFSIZE)
 unsigned char *opt_reply;  static unsigned char *opt_reply;
 unsigned char *opt_replyp;  static unsigned char *opt_replyp;
 unsigned char *opt_replyend;  static unsigned char *opt_replyend;
   
         void          void
   opt_add(unsigned char ch)
   {
           if (opt_replyp == opt_replyend)
                   return;
           *opt_replyp++ = ch;
   }
           void
 env_opt_start()  env_opt_start()
 {  {
         unsigned char *p;          unsigned char *p;
Line 1506 
Line 1530 
         }          }
         opt_replyp = opt_reply;          opt_replyp = opt_reply;
         opt_replyend = opt_reply + OPT_REPLY_SIZE;          opt_replyend = opt_reply + OPT_REPLY_SIZE;
         *opt_replyp++ = IAC;          opt_add(IAC);
         *opt_replyp++ = SB;          opt_add(SB);
         *opt_replyp++ = telopt_environ;          opt_add(telopt_environ);
         *opt_replyp++ = TELQUAL_IS;          opt_add(TELQUAL_IS);
 }  }
   
         void          void
Line 1541 
Line 1565 
                         env_opt_add(ep);                          env_opt_add(ep);
                 return;                  return;
         }          }
         vp = env_getvalue(ep);          vp = env_getvalue(ep, 1);
         if (opt_replyp + (vp ? strlen((char *)vp) : 0) +          if (opt_replyp + 2 * (vp ? strlen((char *)vp) : 0) +
                                 strlen((char *)ep) + 6 > opt_replyend)                                  2 * strlen((char *)ep) + 6 > opt_replyend)
         {          {
                 int len;                  size_t len;
                 unsigned char *p;                  unsigned char *p;
                 opt_replyend += OPT_REPLY_SIZE;  
                 len = opt_replyend - opt_reply;                  len = opt_replyend - opt_reply;
                   len += OPT_REPLY_SIZE + 2 * strlen(ep);
                   if (vp)
                           len += 2 * strlen(vp);
                 p = (unsigned char *)realloc(opt_reply, len);                  p = (unsigned char *)realloc(opt_reply, len);
                 if (p == NULL)                  if (p == NULL) {
                         free(opt_reply);                          free(opt_reply);
                 opt_reply = p;  
                 if (opt_reply == NULL) {  
 /*@*/                   printf("env_opt_add: realloc() failed!!!\n");  /*@*/                   printf("env_opt_add: realloc() failed!!!\n");
                         opt_reply = opt_replyp = opt_replyend = NULL;                          opt_reply = opt_replyp = opt_replyend = NULL;
                         return;                          return;
                 }                  }
                 opt_replyp = opt_reply + len - (opt_replyend - opt_replyp);                  opt_replyp = p + (opt_replyp - opt_reply);
                 opt_replyend = opt_reply + len;                  opt_replyend = p + len;
                   opt_reply = p;
         }          }
         if (opt_welldefined((char *)ep))          if (opt_welldefined((char *)ep))
 #ifdef  OLD_ENVIRON  #ifdef  OLD_ENVIRON
                 if (telopt_environ == TELOPT_OLD_ENVIRON)                  if (telopt_environ == TELOPT_OLD_ENVIRON)
                         *opt_replyp++ = old_env_var;                          opt_add(old_env_var);
                 else                  else
 #endif  #endif
                         *opt_replyp++ = NEW_ENV_VAR;                          opt_add(NEW_ENV_VAR);
         else          else
                 *opt_replyp++ = ENV_USERVAR;                  opt_add(ENV_USERVAR);
   
         for (;;) {          for (;;) {
                 while ((c = *ep++)) {                  while ((c = *ep++)) {
                         switch(c&0xff) {                          switch(c&0xff) {
                         case IAC:                          case IAC:
                                 *opt_replyp++ = IAC;                                  opt_add(IAC);
                                 break;                                  break;
                         case NEW_ENV_VAR:                          case NEW_ENV_VAR:
                         case NEW_ENV_VALUE:                          case NEW_ENV_VALUE:
                         case ENV_ESC:                          case ENV_ESC:
                         case ENV_USERVAR:                          case ENV_USERVAR:
                                 *opt_replyp++ = ENV_ESC;                                  opt_add(ENV_ESC);
                                 break;                                  break;
                         }                          }
                         *opt_replyp++ = c;                          opt_add(c);
                 }                  }
                 if ((ep = vp)) {                  if ((ep = vp)) {
 #ifdef  OLD_ENVIRON  #ifdef  OLD_ENVIRON
                         if (telopt_environ == TELOPT_OLD_ENVIRON)                          if (telopt_environ == TELOPT_OLD_ENVIRON)
                                 *opt_replyp++ = old_env_value;                                  opt_add(old_env_value);
                         else                          else
 #endif  #endif
                                 *opt_replyp++ = NEW_ENV_VALUE;                                  opt_add(NEW_ENV_VALUE);
                         vp = NULL;                          vp = NULL;
                 } else                  } else
                         break;                          break;
Line 1619 
Line 1646 
   
         len = opt_replyp - opt_reply + 2;          len = opt_replyp - opt_reply + 2;
         if (emptyok || len > 6) {          if (emptyok || len > 6) {
                 *opt_replyp++ = IAC;                  opt_add(IAC);
                 *opt_replyp++ = SE;                  opt_add(SE);
                 if (NETROOM() > len) {                  if (NETROOM() > len) {
                         ring_supply_data(&netoring, opt_reply, len);                          ring_supply_data(&netoring, opt_reply, len);
                         printsub('>', &opt_reply[2], len - 2);                          printsub('>', &opt_reply[2], len - 2);
Line 2197 
Line 2224 
         send_will(TELOPT_LINEMODE, 1);          send_will(TELOPT_LINEMODE, 1);
         send_will(TELOPT_NEW_ENVIRON, 1);          send_will(TELOPT_NEW_ENVIRON, 1);
         send_do(TELOPT_STATUS, 1);          send_do(TELOPT_STATUS, 1);
         if (env_getvalue((unsigned char *)"DISPLAY"))          if (env_getvalue((unsigned char *)"DISPLAY", 0))
             send_will(TELOPT_XDISPLOC, 1);              send_will(TELOPT_XDISPLOC, 1);
         if (binary)          if (binary)
             tel_enter_binary(binary);              tel_enter_binary(binary);

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.18.2.1