Ejemplo n.º 1
0
void Check64BitPortability::pointerassignment()
{
    if (!_settings->isEnabled("portability"))
        return;

    for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
        if (Token::Match(tok, "[;{}] %var% = %var% [;+]")) {
            const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

            const Variable *var1(symbolDatabase->getVariableFromVarId(tok->next()->varId()));
            const Variable *var2(symbolDatabase->getVariableFromVarId(tok->tokAt(3)->varId()));

            if (isaddr(var1) && isint(var2) && tok->strAt(4) != "+")
                assignmentIntegerToAddressError(tok->next());

            else if (isint(var1) && isaddr(var2) && !tok->tokAt(3)->isPointerCompare()) {
                // assigning address => warning
                // some trivial addition => warning
                if (Token::Match(tok->tokAt(4), "+ %any% !!;"))
                    continue;

                assignmentAddressToIntegerError(tok->next());
            }
        }
    }
}
Ejemplo n.º 2
0
isaddr(register expptr p)
#endif
{
	if(p->tag == TADDR)
		return(YES);
	if(p->tag == TEXPR)
		switch(p->exprblock.opcode)
		{
		case OPCOMMA:
			return( isaddr(p->exprblock.rightp) );

		case OPASSIGN:
		case OPASSIGNI:
		case OPPLUSEQ:
		case OPMINUSEQ:
		case OPSLASHEQ:
		case OPMODEQ:
		case OPLSHIFTEQ:
		case OPRSHIFTEQ:
		case OPBITANDEQ:
		case OPBITXOREQ:
		case OPBITOREQ:
			return( isaddr(p->exprblock.leftp) );
		}
	return(NO);
}
Ejemplo n.º 3
0
/**
 * Return the next (non-commented) line from the host-file.
 * Format is:
 *  ip-address host-name [alias..] {\n | # ..}
 */
struct hostent * W32_CALL gethostent (void)
{
  struct _hostent h;
  char  *tok, *ip, *name, *alias;
  char   buf [2*MAX_HOSTLEN];
  int    i;

  if (!netdb_init() || !hostFile)
  {
    h_errno = NO_RECOVERY;
    return (NULL);
  }

  while (1)
  {
    if (!fgets(buf,sizeof(buf),hostFile))
       return (NULL);

    tok = strltrim (buf);
    if (*tok == '#' || *tok == ';' || *tok == '\n')
       continue;

    ip   = strtok (tok, " \t");
    name = strtok (NULL, " \t\n");
    if (ip && name && isaddr(ip))
       break;
  }

  if (hostClose)
     endhostent();

  memset (&h, 0, sizeof(h));
  if (!strcmp(ip,"0.0.0.0"))   /* inet_addr() maps 0 -> INADDR_NONE */
       h.h_address[0] = INADDR_ANY;
  else h.h_address[0] = inet_addr (ip);

  h.h_num_addr = 1;
  h.h_name = name;
  alias    = strtok (NULL, " \t\n");

  for (i = 0; alias && i < MAX_HOST_ALIASES; i++)
  {
    static char aliases [MAX_NETENT_ALIASES][MAX_HOSTLEN];

    if (*alias == '#' || *alias == ';')
       break;

    h.h_aliases[i] = StrLcpy (aliases[i], alias, sizeof(aliases[i]));
    alias = strtok (NULL, " \t\n");
  }
  return fill_hostent (&h);
}
Ejemplo n.º 4
0
/*
 * resolve()
 * 	convert domain name -> address resolution.
 * 	returns 0 if name is unresolvable right now
 */
