Example #1
0
void main(int argc, char **argv)
{
  int i, k, quit;
	
	quit = 0;

  /* nothing has gotten through okay yet */	
  for (i = START_AT; i < STOP_AT; i++)
	{
		valid[i] = 0;
		skip[i] = 0;
	}

  skipchars(argv+1);

	terminal_save(0);
	terminal_raw(0);

  setbuf(stdout,NULL);
	
  handshake();

  /* test all the chars */
  for (i = START_AT; i < STOP_AT; i++ )
  {
		/* don't send chars we are told to skip */
    if ( skip[i] )
      continue;
		
    fprintf(stderr, "%3d sending char\n", i);

    /* attempt to send this char across, in a cute little packet */
		for (k=0; k<TRIES; k++)
		{
			if ( !skip[(int)XON] )
				printf("\n%d %c%c%c%c%c\n", i, START, (char)i, STOP, XON, END_PACKET );
			else
				printf("\n%d %c%c%c%c\n", i, START, (char)i, STOP, END_PACKET );
			
			bum(NULL);

 			/* while we're at it, take a look to the other side */
			if (!quit)
				quit = handle_incoming();
		}
	}

  bum(QUIT);

  /* let the other side finish */
	while (!quit)
		quit = handle_incoming();
	
  print_esc();
	
	terminal_restore(0);
}
Example #2
0
static void
ufo_daemon_start_impl (UfoDaemon *daemon)
{
    UfoDaemonPrivate *priv = UFO_DAEMON_GET_PRIVATE (daemon);
    g_debug ("UfoDaemon started on address %s", priv->listen_address);

    // tell the calling thread that we have started
    g_mutex_lock (priv->started_lock);
    priv->has_started = TRUE;
    g_cond_signal (priv->started_cond);
    g_mutex_unlock (priv->started_lock);

    gboolean wait_for_messages = TRUE;
    while (wait_for_messages) {
        GError *err = NULL;
        UfoMessage *msg = ufo_messenger_recv_blocking (priv->msger, &err);
        if (err != NULL) {
            /* if daemon is stopped, socket will be closed and msg_recv
            * will yield an error - we stop
            */
            wait_for_messages = FALSE;
        } else {
            // spawn a new thread that handles this request

            wait_for_messages = handle_incoming (daemon, msg);
            ufo_message_free (msg);
        }
    }

    // tell calling thread we have stopped
    g_mutex_lock (priv->stopped_lock);
    priv->has_stopped = TRUE;
    g_cond_signal (priv->stopped_cond);
    g_mutex_unlock (priv->stopped_lock);
}
Example #3
0
std::string IRC::listen() {
  std::string output(512, 0);

  if (read(sockfd, &output[0], 512-1) < 0)
    error("ERROR reading from socket");

  std::cout << output << std::endl;
  handle_incoming(output);
  return output;
}
Example #4
0
int main(int argc, char *argv[]) {
    if (argc < 2) {
        printf("expected a port number\n");
        return 0;
    }

    uint16_t port = (uint16_t) atoi(argv[1]);
    int sock = create_socket(port);

    handle_incoming(sock);

    close(sock);

    return 0;
}
Example #5
0
void snd_recv_pkt(struct sbuff *b, int ifi, unsigned int in, void *pkt)
{
  int tlen, drop = 0;
  int changed = 0;
  int dad = 0;
  struct snd_pkt_info *pi = NULL;
  enum snd_pkt_decision r;
  void *start;
  struct ip6_hdr *iph;

  start = sbuff_data(b);

  if (!snd_iface_ok(ifi)) {
    goto done; /* Luk: We need to keep packets flowing on non-SEND interfaces */
    //return;
  }

  DBG(&dbg, "%s", in ? "<<<<<<<<<<<<<<<Incoming<<<<<<<<<<<<<<<" :
      ">>>>>>>>>>>>>>>Outgoing>>>>>>>>>>>>>>>");

  if ((pi = calloc(1, sizeof (*pi))) == NULL) {
    APPLOG_NOMEM();
    goto drop;  /* For security reason we drop packet */
  }
  pi->b = b;
  pi->os_pkt = pkt; /* Needed in other threads */
  pi->ifi = ifi;

  /* Save packet start and len */
  pi->start = sbuff_data(b);
  tlen = b->len;

  if ((iph = pi->iph = sbuff_pull(b, sizeof (*(pi->iph)))) == NULL) {
    DBG(&dbg_snd, "packet too small for ipv6 header");
    /* This could be different protocol, so let something else handle it */
    goto done;
  }

  pi->icmp = sbuff_data(b);
  if (b->len < sizeof (*(pi->icmp))) {
    DBG(&dbg_snd, "packet too small for icmpv6 header");
    /* This could be different protocol, so let something else handle it */
    goto done;
  }

  DBG(&dbg_snd, "%s %s (%d) (if %d)", in ? "Incoming" : "Outgoing",
      pi->icmp->icmp6_type == ND_ROUTER_SOLICIT ? "Router Solicit" :
      pi->icmp->icmp6_type == ND_ROUTER_ADVERT ? "Router Advert" :
      pi->icmp->icmp6_type == ND_NEIGHBOR_SOLICIT ? "Neighbor Solicit" :
      pi->icmp->icmp6_type == ND_NEIGHBOR_ADVERT ? "Neighbor Advert" :
      pi->icmp->icmp6_type == ND_REDIRECT ? "Redirect" :
      "<unknown>", pi->icmp->icmp6_type, ifi);
  DBG(&dbg_snd, "src: %s",
      inet_ntop(AF_INET6, &iph->ip6_src, abuf, sizeof (abuf)));
  DBG(&dbg_snd, "dst: %s",
      inet_ntop(AF_INET6, &iph->ip6_dst, abuf, sizeof (abuf)));

  /* Do we need to secure this type? */
  switch (is_pkt_valid_nd(pi, &dad)) {
  case SND_PKT_CHECK:
    break;
  case SND_NO_PKT_CHECK:
    goto done;
  default:
  case SND_INVALID_ND:
    goto drop;
  }

  if (in) {
    if (snd_is_lcl_cga(pi->cga, ifi)) {
      DBG(&dbg, "is local; don't need to check");
      goto done;
    }

    if (snd_parse_opts(&pi->ndopts, sbuff_data(b), b->len) < 0) {
      goto drop;
    }
    b->len = tlen;
    r = handle_incoming(pi);
  } else {
    /* skip all options */
    sbuff_advance(b, b->len);
    b->len = tlen;

    if (!snd_is_lcl_cga(pi->cga, ifi)) {
      DBG(&dbg_snd, "outgoing: not CGA, dropping");
      if (dad && IN6_IS_ADDR_LINKLOCAL(pi->cga)) {
        snd_replace_this_non_cga_linklocal(pi->cga, pi->ifi);
      }
      goto drop;
    }
    r = handle_outgoing(pi);
  }

  switch (r) {
    case SND_STOLEN:
      return;
    case SND_ACCEPT_CHANGED:
      changed = 1;
      /* fallthru */
    case SND_ACCEPT_NOTCHANGED:
      goto done;
    case SND_DROP:
      break;
  }

drop:
  drop = 1;
done:
  b->data = start;
  os_specific_deliver_pkt(pkt, b, drop, changed);
  if (pi) free(pi);
}