Exemplo n.º 1
0
static void *correct_thread(void *data) {
	correct_aux_t *d = (correct_aux_t*) data;
	int i = 0;
	bwa_seq_t *s = NULL, *query = NULL, *seqs = d->ht->seqs;
	readarray *low_kmer_reads = d->low_kmer_reads;
	alignarray *aligns = NULL;

	aligns = g_ptr_array_sized_new(N_DEFAULT_ALIGNS);
	for (i = d->start; i < d->end; i++) {
		if (i % 10000 == 0)
			show_msg(__func__,
					"Thread %d correction progress: [%d,%d,%d]... \n", d->tid,
					d->start, i, d->end);
		s = g_ptr_array_index(low_kmer_reads, i);
		if (is_repetitive_q(s)) {
			s->status = USED;
			continue;
		}
		// Only the fresh reads, or the reads tried once would be corrected.
		if (s->status != FRESH)
			continue;
		query = new_seq(s, s->len - 8, 0);
		pe_aln_query(s, s->seq, d->ht, MISMATCHES, s->len, 0, aligns);
		pe_aln_query(s, s->rseq, d->ht, MISMATCHES, s->len, 1, aligns);
		if (aligns->len >= 4)
			correct_bases(seqs, s, aligns, d->tid);
		s->status = TRIED;
		reset_alg(aligns);
		bwa_free_read_seq(1, query);
		//if (i > 10000)
		//	break;
	}
	free_alg(aligns);
	show_msg(__func__, "Thread %d finished. \n", d->tid);
}
Exemplo n.º 2
0
static int recv_buffer(struct connreq *conn) {
   int rc = 0;

   show_msg(MSGDEBUG, "Reading from server (expecting %d bytes)\n", conn->datalen);
   while ((rc == 0) && (conn->datadone != conn->datalen)) {
      rc = recv(conn->sockid, conn->buffer + conn->datadone, 
                conn->datalen - conn->datadone, 0);
      if (rc > 0) {
         conn->datadone += rc;
         rc = 0;
      } else if (rc == 0) {
         show_msg(MSGDEBUG, "Peer has shutdown but we only read %d of %d bytes.\n",
            conn->datadone, conn->datalen);
         rc = ENOTCONN; /* ENOTCONN seems like the most fitting error message */
      } else {
         if (errno != EWOULDBLOCK)
            show_msg(MSGDEBUG, "Read failed, %s\n", strerror(errno));
         rc = errno;
      }
   }

   if (conn->datadone == conn->datalen)
      conn->state = conn->nextstate;

   show_msg(MSGDEBUG, "Received %d bytes of %d bytes expected, return code is %d\n",
            conn->datadone, conn->datalen, rc);
   return(rc);
}
Exemplo n.º 3
0
static int handle_path(struct parsedfile *config, int lineno, int nowords, char *words[]) {
    struct serverent *newserver;

    if ((nowords != 2) || (strcmp(words[1], "{"))) {
        show_msg(MSGERR, "Badly formed path open statement on line %d "
               "in configuration file (should look like "
               "\"path {\")\n", lineno);
    } else if (currentcontext != &(config->defaultserver)) {
        /* You cannot nest path statements so check that */
        /* the current context is defaultserver          */
        show_msg(MSGERR, "Path statements cannot be nested on line %d "
               "in configuration file\n", lineno);
    } else {
        /* Open up a new serverent, put it on the list   */
        /* then set the current context                  */
        if (((int) (newserver = (struct serverent *) malloc(sizeof(struct serverent)))) == -1)
            exit(-1);

        /* Initialize the structure */
        show_msg(MSGDEBUG, "New server structure from line %d in configuration file going "
                           "to 0x%08x\n", lineno, newserver);
        memset(newserver, 0x0, sizeof(*newserver));
        newserver->next = config->paths;
        newserver->lineno = lineno;
        config->paths = newserver;
        currentcontext = newserver;
    }
 
    return(0);
}
Exemplo n.º 4
0
/* If we are not done setting up the connection yet, return
 * -1 and ENOTCONN, otherwise call getpeername
 *
 * This is necessary since some applications, when using non-blocking connect,
 * (like ircII) use getpeername() to find out if they are connected already.
 *
 * This results in races sometimes, where the client sends data to the socket
 * before we are done with the socks connection setup.  Another solution would
 * be to intercept send().
 * 
 * This could be extended to actually set the peername to the peer the
 * client application has requested, but not for now.
 *
 * PP, Sat, 27 Mar 2004 11:30:23 +0100
 */
