Пример #1
0
Файл: ipc.c Проект: Dany3R9/Proj
int
ipc_eval_route_packet(struct routemsg *msg)
{
  struct route_entry rt_ent;
  char dev[5];
  char gw[16];
  char itoa_buf[10];
  dev[4] = '\0';
  memset(&gw[0], 0, 16);

  printf("Processing route packet\n");

  memset(rt_ent.if_name, 0, MAX_IF_NAMESIZ);

  /* Fill struct */

  memcpy(&rt_ent.gw, &msg->gateway_addr, ipsize);
  memcpy(&rt_ent.dst, &msg->target_addr, ipsize);
  memcpy(rt_ent.if_name, msg->device, 4);
  rt_ent.hopcnt = msg->metric;

  if (msg->add) {
    memcpy(&dev[0], &msg->device[0], 4);

    /*Add node to node list */
    memcpy(&gw[0], ip_to_string(&msg->gateway_addr), 16);

    gui_itoa(msg->metric, itoa_buf);

    route_list_add(ip_to_string(&msg->target_addr), gw, dev, itoa_buf);

    printf("\tRoute to %s(hc %d) added\n", ip_to_string(&msg->target_addr), rt_ent.hopcnt);

    /*
       printf("\tRoute to %s added\n", ip_to_string(&msg->target_addr));
       printf("\tGateway %s\n", gw);
       printf("\tInterface %s\n", msg->device);
       printf("\tMetric %d\n", msg->metric);
     */
  } else {

    if (route_list_del(ip_to_string(&msg->target_addr)) < 1)
      printf("COULD NOT FIND ROUTE TO DELETE!\n\n");

    printf("\tRoute to %s deleted\n", ip_to_string(&msg->target_addr));
  }
  return 1;
}
Пример #2
0
Файл: ipc.c Проект: Dany3R9/Proj
int
ipc_evaluate_message(union olsr_message *olsr_in)
{
  int ipc_pack = 0;
  olsr_u8_t type;
  int msgsize;
  char itoa_buf[10];
  olsr_u8_t vtime;
  union olsr_ip_addr *originator;

  /* Find size, vtime, originator and type - same for IPv4 and 6 */
  type = olsr_in->v4.olsr_msgtype;
  msgsize = ntohs(olsr_in->v4.olsr_msgsize);
  vtime = olsr_in->v4.olsr_vtime;
  originator = (union olsr_ip_addr *)&olsr_in->v4.originator;

  gui_itoa(msgsize, itoa_buf);

  switch (type) {
  case HELLO_MESSAGE:
    //printf("Received HELLO packet\n");
    if (!freeze_packets)
      packet_list_add("HELLO", ip_to_string(originator), itoa_buf);

    if (ipversion == AF_INET) {
      process_hello(msgsize, vtime, originator, (union hello_message *)&olsr_in->v4.message.hello);
    } else {
      process_hello(msgsize, vtime, originator, (union hello_message *)&olsr_in->v6.message.hello);
    }
    break;

  case TC_MESSAGE:
    if (!freeze_packets)
      packet_list_add("TC", ip_to_string(originator), itoa_buf);

    if (ipversion == AF_INET) {
      process_tc(msgsize, vtime, originator, (union tc_message *)&olsr_in->v4.message.tc);
      //printf("Received TC packet from %s\n", ip_to_string(&m->olsr_tc->tc_origaddr));
    } else {
      process_tc(msgsize, vtime, originator, (union tc_message *)&olsr_in->v6.message.tc);
      //printf("Received TC packet from %s\n", ip_to_string(&m->olsr_tc->tc_origaddr));
    }
    break;

  case MID_MESSAGE:
    if (!freeze_packets)
      packet_list_add("MID", ip_to_string(originator), itoa_buf);
    if (ipversion == AF_INET) {
      process_mid(msgsize, vtime, originator, (union mid_message *)&olsr_in->v4.message.mid);
      //printf("Received MID packet from %s\n", ip_to_string(&m->olsr_mid->mid_origaddr));
    } else {
      process_mid(msgsize, vtime, originator, (union mid_message *)&olsr_in->v6.message.mid);
      //printf("Received MID packet from %s\n", ip_to_string(&m->olsr_mid->mid_origaddr));
    }

    break;

  case HNA_MESSAGE:

    if (!freeze_packets)
      packet_list_add("HNA", ip_to_string(originator), itoa_buf);
    if (ipversion == AF_INET) {
      process_hna(msgsize, vtime, originator, (union hna_message *)&olsr_in->v4.message.hna);
      //printf("Received HNA packet\n");
    } else {
      process_hna(msgsize, vtime, originator, (union hna_message *)&olsr_in->v6.message.hna);
      //printf("Received HNA packet\n");
    }

    break;

  case IPC_MESSAGE:
    //printf("Received IPC packet\n");
    ipc_pack = 1;               /* Don't add to buffer */
    ipc_eval_route_packet((struct routemsg *)olsr_in);
    break;
  case IPC_NET:
    //printf("Received IPC packet\n");
    ipc_pack = 1;               /* Don't add to buffer */
    ipc_eval_net_info((struct netmsg *)olsr_in);
    break;
  default:
    if (!freeze_packets) {
      char unk_label[8];
      sprintf(unk_label, "%d", type);
      packet_list_add(unk_label, ip_to_string(originator), itoa_buf);
    }
    printf("Unknown packet type %d\n", type);
    break;
  }

  if (!freeze_packets && !ipc_pack) {
    add_packet_to_buffer(olsr_in, msgsize);
  }

  return 1;
}
Пример #3
0
/*
 *If the node passed as a parameter exists then
 *update it. If not add it to the list
 */
