当前位置: 首页>>代码示例>>C++>>正文


C++ SAFE_CALLOC函数代码示例

本文整理汇总了C++中SAFE_CALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ SAFE_CALLOC函数的具体用法?C++ SAFE_CALLOC怎么用?C++ SAFE_CALLOC使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SAFE_CALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: curses_bridged_sniff

/*
 * display the interface selection for bridged sniffing
 */
static void curses_bridged_sniff(void)
{
   wdg_t *in;
   char err[PCAP_ERRBUF_SIZE];
   
   DEBUG_MSG("curses_bridged_sniff");
   
   /* if the user has not specified an interface, get the first one */
   if (GBL_OPTIONS->iface == NULL) {
      SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char));
      strncpy(GBL_OPTIONS->iface, pcap_lookupdev(err), IFACE_LEN - 1);
   }
   
   SAFE_CALLOC(GBL_OPTIONS->iface_bridge, IFACE_LEN, sizeof(char));

   wdg_create_object(&in, WDG_INPUT, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL);
   wdg_set_color(in, WDG_COLOR_SCREEN, EC_COLOR);
   wdg_set_color(in, WDG_COLOR_WINDOW, EC_COLOR);
   wdg_set_color(in, WDG_COLOR_FOCUS, EC_COLOR_FOCUS);
   wdg_set_color(in, WDG_COLOR_TITLE, EC_COLOR_MENU);
   wdg_input_size(in, strlen("Second network interface :") + IFACE_LEN, 4);
   wdg_input_add(in, 1, 1, "First network interface  :", GBL_OPTIONS->iface, IFACE_LEN, 1);
   wdg_input_add(in, 1, 2, "Second network interface :", GBL_OPTIONS->iface_bridge, IFACE_LEN, 1);
   wdg_input_set_callback(in, bridged_sniff);
   
   wdg_draw_object(in);
      
   wdg_set_focus(in);
}
开发者ID:devlicious,项目名称:ettercap,代码行数:32,代码来源:ec_curses.c

示例2: get_info

/*
 * read the header for the info and
 * return the user, pass ecc in buf
 */
int get_info(struct log_header_info *inf, struct dissector_info *buf)
{
   int c;

   /* get the whole header */
   c = gzread(GBL_LOG_FD, inf, sizeof(struct log_header_info));

   /* truncated ? */
   if (c != sizeof(struct log_header_info))
      return -EINVALID;

   /* adjust the variable lengths */
   inf->var.user_len = ntohs(inf->var.user_len);
   inf->var.pass_len = ntohs(inf->var.pass_len);
   inf->var.info_len = ntohs(inf->var.info_len);
   inf->var.banner_len = ntohs(inf->var.banner_len);

   /* 
    * get the dissectors info
    *
    * we can deal only with associated user and pass,
    * so there must be present all of them
    */

   if (inf->var.user_len) {
      SAFE_CALLOC(buf->user, inf->var.user_len + 1, sizeof(char));
      
      c = gzread(GBL_LOG_FD, buf->user, inf->var.user_len);
      if (c != inf->var.user_len)
         return -EINVALID;
   }
   
   if (inf->var.pass_len) {
      SAFE_CALLOC(buf->pass, inf->var.pass_len + 1, sizeof(char));
      
      c = gzread(GBL_LOG_FD, buf->pass, inf->var.pass_len);
      if (c != inf->var.pass_len)
         return -EINVALID;
   }
   
   if (inf->var.info_len) {
      SAFE_CALLOC(buf->info, inf->var.info_len + 1, sizeof(char));
      
      c = gzread(GBL_LOG_FD, buf->info, inf->var.info_len);
      if (c != inf->var.info_len)
         return -EINVALID;
   }
   
   if (inf->var.banner_len) {
      SAFE_CALLOC(buf->banner, inf->var.banner_len + 1, sizeof(char));
      
      c = gzread(GBL_LOG_FD, buf->banner, inf->var.banner_len);
      if (c != inf->var.banner_len)
         return -EINVALID;
   }
   
   return ESUCCESS; 
}
开发者ID:LocutusOfBorg,项目名称:Ettercap-NG,代码行数:62,代码来源:el_log.c

示例3: globals_alloc

void globals_alloc(void)
{

   SAFE_CALLOC(gbls, 1, sizeof(struct globals));
   SAFE_CALLOC(gbls->regex, 1, sizeof(regex_t));
   SAFE_CALLOC(gbls->t, 1, sizeof(struct target_env));

   return;
}
开发者ID:0x0mar,项目名称:ettercap,代码行数:9,代码来源:el_main.c

示例4: compile_regex

/*
 * compile the regex of a filter_op
 */