int getpeername(GETPEERNAME_SIGNATURE) {
   struct connreq *conn;
   int rc;

    if (realgetpeername == NULL) {
        show_msg(MSGERR, "Unresolved symbol: getpeername\n");
        return(-1);
    }

   show_msg(MSGDEBUG, "Call to getpeername for fd %d\n", __fd);


   rc = realgetpeername(__fd, __name, __namelen);
   if (rc == -1)
       return rc;

   /* Are we handling this connect? */
   if ((conn = find_socks_request(__fd, 1))) {
       /* While we are at it, we might was well try to do something useful */
       handle_request(conn);

       if (conn->state != DONE) {
           errno = ENOTCONN;
           return(-1);
       }
   }
   return rc;
}
Exemplo n.º 5
0
static int handle_type(struct parsedfile *config, int lineno, char *value) {

    if (currentcontext->type != 0) {
        if (currentcontext == &(config->defaultserver))
            show_msg(MSGERR, "Server type may only be specified "
                   "once for default server, at line %d "
                   "in configuration file\n", lineno);
        else
            show_msg(MSGERR, "Server type may only be specified "
                   "once per path on line %d in configuration "
                   "file. (Path begins on line %d)\n",
                   lineno, currentcontext->lineno);
    } else {
        errno = 0;
        currentcontext->type = (int) strtol(value, (char **)NULL, 10);
        if ((errno != 0) || (currentcontext->type == 0) ||
            ((currentcontext->type != 4) && (currentcontext->type != 5))) {
            show_msg(MSGERR, "Invalid server type (%s) "
                   "specified in configuration file "
                   "on line %d, only 4 or 5 may be "
                   "specified\n", value, lineno);
            currentcontext->type = 0;
        }
    }
    
    return(0);
}
Exemplo n.º 6
0
struct hostent * our_gethostbyname(dead_pool *pool, const char *name)
{
  int pos;
  static struct in_addr addr;
  static struct hostent he;
  static char *addrs[2];

  show_msg(MSGDEBUG, "our_gethostbyname: '%s' requested\n", name);

  pos = store_pool_entry(pool,(char *) name, &addr);
  if(pos == -1) {
      h_errno = HOST_NOT_FOUND;
      return NULL;
  }

  addrs[0] = (char *)&addr;
  addrs[1] = NULL;

  he.h_name      = pool->entries[pos].name;
  he.h_aliases   = NULL;
  he.h_length    = 4;
  he.h_addrtype  = AF_INET;
  he.h_addr_list = addrs;

  show_msg(MSGDEBUG, "our_gethostbyname: resolved '%s' to: '%s'\n", 
           name, inet_ntoa(*((struct in_addr *)he.h_addr)));