void
update_nodes_list(struct node *node)
{
  int i = 0;
  char *ip;
  int found = 0;
  char *dest;
  char *tmp[9] = { (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", (char *)"", (char *)"" };
  char timer[20];
  struct tm *time_st;
  char itoa_buf[10];

  if (memcmp(&node->addr, &main_addr, ipsize) == 0)
    dest = (char *)"local";
  else
    dest = ip_to_string(&node->addr);

  gtk_clist_freeze(GTK_CLIST(node_list));

  while ((i < node_list_size) && !found) {
    gtk_clist_get_text(GTK_CLIST(node_list), i, 0, (gchar **) & ip);
    if (strcmp(dest, ip) == 0)
      found = 1;
    i++;
  }

  /* Update node */
  if (found) {
    i--;                        /* Go backt to the right row */
    //printf("Updating %s\n\n", ip_to_string(&node->addr));
    /* don't update main addr */
    /* Gateway */
    if (memcmp(&node->addr, &main_addr, ipsize) != 0) {
      if (memcmp(&node->gw_addr, &null_addr, ipsize) != 0)
        gtk_clist_set_text(GTK_CLIST(node_list), i, 1, ip_to_string(&node->gw_addr));
      /* Weigth */
      if (node->hopcount != 0) {
        gui_itoa(node->hopcount, itoa_buf);
        gtk_clist_set_text(GTK_CLIST(node_list), i, 2, itoa_buf);
      }
      /* Device */
      gtk_clist_set_text(GTK_CLIST(node_list), i, 3, &node->dev[0]);
    }

    /* Timer */
    if (node->timer.tv_usec) {
      memset(&timer[0], 0, 20);
      time_st = localtime((time_t *) & node->timer.tv_sec);
      sprintf(&timer[0], "%02d:%02d:%02d", time_st->tm_hour, time_st->tm_min, time_st->tm_sec);
      gtk_clist_set_text(GTK_CLIST(node_list), i, 4, &timer[0]);
    }

    /* MID */
    if (node->mid.next != &node->mid)
      gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "yes");
    else
      gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "no");
    /* HNA */
    if (node->hna.next != &node->hna)
      gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "yes");
    else
      gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "no");

  }
  /* Add new node */
  else {
    i = node_list_size;
    /* Create entry */
    gtk_clist_insert(GTK_CLIST(node_list), i, tmp);
    /* Main address */
    gtk_clist_set_text(GTK_CLIST(node_list), i, 0, dest);
    if (memcmp(&node->addr, &main_addr, ipsize) == 0) {
      if (memcmp(&node->gw_addr, &null_addr, ipsize) != 0)
        gtk_clist_set_text(GTK_CLIST(node_list), i, 1, ip_to_string(&node->gw_addr));
      /* Weigth */
      if (node->hopcount != 0) {
        gui_itoa(node->hopcount, itoa_buf);
        gtk_clist_set_text(GTK_CLIST(node_list), i, 2, itoa_buf);
      }
      /* Device */
      gtk_clist_set_text(GTK_CLIST(node_list), i, 3, &node->dev[0]);
    }

    /* MID */
    if (node->mid.next != &node->mid)
      gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "yes");
    else
      gtk_clist_set_text(GTK_CLIST(node_list), i, 5, "no");
    /* HNA */
    if (node->hna.next != &node->hna)
      gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "yes");
    else
      gtk_clist_set_text(GTK_CLIST(node_list), i, 6, "no");

    node_list_size++;
  }

  gtk_clist_thaw(GTK_CLIST(node_list));

}