示例#1
0
文件: miro_client.cpp 项目: karhu/sol
void ClientConnection::send_action_data()
{
    socket().send((void*)m_send_buffer.ptr_data(),m_send_buffer.size_data(),[this](error_ref e) {
        if (check_error(e)) {
            // std::cout << "<C><sent " << m_send_buffer.size_data() << " bytes of action data>" << std::endl;
            handle_outgoing();
        }
    });
}
示例#2
0
文件: miro_client.cpp 项目: karhu/sol
void ClientConnection::handle_handshake()
{
    auto& alias = m_session.m_user_info.user_alias;

    m_send_header = MessageHeader();
    m_send_header.flag = MessageHeader::Flag::handshake;
    m_send_header.len1 = alias.length() + 1;

    socket().send(buffer(m_send_header),[this](error_ref e) {
        if (check_error(e)) {
            auto& alias = m_session.m_user_info.user_alias;
            socket().send((void*)alias.data(),alias.length()+1,[this](error_ref e) {
                if (check_error(e)) {
                    handle_outgoing();
                    handle_incomming();
                }
            });
        }
    });
}
示例#3
0
文件: proto.c 项目: LucasBe/sendd
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);
}
示例#4
0
文件: miro_client.cpp 项目: karhu/sol
void ClientConnection::notify_send_data_available()
{
    if (!m_send_active) handle_outgoing();
}