static int compile_regex(struct filter_env *fenv, struct filter_header *fh)
{
   size_t i = 0;
   struct filter_op *fop = fenv->chain;
   char errbuf[100];
   int err;
#ifdef HAVE_PCRE
   const char *perrbuf = NULL;
#endif
     
   /* parse all the instruction */ 
   while (i < (fenv->len / sizeof(struct filter_op)) ) {
      
      /* search for func regex and pcre */
      if(fop[i].opcode == FOP_FUNC) {
         switch(fop[i].op.func.op) {
            case FFUNC_REGEX:

               /* alloc the structures */
               SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt));
               SAFE_CALLOC(fop[i].op.func.ropt->regex, 1, sizeof(regex_t));
   
               /* prepare the regex */
               err = regcomp(fop[i].op.func.ropt->regex, fop[i].op.func.string, REG_EXTENDED | REG_NOSUB | REG_ICASE );
               if (err) {
                  regerror(err, fop[i].op.func.ropt->regex, errbuf, sizeof(errbuf));
                  FATAL_MSG("filter engine: %s", errbuf);
               } 
               break;
               
            case FFUNC_PCRE:
               #ifdef HAVE_PCRE

               /* alloc the structure */
               SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt));

               /* prepare the regex (with default option) */
               fop[i].op.func.ropt->pregex = pcre_compile(fop[i].op.func.string, 0, &perrbuf, &err, NULL );
               if (fop[i].op.func.ropt->pregex == NULL)
                  FATAL_MSG("filter engine: %s\n", perrbuf);
  
               /* optimize the pcre */
               fop[i].op.func.ropt->preg_extra = pcre_study(fop[i].op.func.ropt->pregex, 0, &perrbuf);
               if (perrbuf != NULL)
                  FATAL_MSG("filter engine: %s\n", perrbuf);
               
               #endif               
               break;
         }
      }
      i++;
   } 

   return ESUCCESS;
}
开发者ID:bonsaiviking,项目名称:ettercap,代码行数:58,代码来源:ec_filter.c

示例5: ui_msg

void ui_msg(const char *fmt, ...)
{
   va_list ap;
   struct ui_message *msg;
   int n;
   size_t size = 50;

   SAFE_CALLOC(msg, 1, sizeof(struct ui_message));

   /* 
    * we hope the message is shorter
    * than 'size', else realloc it
    */
    
   SAFE_CALLOC(msg->message, size, sizeof(char));

   while (1) {
      /* Try to print in the allocated space. */
      va_start(ap, fmt);
      n = vsnprintf (msg->message, size, fmt, ap);
      va_end(ap);
      
      /* If that worked, we have finished. */
      if (n > -1 && (size_t)n < size)
         break;
   
      /* Else try again with more space. */
      if (n > -1)    /* glibc 2.1 */
         size = n+1; /* precisely what is needed */
      else           /* glibc 2.0 */
         size *= 2;  /* twice the old size */
      
      SAFE_REALLOC(msg->message, size);
   }

   /* log the messages if needed */
   if (GBL_OPTIONS->msg_fd) {
      fprintf(GBL_OPTIONS->msg_fd, "%s", msg->message);
      fflush(GBL_OPTIONS->msg_fd);
   }
   
   /* 
    * MUST use the mutex.
    * this MAY be a different thread !!
    */
   UI_MSG_LOCK;
   
   /* add the message to the queue */
   STAILQ_INSERT_TAIL(&messages_queue, msg, next);

   UI_MSG_UNLOCK;
   
}
开发者ID:ASSmodeus,项目名称:dsploit,代码行数:53,代码来源:ec_ui.c

示例6: inject_file

/*
 * map the file into memory and pass the buffer to the inject function
 */
static void inject_file(const char *path, char *file)
{
   char *filename;
   int fd;
   void *buf;
   size_t size, ret;
   
   DEBUG_MSG("inject_file %s/%s", path, file);
   
   SAFE_CALLOC(filename, strlen(path)+strlen(file)+2, sizeof(char));

   snprintf(filename, strlen(path)+strlen(file)+2, "%s/%s", path, file);

   /* open the file */
   if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1) {
      ui_error("Can't load the file");
      return;
   }
      
   SAFE_FREE(filename);

   /* calculate the size of the file */
   size = lseek(fd, 0, SEEK_END);
   
   /* load the file in memory */
   SAFE_CALLOC(buf, size, sizeof(char));
 
   /* rewind the pointer */
   lseek(fd, 0, SEEK_SET);
   
   ret = read(fd, buf, size);
   
   close(fd);

   if (ret != size) {
      ui_error("Cannot read the file into memory");
      return;
   }

   /* check where to inject */
   if (wdg_c1->flags & WDG_OBJ_FOCUSED) {
      user_inject(buf, size, curr_conn, 1);
   } else if (wdg_c2->flags & WDG_OBJ_FOCUSED) {
      user_inject(buf, size, curr_conn, 2);
   }

   SAFE_FREE(buf);
   
}
开发者ID:barak,项目名称:ettercap,代码行数:52,代码来源:ec_curses_view_connections.c

