Example #1
0
static int is_compressedfile(char *filename)
{
  char buf1[50], buf2[50];
  FILE *fin;
  register int len1, len2, i;

  egg_memset(buf1, 0, 50);
  egg_memset(buf2, 0, 50);
  if (!is_file(filename))
    return COMPF_FAILED;

  /* Read data with zlib routines.
   */
  fin = gzopen(filename, "rb");
  if (!fin)
    return COMPF_FAILED;
  len1 = gzread(fin, buf1, sizeof(buf1));
  if (len1 < 0) {
    gzclose(fin);
    return COMPF_FAILED;
  }
  if (gzclose(fin) != Z_OK)
    return COMPF_FAILED;

  /* Read raw data.
   */
  fin = fopen(filename, "rb");
  if (!fin)
    return COMPF_FAILED;
  len2 = fread(buf2, 1, sizeof(buf2), fin);
  if (ferror(fin)) {
    fclose(fin);
    return COMPF_FAILED;
  }
  fclose(fin);

  /* Compare what we found.
   */
  if (len1 != len2)
    return COMPF_COMPRESSED;
  for (i = 0; i < sizeof(buf1); i++)
    if (buf1[i] != buf2[i])
      return COMPF_COMPRESSED;
  return COMPF_UNCOMPRESSED;
}
Example #2
0
/* Allocate and initialise a chunk of memory.
 */
static inline void *n_malloc_null(int size, const char *file, int line)
{
#ifdef DEBUG_MEM
#  define nmalloc_null(size) n_malloc_null(size, __FILE__, __LINE__)
  void *ptr = n_malloc(size, file, line);
#else
#  define nmalloc_null(size) n_malloc_null(size, NULL, 0)
  void *ptr = nmalloc(size);
#endif

  egg_memset(ptr, 0, size);
  return ptr;
}
Example #3
0
int init_uptime(void)
{
  struct sockaddr_in sai;
  char x[64], *z = x;

  upPack.regnr = 0;  /* unused */
  upPack.pid = 0;    /* must set this later */
  upPack.type = htonl(uptime_type);
  upPack.packets_sent = 0; /* reused (abused?) to send our packet count */
  upPack.uptime = 0; /* must set this later */
  uptimecount = 0;
  uptimeip = -1;

  strncpyz(x, ver, sizeof x);
  newsplit(&z);
  strncpyz(uptime_version, z, sizeof uptime_version);

  if ((uptimesock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    putlog(LOG_DEBUG, "*", "init_uptime socket returned < 0 %d", uptimesock);
    return ((uptimesock = -1));
  }
  egg_memset(&sai, 0, sizeof(sai));
  sai.sin_addr.s_addr = INADDR_ANY;
  sai.sin_family = AF_INET;
  if (bind(uptimesock, (struct sockaddr *) &sai, sizeof(sai)) < 0) {
    close(uptimesock);
    return ((uptimesock = -1));
  }
  fcntl(uptimesock, F_SETFL, O_NONBLOCK | fcntl(uptimesock, F_GETFL));

  next_minutes = rand() % update_interval; /* Initial update delay */
  next_seconds = rand() % 59;
  next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) +
    next_seconds);

  return 0;
}