コード例 #1
0
ファイル: tcpbridge.c プロジェクト: AmesianX/tcpreplay-netmap
int 
main(int argc, char *argv[])
{
    int optct, rcode;

    init();

    /* call autoopts to process arguments */
    optct = optionProcess(&tcpbridgeOptions, argc, argv);
    argc -= optct;
    argv += optct;

    post_args(argc, argv);

   
    /* init tcpedit context */
    if (tcpedit_init(&tcpedit, pcap_datalink(options.pcap1)) < 0) {
        errx(-1, "Error initializing tcpedit: %s", tcpedit_geterr(tcpedit));
    }
    
    /* parse the tcpedit args */
    rcode = tcpedit_post_args(&tcpedit);
    if (rcode < 0) {
        errx(-1, "Unable to parse args: %s", tcpedit_geterr(tcpedit));
    } else if (rcode == 1) {
        warnx("%s", tcpedit_geterr(tcpedit));
    }
    
    if (tcpedit_validate(tcpedit) < 0) {
        errx(-1, "Unable to edit packets given options:\n%s",
                tcpedit_geterr(tcpedit));
    }

#ifdef ENABLE_VERBOSE
    if (options.verbose) {
        options.tcpdump = (tcpdump_t*)safe_malloc(sizeof(tcpdump_t));
        tcpdump_open(options.tcpdump, options.pcap1);
    }
#endif

    if (gettimeofday(&begin, NULL) < 0)
        err(-1, "gettimeofday() failed");


    /* process packets */
    do_bridge(&options, tcpedit);

    /* clean up after ourselves */
    pcap_close(options.pcap1);

    if (options.unidir) {
        pcap_close(options.pcap2);
    }

#ifdef ENABLE_VERBOSE
    tcpdump_close(options.tcpdump);
#endif

    return 0;
}
コード例 #2
0
ファイル: cpuicon.c プロジェクト: micove/awn-extras
static void
awn_CPUicon_constructed (GObject *object)
{
  /*FIXME*/
  AwnCPUiconPrivate * priv;
  
  glibtop_cpu cpu;
  int i = 0;
  AwnApplet * applet;
  
  g_assert (G_OBJECT_CLASS ( awn_CPUicon_parent_class) );
  
  if (G_OBJECT_CLASS ( awn_CPUicon_parent_class)->constructed)
  {
    G_OBJECT_CLASS ( awn_CPUicon_parent_class)->constructed(object);
  }
  
  g_object_get (object,
                "applet",&applet,
                NULL);
  g_assert (applet);
  g_assert (AWN_IS_APPLET (applet));
  
  priv = AWN_CPUICON_GET_PRIVATE (object); 
  /*
   this will choose add_seconds in a relatively conservative manner.  Note that
   the timer is assumed to be incorrect and time elapsed is actually measured 
   accurately when the timer fires.  Area graph can be informed that the 
   measurement contains a partial point and it will average things out.
   */
  priv->dialog = awn_cpu_dialog_new_with_applet(GTK_WIDGET(object),applet);
  gtk_window_set_title (GTK_WINDOW (priv->dialog),_("CPU"));
  g_signal_connect(object, "button-press-event", 
                   G_CALLBACK(_awn_cpu_icon_clicked), 
                   priv->dialog);
  
  
  priv->num_cpus = 0;
  priv->prev_time = get_double_time();
  glibtop_get_cpu(&cpu);

  while (i < GLIBTOP_NCPU && cpu.xcpu_total[i] != 0)
  {
    priv->num_cpus++;
    i++;
  }
  priv->now = 0;
  
  connect_notify (object, "graph-type",
                    G_CALLBACK (_graph_type_change),applet);
  connect_notify (object, "update-timeout",
                    G_CALLBACK (_update_timeout_change),object);
  
  set_timeout (AWN_CPUICON(object));
  priv->text_overlay = AWN_OVERLAY(awn_overlay_text_new());

  g_object_set (priv->text_overlay,
               "align", AWN_OVERLAY_ALIGN_RIGHT,
               "gravity", GDK_GRAVITY_SOUTH,
                "x-adj", 0.3,
                "y-adj", 0.0,
                "text", "0.0",
               NULL);
  awn_overlayable_add_overlay (AWN_OVERLAYABLE(object), priv->text_overlay);

  do_bridge ( applet,object,
             "icon","update_timeout","update-timeout");

}