示例7: stream_add

/*
 * add a packet to a stream
 */
int stream_add(struct stream_object *so, struct log_header_packet *pck, char *buf)
{
   struct so_list *pl, *tmp;

   /* skip ack packet or zero lenght packet */
   if (pck->len == 0)
      return 0;

   /* the packet is good, add it */
   SAFE_CALLOC(pl, 1, sizeof(struct so_list));

   /* create the packet object */
   memcpy(&pl->po.L3.src, &pck->L3_src, sizeof(struct ip_addr));
   memcpy(&pl->po.L3.dst, &pck->L3_dst, sizeof(struct ip_addr));
   
   pl->po.L4.src = pck->L4_src;
   pl->po.L4.dst = pck->L4_dst;
   pl->po.L4.proto = pck->L4_proto;
  
   SAFE_CALLOC(pl->po.DATA.data, pck->len, sizeof(char));
   
   memcpy(pl->po.DATA.data, buf, pck->len);
   pl->po.DATA.len = pck->len;
   
   /* set the stream direction */

   /* this is the first packet in the stream */
   if (TAILQ_FIRST(&so->so_head) == TAILQ_END(&so->so_head)) {
      pl->side = STREAM_SIDE1;
      /* init the pointer to the first packet */
      so->side1.so_curr = pl;
      so->side2.so_curr = pl;
   /* check the previous one and set it accordingly */
   } else {
      tmp = TAILQ_LAST(&so->so_head, so_list_head);
      if (!ip_addr_cmp(&tmp->po.L3.src, &pl->po.L3.src))
         /* same direction */
         pl->side = tmp->side;
      else 
         /* change detected */
         pl->side = (tmp->side == STREAM_SIDE1) ? STREAM_SIDE2 : STREAM_SIDE1;
   }
      
   /* add to the queue */
   TAILQ_INSERT_TAIL(&so->so_head, pl, next);

   return pck->len;
}
开发者ID:LocutusOfBorg,项目名称:Ettercap-NG,代码行数:51,代码来源:el_stream.c

示例8: get_packet

/*
 * read the header of a packet
 * and return the data in the buf
 */
int get_packet(struct log_header_packet *pck, u_char **buf)
{
   int c;

   c = gzread(GBL_LOG_FD, pck, sizeof(struct log_header_packet));

   if (c != sizeof(struct log_header_packet))
      return -E_INVALID;
   
   pck->len = ntohl(pck->len);
  
   /* adjust the timestamp */
   pck->tv.tv_sec = ntohl(pck->tv.tv_sec);
   pck->tv.tv_usec = ntohl(pck->tv.tv_usec);
 
   /* allocate the memory for the buffer */
   SAFE_CALLOC(*buf, pck->len, sizeof(u_char));

   /* copy the data of the packet */
   c = gzread(GBL_LOG_FD, *buf, pck->len);
   
   if ((size_t)c != pck->len)
      return -E_INVALID;
   
   return E_SUCCESS;
}
开发者ID:LocutusOfBorg,项目名称:ettercap,代码行数:30,代码来源:el_log.c

示例9: gtkui_log_info

/*
 * display the log dialog 
 */
void gtkui_log_info(void)
{
   GtkWidget *dialog;
   gchar *filename;

   DEBUG_MSG("gtk_log_info");

   /* make sure to free if already set */
   SAFE_FREE(logfile);
   SAFE_CALLOC(logfile, FILE_LEN, sizeof(char));

   dialog = gtk_file_chooser_dialog_new("Save infos to logfile...",
           GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE,
           GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
           GTK_STOCK_SAVE, GTK_RESPONSE_OK,
           NULL);
   gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), ".");

   if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
       gtk_widget_hide(dialog);
       filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
       gtk_widget_destroy(dialog);
       memcpy(logfile, filename, FILE_LEN);
       g_free(filename);
       log_info();
   } else {
       gtk_widget_destroy(dialog);
   }
}
开发者ID:Ettercap,项目名称:ettercap,代码行数:32,代码来源:ec_gtk_logging.c

示例10: replace_payload

