Example #1
0
WSLUA_METAMETHOD Address__tostring(lua_State* L) {
    Address addr = checkAddress(L,1);

    lua_pushstring(L,get_addr_name(addr));

    WSLUA_RETURN(1); /* The string representing the address. */
}
Example #2
0
/*
* Write a header to the current output file.
* The header consists of an identifying string, followed
* by a binary structure.
*/
void rtp_write_header(rtp_stream_info_t *strinfo, FILE *file)
{
	guint32 start_sec;     /* start of recording (GMT) (seconds) */
	guint32 start_usec;    /* start of recording (GMT) (microseconds)*/
	guint32 source;        /* network source (multicast address) */
	size_t sourcelen;
	guint16 port;          /* UDP port */
	guint16 padding;       /* 2 padding bytes */

	fprintf(file, "#!rtpplay%s %s/%u\n", RTPFILE_VERSION,
		get_addr_name(&(strinfo->dest_addr)),
		strinfo->dest_port);

	start_sec = g_htonl(strinfo->start_sec);
	start_usec = g_htonl(strinfo->start_usec);
	/* rtpdump only accepts guint32 as source, will be fake for IPv6 */
	memset(&source, 0, sizeof source);
	sourcelen = strinfo->src_addr.len;
	if (sourcelen > sizeof source)
		sourcelen = sizeof source;
	memcpy(&source, strinfo->src_addr.data, sourcelen);
	port = g_htons(strinfo->src_port);
	padding = 0;

	if (fwrite(&start_sec, 4, 1, file) == 0)
		return;
	if (fwrite(&start_usec, 4, 1, file) == 0)
		return;
	if (fwrite(&source, 4, 1, file) == 0)
		return;
	if (fwrite(&port, 2, 1, file) == 0)
		return;
	if (fwrite(&padding, 2, 1, file) == 0)
		return;
}
Example #3
0
void SequenceDialog::fillDiagram()
{
    QCustomPlot *sp = ui->sequencePlot;
    seq_analysis_info_t new_sa;

    new_sa = seq_analysis_;
    new_sa.list = NULL;
    new_sa.ht = NULL;
    new_sa.num_nodes = 0;
    sequence_analysis_list_get(cap_file_, &new_sa);
    num_items_ = sequence_analysis_get_nodes(&new_sa);
    seq_diagram_->setData(&new_sa);
    sequence_analysis_list_free(&seq_analysis_);
    seq_analysis_ = new_sa;

    QFontMetrics vfm = QFontMetrics(sp->xAxis2->labelFont());
    node_label_w_ = 0;
    for (guint i = 0; i < seq_analysis_.num_nodes; i++) {
        int label_w = vfm.width(get_addr_name(&(seq_analysis_.nodes[i])));
        if (node_label_w_ < label_w) {
            node_label_w_ = label_w;
        }
    }
    node_label_w_ = (node_label_w_ * 3 / 4) + one_em_;

    mouseMoved(NULL);
    resetAxes();

    // XXX QCustomPlot doesn't seem to draw any sort of focus indicator.
    sp->setFocus();
}
Example #4
0
static void handle_datagram(int fd, short what, void *arg) {
  struct sockaddr_in addr;
  socklen_t addrlen = sizeof(addr);
  char msgbuf[DGRAM_MSGBUF_LEN];
  int msglen;
  char newname[1024];

  if ((msglen = recvfrom(fd, msgbuf, DGRAM_MSGBUF_LEN, 0,
			 (struct sockaddr *) &addr, &addrlen)) >= 0) {
    unsigned short newport = ntohs(addr.sin_port);
    get_addr_name(newname, (unsigned char *) &addr.sin_addr.s_addr);

    log_fmt("UDP: %s:%d sent %d bytes:\n", newname, newport, msglen);
    dump_buffer_to_stdout(msgbuf, msglen, cfg.hexmode);
    fflush(stdout);

    if (cfg.echo_udp) {
      if (sendto(fd, msgbuf, msglen, 0, (struct sockaddr *) &addr, addrlen) == -1)
	log_fmt("UDP: echo failed, errno = %d\n", errno);
      else
	log_fmt("UDP: echo succeeded\n");
    }

    if (cfg.have_otherhost) {
      struct sockaddr_in oa;

      setup_other_sockaddr(&oa);

      if (sendto(fd, msgbuf, msglen, 0, (struct sockaddr *) &oa, sizeof(oa)) == -1)
	log_fmt("UDP: pass through failed, errno = %d\n", errno);
      else
	log_fmt("UDP: pass through succeeded\n");
    }
  }
}
Example #5
0
static void accept_connection(int fd, short what, void *arg) {
  struct sockaddr_in addr;
  socklen_t addrlen = sizeof(addr);
  int newfd = accept(fd, (struct sockaddr *) &addr, &addrlen);
  Connection *conn;

  if (newfd < 0)
    return;

  conn = calloc(sizeof(Connection), 1);

  conn->txfer_buf = newbuf(4096);
  conn->collecting_from = -1;
  conn->last_read_time = 0;

  conn->name[0] = malloc(1024);
  conn->fd[0] = newfd;
  get_addr_name(conn->name[0], (unsigned char *) &addr.sin_addr.s_addr);
  event_set(&conn->read_event[0], conn->fd[0], EV_READ | EV_PERSIST,
	    (event_handler_t) handle_data0, conn);

  conn->name[1] = cfg.otherhostname;
  conn->fd[1] = open_otherhost();
  event_set(&conn->read_event[1], conn->fd[1], EV_READ | EV_PERSIST,
	    (event_handler_t) handle_data1, conn);

  log_fmt("connection accepted on I fd %d from %s to O fd %d\n",
	  newfd, conn->name[0], conn->fd[1]);

  event_add(&conn->read_event[0], &cfg.timeout);
  event_add(&conn->read_event[1], &cfg.timeout);
}
Example #6
0
static int parse_cmdline(int argc, char *argv[]) {
  int show_help = 0;
  int have_opt_o = 0;

  while (1) {
    switch (getopt(argc, argv, "uEtbxp:o:h:f:")) {
      case 'u':
	cfg.pass_udp = 1;
	continue;

      case 'E':
	cfg.echo_udp = 1;
	continue;

      case 't':
	cfg.pass_tcp = 1;
	continue;

      case 'b':
	cfg.hexmode = 0;
	continue;

      case 'x':
	cfg.hexmode = 1;
	continue;

      case 'p':
	cfg.portnumber = atoi(optarg);
	continue;

      case 'o':
	cfg.otherport = atoi(optarg);
	have_opt_o = 1;
	cfg.have_otherhost = 1;
	continue;

      case 'h': {
	struct hostent *h = gethostbyname(optarg);

	if (h == NULL) {
	  fprintf(stderr, "Host not found. Bailing out.\n");
	  break;
	}

	memcpy(cfg.otherhostaddr, h->h_addr_list[0], sizeof(cfg.otherhostaddr));
	cfg.have_otherhost = 1;
	continue;
      }

      case 'f': {
	double seconds;
	seconds = strtod(optarg, NULL);
	cfg.timeout.tv_sec = (long) seconds;
	cfg.timeout.tv_usec = (long) ((seconds - cfg.timeout.tv_sec) * 1000000.0) % 1000000;
	continue;
      }

      case EOF:
	break;

      default:
	show_help = 1;
	break;
    }

    break;
  }

  if (!have_opt_o)
    cfg.otherport = cfg.portnumber;

  if (cfg.have_otherhost)
    get_addr_name(cfg.otherhostname, cfg.otherhostaddr);

  if (show_help || (!cfg.pass_udp && !cfg.pass_tcp)) {
    fprintf(stderr,
	    "Usage: passthru [-uEtbx] [-p portnumber] [-o destportnumber] [-h host_impersonated] [-f seconds]\n"
	    "\t-u\tPass UDP traffic through\n"
	    "\t-E\tEcho UDP traffic back to sender\n"
	    "\t-t\tPass TCP traffic through\n"
	    "\t-b\tDump results in binary format\n"
	    "\t-x\tDump results in hex format (default)\n"
	    "\t-p\tSpecify the port of TCP and/or UDP traffic to pass\n"
	    "\t-o\tSpecify the port to connect to at the destination\n"
	    "\t-h\tSpecify the host to pass through to\n"
	    "\t-f\tEnable and specify buffer flush interval in seconds\n"
	    "\tYou must select either -u or -t (or both).\n"
	    );
    return 0;
  }

  dump_configuration_settings();
  return 1;
}