  return &he;
}
Exemplo n.º 7
0
static int parse_socks4a_resolve_response(const char *response, size_t len, uint32_t *addr_out)
{
  uint8_t status;
  uint16_t port;

  if (len < RESPONSE_LEN) {
    show_msg(MSGWARN,"Truncated socks response.\n"); 
    return -1;
  }
  if (((uint8_t)response[0])!=0) { /* version: 0 */
    show_msg(MSGWARN,"Nonzero version in socks response: bad format.\n");
    return -1;
  }
  status = (uint8_t)response[1];

  memcpy(&port, response+2, sizeof(port));
  if (port!=0) { /* port: 0 */
    show_msg(MSGWARN,"Nonzero port in socks response: bad format.\n"); 
    return -1;
  }
  if (status != 90) {
    show_msg(MSGWARN,"Bad status: socks request failed.\n"); 
    return -1;
  }

  memcpy(addr_out, response+4, sizeof(*addr_out));

  return 0;
}
Exemplo n.º 8
0
bwa_seq_t *load_reads(const char *fa_fn, uint32_t *n_seqs) {
	bwa_seq_t *seqs, *part_seqs;
	bwa_seqio_t *ks;
	int n_part_seqs = 0, n_seqs_full = 0, n_seqs_loaded = 0;
	clock_t t = clock();

	ks = bwa_open_reads(BWA_MODE, fa_fn);
	n_seqs_full = N_CHUNK_SEQS;
	show_msg(__func__, "Loading reads from library %s...\n", fa_fn);
	seqs = (bwa_seq_t*) calloc (N_DF_MAX_SEQS, sizeof(bwa_seq_t));
	while ((part_seqs = bwa_read_seq(ks, N_CHUNK_SEQS, &n_part_seqs, BWA_MODE, 0))
			!= 0) {
		show_msg(__func__, "%d sequences loaded: %.2f sec... \n",
				n_seqs_loaded + n_part_seqs, fa_fn, (float) (clock() - t) / CLOCKS_PER_SEC);
		pe_reverse_seqs(part_seqs, n_part_seqs);

		if ((n_seqs_loaded + n_part_seqs) > n_seqs_full) {
			n_seqs_full += n_part_seqs + 2;
			kroundup32(n_seqs_full);
			seqs = (bwa_seq_t*) realloc(seqs, sizeof(bwa_seq_t) * n_seqs_full);
		}
		memmove(&seqs[n_seqs_loaded], part_seqs, sizeof(bwa_seq_t) * n_part_seqs);
		free(part_seqs);
		n_seqs_loaded += n_part_seqs;
	}
	bwa_seq_close(ks);
	if (n_seqs_loaded < 1) {
		err_fatal(__func__,
				"No sequence in file %s, make sure the format is correct! \n",
				fa_fn);
	}
	*n_seqs = n_seqs_loaded;
	return seqs;
}
Exemplo n.º 9
0
static int read_socksv4_req(struct connreq *conn) {
   struct sockrep *thisrep;

   thisrep = (struct sockrep *) conn->buffer;

   if (thisrep->result != 90) {
      show_msg(MSGERR, "SOCKS V4 connect rejected:\n");
      conn->state = FAILED;
      switch(thisrep->result) {
         case 91:
            show_msg(MSGERR, "SOCKS server refused connection\n");
            return(ECONNREFUSED);
         case 92:
            show_msg(MSGERR, "SOCKS server refused connection "
                  "because of failed connect to identd "
                  "on this machine\n");
            return(ECONNREFUSED);
         case 93:
            show_msg(MSGERR, "SOCKS server refused connection "
                  "because identd and this library "
                  "reported different user-ids\n");
            return(ECONNREFUSED);
         default:
            show_msg(MSGERR, "Unknown reason\n");
            return(ECONNREFUSED);
      }
   }

   conn->state = DONE;

   return(0);
}
Exemplo n.º 10
0
static int handle_port(struct parsedfile *config, int lineno, char *value) {

    if (currentcontext->port != 0) {
        if (currentcontext == &(config->defaultserver))
            show_msg(MSGERR, "Server port may only be specified "
                   "once for default server, at line %d "
                   "in configuration file\n", lineno);
        else
            show_msg(MSGERR, "Server port may only be specified "
                   "once per path on line %d in configuration "
                   "file. (Path begins on line %d)\n",
                   lineno, currentcontext->lineno);
    } else {
        errno = 0;
        currentcontext->port = (unsigned short int)
                  (strtol(value, (char **)NULL, 10));
        if ((errno != 0) || (currentcontext->port == 0)) {
            show_msg(MSGERR, "Invalid server port number "
                   "specified in configuration file "
                   "(%s) on line %d\n", value, lineno);
            currentcontext->port = 0;
        }
    }
    
    return(0);
}
Exemplo n.º 11
0
static int connect_server(struct connreq *conn) {
   int rc;

	/* Connect this socket to the socks server */
   show_msg(MSGDEBUG, "Connecting to %s port %d\n", 
            inet_ntoa(conn->serveraddr.sin_addr), ntohs(conn->serveraddr.sin_port));
   rc = realconnect(conn->sockid, (CONNECT_SOCKARG) &(conn->serveraddr),
                    sizeof(conn->serveraddr));
   show_msg(MSGDEBUG, "Connect returned %d, errno is %d\n", rc, errno); 
	if (rc) {
      if (errno != EINPROGRESS) {
         show_msg(MSGERR, "Error %d attempting to connect to SOCKS "
                  "server (%s)\n", errno, strerror(errno));
         conn->state = FAILED;
      } else {
         show_msg(MSGDEBUG, "Connection in progress\n");
         conn->state = CONNECTING;
      }
   } else {
      show_msg(MSGDEBUG, "Socket %d connected to SOCKS server\n", conn->sockid);
      conn->state = CONNECTED;
   }

   return((rc ? errno : 0));
}
Exemplo n.º 12
0
static ssize_t client_receive_smb(struct cli_state *cli, size_t maxlen)
{
	size_t len;

	for(;;) {
		NTSTATUS status;

		set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);

		status = receive_smb_raw(cli->fd, cli->inbuf, cli->bufsize,
					cli->timeout, maxlen, &len);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(10,("client_receive_smb failed\n"));
			show_msg(cli->inbuf);

			if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
				set_smb_read_error(&cli->smb_rw_error,
						   SMB_READ_EOF);
				return -1;
			}

			if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
				set_smb_read_error(&cli->smb_rw_error,
						   SMB_READ_TIMEOUT);
				return -1;
			}

			set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
			return -1;
		}

		/*
		 * I don't believe len can be < 0 with NT_STATUS_OK
		 * returned above, but this check doesn't hurt. JRA.
		 */

		if ((ssize_t)len < 0) {
			return len;
		}

		/* Ignore session keepalive packets. */
		if(CVAL(cli->inbuf,0) != SMBkeepalive) {
			break;
		}
	}

	if (cli_encryption_on(cli)) {
		NTSTATUS status = cli_decrypt_message(cli);
		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(0, ("SMB decryption failed on incoming packet! Error %s\n",
				nt_errstr(status)));
			cli->smb_rw_error = SMB_READ_BAD_DECRYPT;
			return -1;
		}
	}

	show_msg(cli->inbuf);
	return len;
}
Exemplo n.º 13
0
static int handle_line(struct parsedfile *config, char *line, int lineno) {
	char *words[10];
	static char savedline[MAXLINE];
	int   nowords = 0, i;

	/* Save the input string */
	strncpy(savedline, line, MAXLINE - 1);
	savedline[MAXLINE - 1] = (char) 0;
	/* Tokenize the input string */
	nowords = tokenize(line, 10, words);	

	/* Set the spare slots to an empty string to simplify */
	/* processing                                         */
	for (i = nowords; i < 10; i++) 
		words[i] = "";

	if (nowords > 0) {
		/* Now this can either be a "path" block starter or */
		/* ender, otherwise it has to be a pair (<name> =   */
		/* <value>)                                         */
		if (!strcmp(words[0], "path")) {
			handle_path(config, lineno, nowords, words);
		} else if (!strcmp(words[0], "}")) {
			handle_endpath(config, lineno, nowords, words);
		} else {
			/* Has to be a pair */
			if ((nowords != 3) || (strcmp(words[1], "="))) {
				show_msg(MSGERR, "Malformed configuration pair "
					   "on line %d in configuration "
					   "file, \"%s\"\n", lineno, savedline);
			} else if (!strcmp(words[0], "reaches")) {
				handle_reaches(config, lineno, words[2]);
			} else if (!strcmp(words[0], "server")) {
				handle_server(config, lineno, words[2]);
			} else if (!strcmp(words[0], "server_port")) {
				handle_port(config, lineno, words[2]);
			} else if (!strcmp(words[0], "server_type")) {
				handle_type(config, lineno, words[2]);
			} else if (!strcmp(words[0], "default_user")) {
				handle_defuser(config, lineno, words[2]);
			} else if (!strcmp(words[0], "default_pass")) {
				handle_defpass(config, lineno, words[2]);
			} else if (!strcmp(words[0], "local")) {
				handle_local(config, lineno, words[2]);
			} else {
				show_msg(MSGERR, "Invalid pair type (%s) specified "
					   "on line %d in configuration file, "
					   "\"%s\"\n", words[0], lineno, 
					   savedline);
			}
		}
	}

	return(0);
}
Exemplo n.º 14
0
static int send_socksv5_connect(struct connreq *conn) {
#ifdef USE_TOR_DNS
   int namelen = 0;
   char *name = NULL;
#endif
   char constring[] = { 0x05,    /* Version 5 SOCKS */
                        0x01,    /* Connect request */
                        0x00,    /* Reserved        */
                        0x01 };  /* IP Version 4    */

   show_msg(MSGDEBUG, "Constructing V5 connect request\n");
   conn->datadone = 0;
   conn->state = SENDING;
   conn->nextstate = SENTV5CONNECT;
   memcpy(conn->buffer, constring, sizeof(constring)); 
   conn->datalen = sizeof(constring);

#ifdef USE_TOR_DNS
   show_msg(MSGDEBUG, "send_socksv5_connect: looking for: %s\n",
            inet_ntoa(conn->connaddr.sin_addr));

   name = get_pool_entry(pool, &(conn->connaddr.sin_addr));
   if(name != NULL) {
       namelen = strlen(name);
       if(namelen > 255) {  /* "Can't happen" */
           name = NULL;
       }
   }
   if(name != NULL) {
       show_msg(MSGDEBUG, "send_socksv5_connect: found it!\n");
       /* Substitute the domain name from the pool into the SOCKS request. */
       conn->buffer[3] = 0x03;  /* Change the ATYP field */
       conn->buffer[4] = namelen;  /* Length of name */
       conn->datalen++;
       memcpy(&conn->buffer[conn->datalen], name, namelen);
       conn->datalen += namelen;
   } else {
       show_msg(MSGDEBUG, "send_socksv5_connect: ip address not found\n");
#endif
       /* Use the raw IP address */
       memcpy(&conn->buffer[conn->datalen], &(conn->connaddr.sin_addr.s_addr), 
              sizeof(conn->connaddr.sin_addr.s_addr));
       conn->datalen += sizeof(conn->connaddr.sin_addr.s_addr);
#ifdef USE_TOR_DNS
   }
#endif
   memcpy(&conn->buffer[conn->datalen], &(conn->connaddr.sin_port), 
        sizeof(conn->connaddr.sin_port));
   conn->datalen += sizeof(conn->connaddr.sin_port);

   return(0);
}			
Exemplo n.º 15
0
static int handle_reaches(int lineno, char *value) {
    int rc;
    struct netent *ent;

    rc = make_netent(value, &ent);
    switch(rc) {
        case 1:
            show_msg(MSGERR, "Local network specification (%s) is not validly "
                   "constructed in reach statement on line "
                   "%d in configuration "
                   "file\n", value, lineno);
            return(0);
            break;
        case 2:
            show_msg(MSGERR, "IP in reach statement "
                   "network specification (%s) is not valid on line "
                   "%d in configuration file\n", value, lineno);
            return(0);
            break;
        case 3:
            show_msg(MSGERR, "SUBNET in reach statement "
                   "network specification (%s) is not valid on "
                   "line %d in configuration file\n", value,
                   lineno);
            return(0);
            break;
        case 4:
            show_msg(MSGERR, "IP (%s) & ", inet_ntoa(ent->localip));
            show_msg(MSGERR, "SUBNET (%s) != IP on line %d in "
                   "configuration file, ignored\n",
                   inet_ntoa(ent->localnet), lineno);
            return(0);
         break;
        case 5:
            show_msg(MSGERR, "Start port in reach statement "
                    "network specification (%s) is not valid on line "
                    "%d in configuration file\n", value, lineno);
            return(0);
            break;
        case 6:
            show_msg(MSGERR, "End port in reach statement "
                    "network specification (%s) is not valid on line "
                    "%d in configuration file\n", value, lineno);
            return(0);
            break;
        case 7:
            show_msg(MSGERR, "End port in reach statement "
                    "network specification (%s) is less than the start "
                    "port on line %d in configuration file\n", value, 
                    lineno);
            return(0);
            break;
    }

    /* The entry is valid so add it to linked list */
    ent -> next = currentcontext -> reachnets;
    currentcontext -> reachnets = ent;

    return(0);
}
Exemplo n.º 16
0
void STATS_ITEM::sample(double v, bool collecting_stats, double now) {
    if (value != v && log_changes) {
        char buf[256];
        switch (kind) {
        case DISK:
            sprintf(buf, "%s: %f GB -> %f GB\n", name, value/1e9, v/1e9);
            show_msg(buf);
            break;
        case NETWORK:
            sprintf(buf, "%s: %f Mbps -> %f Mbps\n", name, value/1e6, v/1e6);
            show_msg(buf);
            break;
        case FAULT_TOLERANCE:
            sprintf(buf, "%s: %.0f -> %.0f\n", name, value, v);
            show_msg(buf);
            break;
        }
    }
    double old_val = value;
    value = v;
    if (!collecting_stats) return;
    if (first) {
        first = false;
        prev_t = now;
        return;
    }
    double dt = now - prev_t;
    prev_t = now;
    integral += dt*old_val;
    switch (kind) {
    case DISK:
    case NETWORK:
        if (v > extreme_val) {
            extreme_val = v;
            extreme_val_time = now;
        }
        break;
    case FAULT_TOLERANCE:
        if (v < extreme_val) {
            extreme_val = v;
            extreme_val_time = now;
        }
        break;
    }

    fprintf(f, "%f %f\n", now, old_val);
    fprintf(f, "%f %f\n", now, v);
}
Exemplo n.º 17
0
static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf,
				 DATA_BLOB blob, NTSTATUS nt_status)
{
	char *p;

	if (!NT_STATUS_IS_OK(nt_status) && !NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
		ERROR_NT(nt_status_squash(nt_status));
	} else {
		set_message(outbuf,4,0,True);

		nt_status = nt_status_squash(nt_status);
		SIVAL(outbuf, smb_rcls, NT_STATUS_V(nt_status));
		SSVAL(outbuf, smb_vwv0, 0xFF); /* no chaining possible */
		SSVAL(outbuf, smb_vwv3, blob.length);
		p = smb_buf(outbuf);

		/* should we cap this? */
		memcpy(p, blob.data, blob.length);
		p += blob.length;

		p += add_signature( outbuf, p );

		set_message_end(outbuf,p);
	}

	show_msg(outbuf);
	return send_smb(smbd_server_fd(),outbuf);
}
Exemplo n.º 18
0
static int get_config () {
   static int done = 0;

   if (done)
      return(0);

   /* Determine the location of the config file */
#ifdef ALLOW_ENV_CONFIG
   if (!suid) 
      conffile = getenv("TSOCKS_CONF_FILE");
#endif
   
	/* Read in the config file */
   config = malloc(sizeof(*config));
   if (!config)
      return(0);
	read_config(conffile, config);
   if (config->paths)
      show_msg(MSGDEBUG, "First lineno for first path is %d\n", config->paths->lineno);

   done = 1;

	return(0);

}
Exemplo n.º 19
0
Arquivo: std.c Projeto: akaehy/Project
int main(void)
{
    FILE *fp;
    std_t *stdp = NULL;
    int choice, len;
    
    fp = fopen("student_score", "r+");
    if(fp == NULL)
        sys_err("fopen student_score");
    stdp = get_info(fp, stdp, &len);

    while(1){
        show_msg(1);
        scanf("%d", &choice);
        switch(choice){
        case 1:display(stdp, len);
                break;
        case 2:sort(stdp, len, 1);
                break;
        case 3:insert(stdp, len, fp);
               break;
        case 4:sort(stdp, len, 2);
                free(stdp);
                fclose(fp);
                return 0;
        default:fputs("Invalid choice, rechoose!\n", stdout);
                break;
        }
    }

    return 0;
}
Exemplo n.º 20
0
static int send_socksv4_request(struct connreq *conn) {
	struct passwd *user;
	struct sockreq *thisreq;
	
	/* Determine the current username */
	user = getpwuid(getuid());	

   thisreq = (struct sockreq *) conn->buffer;

   /* Check the buffer has enough space for the request  */
   /* and the user name                                  */
   conn->datalen = sizeof(struct sockreq) + 
                   (user == NULL ? 0 : strlen(user->pw_name)) + 1;
   if (sizeof(conn->buffer) < conn->datalen) {
      show_msg(MSGERR, "The SOCKS username is too long");
      conn->state = FAILED;
      return(ECONNREFUSED);
   }

	/* Create the request */
	thisreq->version = 4;
	thisreq->command = 1;
	thisreq->dstport = conn->connaddr.sin_port;
	thisreq->dstip   = conn->connaddr.sin_addr.s_addr;

	/* Copy the username */
	strcpy((char *) thisreq + sizeof(struct sockreq), 
	       (user == NULL ? "" : user->pw_name));

   conn->datadone = 0;
   conn->state = SENDING;
   conn->nextstate = SENTV4REQ;

	return(0);   
}			
Exemplo n.º 21
0
Arquivo: std.c Projeto: akaehy/Project
void display(std_t *stdp, int len)
{
    int i;
    show_msg(2);
    for(i = 0; i < len; i++){
        printf("%u\t%s\t%d\t%d\t%.2f\n", stdp[i].id, stdp[i].name, stdp[i].math, stdp[i].eng, (stdp[i].math + stdp[i].eng) / 2.0);
    }
}
Exemplo n.º 22
0
void
mc_warn (const char *s, ...)
{
  va_list argp;
  va_start (argp, s);
  show_msg ("warning", s, argp);
  va_end (argp);
}
Exemplo n.º 23
0
Arquivo: main.c Projeto: SeaPea/HomeP
// Timer event when status update operation times out
void status_change_timeout(void *data) {
  reset_inactivity_timer();
  status_change_timeout_timer = NULL;
  s_device_status_target = DSNone;
  cancel_status_check();
  show_device_status(s_device_status, s_status_changed);
  show_msg("Operation timed out", false, 5);
}
Exemplo n.º 24
0
void show() {
  char tmfmt[] = "         %2$s\n\0\0%s%s\n\0\0\0\0\0\0\0\0\0\0\0";
  time_t tim;
  struct tm* tm;
  char buf[80];

  time(&tim);
  tm = localtime(&tim);
  strftime(buf, 80, "%H:%M:%S ", tm);

  if (g_ptim != tim) {
    g_ptim = tim;
    show_msg(buf, tmfmt + 16);
  } else {
    show_msg(buf, tmfmt);
  }
}
Exemplo n.º 25
0
struct hostent *
our_gethostbyaddr(dead_pool *pool, const void *_addr, socklen_t len, int type)
{
  const struct in_addr *addr=_addr;
  static struct hostent he;
  uint32_t intaddr=0;
  char *result_hostname=NULL;
  int rc=0;
  static char *addrs[2];
  static char *aliases[2];

  rc = do_resolve("", pool->sockshost, pool->socksport, &intaddr, addr,
                  5 /*SOCKS5*/, 1 /*Reverse*/, &result_hostname);


  if(rc != 0) {
      show_msg(MSGWARN, "failed to reverse resolve: %s\n",
               inet_ntoa(*((struct in_addr *)addr)));
      result_hostname=NULL;
      addrs[0] = NULL;
      addrs[1] = NULL;
  }else{
      addrs[0] = (char *)addr;
      addrs[1] = NULL;
  }

  if (result_hostname)
    he.h_name = result_hostname;
  else
    he.h_name = inet_ntoa(*((struct in_addr *)addr));

  aliases[0] = NULL;
  aliases[1] = NULL;

  he.h_aliases = aliases;
  he.h_length    = len;
  he.h_addrtype  = type;
  he.h_addr_list = addrs;

  show_msg(MSGDEBUG, "our_gethostbyaddr: resolved '%s' to: '%s'\n",
           inet_ntoa(*((struct in_addr *)he.h_addr)), result_hostname);

  return &he;

}
Exemplo n.º 26
0
void
mc_fatal (const char *s, ...)
{
  va_list argp;
  va_start (argp, s);
  show_msg ("fatal", s, argp);
  va_end (argp);
  xexit (1);
}
Exemplo n.º 27
0
int
yyerror (const char *s, ...)
{
  va_list argp;
  va_start (argp, s);
  show_msg ("parser", s, argp);
  va_end (argp);
  return 1;
}
Exemplo n.º 28
0
static int handle_defpass(struct parsedfile *config, int lineno, char *value) {

    if (currentcontext->defpass != NULL) {
        if (currentcontext == &(config->defaultserver))
            show_msg(MSGERR, "Default password may only be specified "
                   "once for default server, at line %d "
                   "in configuration file\n", lineno);
        else
            show_msg(MSGERR, "Default password may only be specified "
                   "once per path on line %d in configuration "
                   "file. (Path begins on line %d)\n",
                   lineno, currentcontext->lineno);
    } else {
        currentcontext->defpass = strdup(value);
    }
    
    return(0);
}
Exemplo n.º 29
0
int read_config (char *filename, struct parsedfile *config) {
	FILE *conf;
	char line[MAXLINE];
	int rc = 0;
	int lineno = 1;
	struct serverent *server;

   /* Clear out the structure */
   memset(config, 0x0, sizeof(*config));

	/* Initialization */
   currentcontext = &(config->defaultserver);

	/* If a filename wasn't provided, use the default */
	if (filename == NULL) {
		strncpy(line, CONF_FILE, sizeof(line) - 1);
		/* Insure null termination */
		line[sizeof(line) - 1] = (char) 0;
		filename = line;
	}

	/* Read the configuration file */
	if ((conf = fopen(filename, "r")) == NULL) {
		show_msg(MSGERR, "Could not open socks configuration file "
			   "(%s), assuming all networks local\n", filename);
      handle_local(config, 0, "0.0.0.0/0.0.0.0");
		rc = 1; /* Severe errors reading configuration */
	}	
	else {
      memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));

		while (NULL != fgets(line, MAXLINE, conf)) {
			/* This line _SHOULD_ end in \n so we  */
			/* just chop off the \n and hand it on */
			if (strlen(line) > 0)
				line[strlen(line) - 1] = '\0';
			handle_line(config, line, lineno);
			lineno++;
		} 
		fclose(conf);

		/* Always add the 127.0.0.1/255.0.0.0 subnet to local */
		handle_local(config, 0, "127.0.0.0/255.0.0.0");

		/* Check default server */
		check_server(&(config->defaultserver));
		server = (config->paths);
		while (server != NULL) {
			check_server(server);
			server = server->next;
		}

	}

	return(rc);
}
Exemplo n.º 30
0
int main(int argc, char *argv[]) {
	const char *usage = "Usage: [-f conf file] [-t hostname/ip[:port]]"; 
	char *filename = NULL;
	char *testhost = NULL;
   struct parsedfile config;
	int i;

	if ((argc > 5) || (((argc - 1) % 2) != 0)) {
		show_msg(MSGERR, "Invalid number of arguments\n");
		show_msg(MSGERR, "%s\n", usage);
		exit(1);
	}

	for (i = 1; i < argc; i = i + 2) {
		if (!strcmp(argv[i], "-f")) {
			filename = argv[(i + 1)];
		} else if (!strcmp(argv[i], "-t")) {
			testhost = argv[(i + 1)];
		} else {
			show_msg(MSGERR, "Unknown option %s\n", argv[i]);
			show_msg(MSGERR, "%s\n", usage);
			exit(1);
		}
	}

	if (!filename) 
		filename = strdup(CONF_FILE);

	printf("Reading configuration file %s...\n", filename);
	if (read_config(filename, &config) == 0)
		printf("... Read complete\n\n");
	else 
		exit(1);

	/* If they specified a test host, test it, otherwise */
	/* dump the configuration                            */
	if (!testhost)
		show_conf(&config);
	else
		test_host(&config, testhost);
	
	return(0);  
}