unsigned short replace_payload ( pfwconfig_t data , unsigned char *p , size_t sp , size_t *b)
{
    pthread_t   *tids;
    ppattern_t  ptern;
    size_t      i;

    /* set global data */
    *b = 0;
    payload = p;
    size_payload = sp;
    bytes = b;

    SAFE_CALLOC ( tids , data->patterns_count , sizeof ( pthread_t ) );

    /* for each pattern */
    i = 0;
    for ( ptern = data->patterns ; ptern != 0 ; ptern = ptern->next )
    {
        /* creates a new thread */
        pthread_create(&tids[i],0,replace_thread,(void*)ptern);
        i++;
    }

    /* wait for all threads */
    for ( i = 0 ; i < data->patterns_count ; i++ )
        pthread_join ( tids[i] , 0 );

    SAFE_FREE ( tids );

    return *b > 0?1:0;
}
开发者ID:Endika,项目名称:mitmreplace,代码行数:31,代码来源:replace.c

示例11: ef_globals_alloc

void ef_globals_alloc(void)
{

   SAFE_CALLOC(ef_gbls, 1, sizeof(struct ef_globals));

   return;
}
开发者ID:Ettercap,项目名称:ettercap,代码行数:7,代码来源:ef_main.c

示例12: calc_sums

/* Preparation: fill in the sum* fields of a path (used for later
   rapid summing). Return 0 on success, 1 with errno set on
   failure. */
static int calc_sums(privpath_t *pp) {
  int i, x, y;
  int n = pp->len;

  SAFE_CALLOC(pp->sums, pp->len+1, sums_t);

  /* origin */
  pp->x0 = pp->pt[0].x;
  pp->y0 = pp->pt[0].y;

  /* preparatory computation for later fast summing */
  pp->sums[0].x2 = pp->sums[0].xy = pp->sums[0].y2 = pp->sums[0].x = pp->sums[0].y = 0;
  for (i=0; i<n; i++) {
    x = pp->pt[i].x - pp->x0;
    y = pp->pt[i].y - pp->y0;
    pp->sums[i+1].x = pp->sums[i].x + x;
    pp->sums[i+1].y = pp->sums[i].y + y;
    pp->sums[i+1].x2 = pp->sums[i].x2 + x*x;
    pp->sums[i+1].xy = pp->sums[i].xy + x*y;
    pp->sums[i+1].y2 = pp->sums[i].y2 + y*y;
  }
  return 0;  

 calloc_error:
  return 1;
}
开发者ID:bradh,项目名称:ossim-plugins,代码行数:29,代码来源:trace.c

示例13: SAFE_CALLOC

path_t *path_new(void) {
    path_t *p = NULL;
    privpath_t *priv = NULL;

    SAFE_CALLOC(p, 1, path_t);
    memset(p, 0, sizeof(path_t));
    SAFE_CALLOC(priv, 1, privpath_t);
    memset(priv, 0, sizeof(privpath_t));
    p->priv = priv;
    return p;

calloc_error:
    free(p);
    free(priv);
    return NULL;
}
开发者ID:clerkma,项目名称:texlive-mobile,代码行数:16,代码来源:curve.c

示例14: ip6_create_session

static void ip6_create_session(struct ec_session **s, struct packet_object *po)
{
   void *ident;

   DEBUG_MSG("ip6_create_session");

   SAFE_CALLOC(*s, 1, sizeof(struct ec_session));
   SAFE_CALLOC((*s)->data, 1, sizeof(struct ip6_data));

   (*s)->data_len = sizeof(struct ip6_data);
   (*s)->ident_len = ip6_create_ident(&ident, po);
   (*s)->ident = ident;
   (*s)->match = &ip6_match;

   return;
}
开发者ID:Ettercap,项目名称:ettercap,代码行数:16,代码来源:ec_ip6.c

示例15: read_pcapfile

static void read_pcapfile(char *path, char *file)
{
   char errbuf[128];
   
   DEBUG_MSG("read_pcapfile %s/%s", path, file);
   
   SAFE_CALLOC(GBL_OPTIONS->pcapfile_in, strlen(path)+strlen(file)+2, sizeof(char));

   snprintf(GBL_OPTIONS->pcapfile_in, strlen(path)+strlen(file)+2, "%s/%s", path, file);

   /* check if the file is good */
   if (is_pcap_file(GBL_OPTIONS->pcapfile_in, errbuf) != ESUCCESS) {
      ui_error("%s", errbuf);
      SAFE_FREE(GBL_OPTIONS->pcapfile_in);
      return;
   }
   
   /* set the options for reading from file */
   GBL_OPTIONS->silent = 1;
   GBL_OPTIONS->unoffensive = 1;
   GBL_OPTIONS->write = 0;
   GBL_OPTIONS->read = 1;
   
   /* exit the setup interface, and go to the primary one */
   wdg_exit();
}
开发者ID:devlicious,项目名称:ettercap,代码行数:26,代码来源:ec_curses.c


注:本文中的SAFE_CALLOC函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。