longword resolve_fn( char *name, sockfunct_t fn )	// S. Lawson
{
    longword ipaddr;
    // S. Lawson
#define DNSCACHESIZE 4			// cache up to 4 names
#define DNSCACHELENGTH 32		//   up to 32 characters
#define DNSCACHETIMEOUT 120             //     for up to 2 minutes
    static char DNScacheName[DNSCACHESIZE][DNSCACHELENGTH];
    static longword DNScacheIP[DNSCACHESIZE];
    static longword DNScacheTimeout[DNSCACHESIZE]={0,0,0,0};
    static char DNScacheNext=0;
    int DNScacheScan;

    if( !name ) return 0L;

    rip( name );			// S. Lawson - trim for cache scan
    if ( isaddr( name ))
	 return( aton( name ));

    // S. Lawson
    for (DNScacheScan=0 ; DNScacheScan<DNSCACHESIZE ; DNScacheScan++) {
       if (DNScacheTimeout[DNScacheScan]==0L) continue;
       if (chk_timeout(DNScacheTimeout[DNScacheScan])) {
	  DNScacheTimeout[DNScacheScan]=0L;
	  continue;
       }
       if(!strcmpi(DNScacheName[DNScacheScan],name))
	  return DNScacheIP[DNScacheScan];
    }

#ifdef NOTUSED	// S. Lawson
    if( do_ns_lookup(name, DTYPEA, typea_unpacker, &ipaddr) )
       return (intel(ipaddr));
    else return (0L);
#else	// S. Lawson
    if( do_ns_lookup(name, DTYPEA, typea_unpacker, &ipaddr, fn) ) {
       strncpy(DNScacheName[DNScacheNext], name, DNSCACHELENGTH);
       DNScacheName[DNScacheNext][DNSCACHELENGTH-1]='\0';
       DNScacheIP[DNScacheNext]=intel(ipaddr);
       DNScacheTimeout[DNScacheNext]=set_timeout(DNSCACHETIMEOUT);
       if (++DNScacheNext>=DNSCACHESIZE) DNScacheNext=0;
       return (intel(ipaddr));
    }
    return (0L);
#endif	// S. Lawson
}
Ejemplo n.º 5
0
debug
void main()
{
   longword host, timer, new_rcvd;
   longword tot_timeout, itts, send_timeout;
   word i;
   word sequence_mode, is_new_line;
   word debug_on;
   static unsigned char tempbuffer[255];
   word arping;
   auto char ip[16], netmask[16];
   auto int status;

   sent=received=tot_delays=last_rcvd=0L;
   tot_timeout=itts=send_timeout=0L;
   debug_on=0;
   is_new_line=1;
   arping = 1;

	// Start network and wait for interface to come up (or error exit).
	printf("Starting/joining ad-hoc network...\n");
	sock_init_or_exit(1);

   name=PINGWHO;
   itts=0;		// 0 == continuous

   if (!(host = resolve( name ))) {
      printf("Unable to resolve '%s'\n", name );
      exit( 3 );
   }
   if ( isaddr( name ))
      printf("Pinging [%s]",inet_ntoa(tempbuffer, host));
   else
      printf("Pinging '%s' [%s]",name, inet_ntoa(tempbuffer, host));

	if (!itts)
		itts = 1000000L;

   printf(" %lu times\n", itts);




   tot_timeout = _SET_TIMEOUT((itts + 2)*1000L);

	send_timeout = _SET_TIMEOUT(0);
   do {
      /* once per second - do all this */
      if ( chk_timeout( send_timeout )) {
         send_timeout = _SET_TIMEOUT(1000L);
         if (chk_timeout( tot_timeout )) {
            stats();
            break;
         }
         if (arping) {
	         if (!_arp_resolve( host, (eth_address *)tempbuffer, 0 ))
	            printf("Could not resolve hardware address (maybe other host not up yet)\n");
	         else {
	         	arping = 0;
	            printf("Hardware address resolved to %02x:%02x:%02x:%02x:%02x:%02x\n",
	               (int)tempbuffer[0],(int)tempbuffer[1],(int)tempbuffer[2],(int)tempbuffer[3],
	               (int)tempbuffer[4],(int)tempbuffer[5]);
	         }
         }
         if (!arping && sent < itts) {
            sent++;
            if (_ping( host , sent ))
               stats();
            if (!is_new_line) printf("\n");
            printf("sent PING # %lu ", sent );
            is_new_line = 0;
         }
      }

      if ( kbhit() ) {
         getchar();    /* trash the character */
         stats();
      }

      tcp_tick(NULL);
      if (arping)
      	continue;
      if ((timer = _chk_ping( host , &new_rcvd)) != 0xffffffffL) {
         tot_delays += timer;
         ++received;
         if ( new_rcvd != last_rcvd + 1 ) {
            if (!is_new_line) printf("\n");
            printf("PING receipt received out of order!\n");
            is_new_line = 1;
         }
         last_rcvd = new_rcvd;
         if (!is_new_line) printf(", ");
         printf("PING receipt # %lu : response time %lu ms\n", received, timer);
         is_new_line = 1;
         if ( received == itts )
            stats();
      }
   } while (1);
}
Ejemplo n.º 6
0
void Check64BitPortability::pointerassignment()
{
    if (!_settings->isEnabled("portability"))
        return;

    const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();

    // Check return values
    const std::size_t functions = symbolDatabase->functionScopes.size();
    for (std::size_t i = 0; i < functions; ++i) {
        const Scope * scope = symbolDatabase->functionScopes[i];
        if (scope->function == 0 || !scope->function->hasBody) // We only look for functions with a body
            continue;

        bool retPointer = false;
        if (scope->function->token->strAt(-1) == "*") // Function returns a pointer
            retPointer = true;
        else if (Token::Match(scope->function->token->previous(), "int|long|DWORD")) // Function returns an integer
            ;
        else
            continue;

        for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
            if (Token::Match(tok, "return %var%|%num% [;+]") && !Token::simpleMatch(tok, "return 0 ;")) {
                enum { NO, INT, PTR, PTRDIFF } type = NO;
                for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
                    if ((type == NO || type == INT) && isaddr(tok2->variable()))
                        type = PTR;
                    else if (type == NO && (tok2->isNumber() || isint(tok2->variable())))
                        type = INT;
                    else if (type == PTR && Token::Match(tok2, "- %var%") && isaddr(tok2->next()->variable()))
                        type = PTRDIFF;
                    else if (Token::Match(tok2, "%type% (")) {
                        type = NO;
                        break;
                    } else if (tok2->str() == ";")
                        break;
                }

                if (retPointer && (type == INT || type == PTRDIFF))
                    returnIntegerError(tok);
                else if (!retPointer && type == PTR)
                    returnPointerError(tok);
            }
        }
    }

    // Check assignments
    for (std::size_t i = 0; i < functions; ++i) {
        const Scope * scope = symbolDatabase->functionScopes[i];
        for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
            if (Token::Match(tok, "[;{}] %var% = %var% [;+]")) {

                const Variable *var1(tok->next()->variable());
                const Variable *var2(tok->tokAt(3)->variable());

                if (isaddr(var1) && isint(var2) && tok->strAt(4) != "+")
                    assignmentIntegerToAddressError(tok->next());

                else if (isint(var1) && isaddr(var2) && !tok->tokAt(3)->isPointerCompare()) {
                    // assigning address => warning
                    // some trivial addition => warning
                    if (Token::Match(tok->tokAt(4), "+ %any% !!;"))
                        continue;

                    assignmentAddressToIntegerError(tok->next());
                }
            }
        }
    }
}
Ejemplo n.º 7
0
debug
void main()
{
   longword host, timer, new_rcvd;
   longword tot_timeout, itts, send_timeout;
   word i;
   word sequence_mode, is_new_line;
   word debug_on;
   static unsigned char tempbuffer[255];

   sent=received=tot_delays=last_rcvd=0L;
   tot_timeout=itts=send_timeout=0L;
   sequence_mode=debug_on=0;
   is_new_line=1;

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);

   name=PINGWHO;
   itts=10;

   if (!(host = resolve( name ))) {
      printf("Unable to resolve '%s'\n", name );
      exit( 3 );
   }
   if ( isaddr( name ))
      printf("Pinging [%s]",inet_ntoa(tempbuffer, host));
   else
      printf("Pinging '%s' [%s]",name, inet_ntoa(tempbuffer, host));

   if (itts) printf(" %u times", itts);
   else
      itts = sequence_mode ? 0xffffffffL : 1;

   if (sequence_mode) printf(" once per_second");
   printf("\n");


   if (!_arp_resolve( host, (eth_address *)tempbuffer, 0 )) {  /* resolve it before timer starts */
   	printf("Could not resolve hardware address\n");
   	exit(2);
   }
   tot_timeout = _SET_TIMEOUT((itts + 2)*1000L);
   if ( debug_on ) printf("ETH -> %02x:%02x:%02x:%02x:%02x:%02x\n",
      (int)tempbuffer[0],(int)tempbuffer[1],(int)tempbuffer[2],(int)tempbuffer[3],
      (int)tempbuffer[4],(int)tempbuffer[5]);

	send_timeout = _SET_TIMEOUT(0);
   do {
      /* once per second - do all this */
      if ( chk_timeout( send_timeout )) {
         send_timeout = _SET_TIMEOUT(1000L);
         if (chk_timeout( tot_timeout )) {
            stats();
            break;
         }
         if ( sent < itts ) {
            sent++;
            if (_ping( host , sent ))
               stats();
            if (!is_new_line) printf("\n");
            printf("sent PING # %lu ", sent );
            is_new_line = 0;
         }
      }

      if ( kbhit() ) {
         getchar();    /* trash the character */
         stats();
      }

      tcp_tick(NULL);
      if ((timer = _chk_ping( host , &new_rcvd)) != 0xffffffffL) {
         tot_delays += timer;
         ++received;
         if ( new_rcvd != last_rcvd + 1 ) {
            if (!is_new_line) printf("\n");
            printf("PING receipt received out of order!\n");
            is_new_line = 1;
         }
         last_rcvd = new_rcvd;
         if (!is_new_line) printf(", ");
         printf("PING receipt # %lu : response time %lu ms\n", received, timer);
         is_new_line = 1;
         if ( received == itts )
            stats();
      }
   } while (1);
}