Beispiel #1
0
static int c2w( int c_count, 
                const char* c, 
                int w_count, 
                wchar_t* w // array of at least w_count+1 wide characters
                )
{
  // convert UTF-8 string to UTF-16 string
  int rc = 0;
  if ( w ) 
    w[0] = 0;
  // returns length of converted c[]
  if ( w_count > 0 && w && c_count > 0 && c && c[0] ) {
    w[0] = 0;
    if ( c ) 
    {
      unsigned int error_status = 0;
      unsigned int error_mask = 0xFFFFFFFF;
      ON__UINT32 error_code_point = 0xFFFD;
      const char* p1 = 0;
      rc = ON_ConvertUTF8ToWideChar(c,c_count,w,w_count,&error_status,error_mask,error_code_point,&p1);
      if ( rc > 0 && rc <= w_count )
        w[rc] = 0;
      else {
        w[w_count] = 0;
        rc = 0;
      }
      if ( 0 != error_status )
      {
        ON_ERROR("Error converting UTF-8 encoded char string to UTF-16 encoded wchar_t string.");
      }
    }
  }
	return rc;
}
Beispiel #2
0
bool ON_GetKnotVectorSpanVector(
          int order,          // order (>=2)
          int cv_count,       // cv count
          const double* knot, // knot[] array
          double* s           // s[] array
          )
{
  if ( 0 == knot || 0 == s )
  {
    if ( 0 != order || 0 != cv_count )
    {
      ON_ERROR("NULL knot[] or s[] passed to ON_KnotVectorSpanCount.");
      return false;
    }
    return true;
  }

  int i, span_count = 0;
  s[span_count++] = knot[order-2];
  for ( i = order-1; i < cv_count; i++ ) {
    if ( knot[i] > knot[i-1] )
      s[span_count++] = knot[i];
  }
  return (span_count>1) ? true : false;
}
Beispiel #3
0
void ON_wString::Empty()
{
  ON_wStringHeader* p = Header();
  if ( p != pEmptyStringHeader ) {
    if ( p->ref_count > 1 ) {
      // string memory is shared
      p->ref_count--;
	    Create();
    }
    else if ( p->ref_count == 1 ) {
      // string memory is not shared - reuse it
      if (m_s && p->string_capacity>0)
        *m_s = 0;
      p->string_length = 0;
    }
    else {
      // should not happen
      ON_ERROR("ON_wString::Empty() encountered invalid header - fixed.");
      Create();
    }
  }
  else {
    // initialized again
	  Create();
  }
}
Beispiel #4
0
bool ON_BezierCage::IsSingular(		 // true if surface side is collapsed to a point
       int side														 // side of parameter space to test
																			// 0 = south, 1 = east, 2 = north, 3 = west, 4 = bottom, 5 =top
				) const
{
  ON_ERROR("TODO: fill in ON_BezierCage::IsSingular\n");
  return false;
  /*
  int i,j,k=0;
  ON_3dPoint p[2];
  double fuzz[2] = {0.0,0.0};
  p[0].Zero();
  p[1].Zero();
  int i0 = 0;
  int i1 = 0;
  int j0 = 0;
  int j1 = 0;
  switch ( side ) {
  case 0: // south
      i0 = 0;
      i1 = Order(0);
      j0 = 0;
      j1 = 1;
    break;
  case 1: // east
      i0 = Order(0)-1;
      i1 = Order(0);
      j0 = 0;
      j1 = Order(1);
    break;
  case 2: // north
      i0 = 0;
      i1 = Order(0);
      j0 = Order(1)-1;
      j1 = Order(1);
    break;
  case 3: // west
      i0 = 0;
      i1 = 1;
      j0 = 0;
      j1 = Order(1);
    break;
  default:
    return false;
    break;
  }

  GetCV(i0,j0,p[k]);
  fuzz[k] = p[k].Fuzz();
  for ( i = i0; i < i1; i++ ) for ( j = j0; j < j1; j++ ) {
    k = (k+1)%2;
    GetCV( i, j, p[k] );
    fuzz[k] = p[k].Fuzz();
    if ( (p[0]-p[1]).MaximumCoordinate() > fuzz[0]+fuzz[1] )
      return false;
  }
  return true;
  */
}
bool ON_BezierCage::IsSingular(		 // true if surface side is collapsed to a point
       int side														 // side of parameter space to test
																			// 0 = south, 1 = east, 2 = north, 3 = west, 4 = bottom, 5 =top
				) const
{
  ON_ERROR("TODO: fill in ON_BezierCage::IsSingular\n");
  return false;
}
Beispiel #6
0
static void daemon_init(void)
{
   fd = open("./ettercap_demonized.log", O_CREAT|O_TRUNC|O_WRONLY, 0600);
   ON_ERROR(fd, -1, "Can't open daemon log file");
   
   /* daemonize ettercap */
   daemonize();
}
bool ON_SubDArchiveIdMap::AddComponentPtr(ON_SubDComponentPtr eptr, unsigned int archive_id)
{
  if (m_element_count != archive_id)
  {
    ON_ERROR("Archive id is not valid and ON_SubD::Read will fail.");
    return false;
  }
  ON_SubDComponentPtr* p = (ON_SubDComponentPtr*)m_fsp.AllocateElement();
  *p = eptr;

#if defined(ON_DEBUG)
  if (0 != archive_id)
  {
    const ON_SubDComponentPtr* p1 = (const ON_SubDComponentPtr*)m_fsp.Element(archive_id);
    unsigned int archive_id1 = 0;
    if (p1 == p)
    {
      switch (p1->ComponentType())
      {
      case ON_SubDComponentPtr::Type::Vertex:
        archive_id1 = p1->Vertex()->ArchiveId();
        break;
      case ON_SubDComponentPtr::Type::Edge:
        archive_id1 = p1->Edge()->ArchiveId();
        break;
      case ON_SubDComponentPtr::Type::Face:
        archive_id1 = p1->Face()->ArchiveId();
        break;
      default:
        ON_ERROR("invalid element type");
        break;
      }
    }
    if (archive_id1 != archive_id)
    {
      // break here and then see what went wrong
      ON_SubDIncrementErrorCount();
      m_fsp.Element(archive_id);
      m_fsp.Element(archive_id);
    }
  }
#endif

  m_element_count++;
  return true;
}
Beispiel #8
0
//
// Object creation
//
void* check_malloc(size_t size)
{
	void* result = malloc(size);
	if(result == NULL)
		ON_ERROR(-1);

	return result;
}
Beispiel #9
0
char* ON_UuidToString( const ON_UUID& uuid, char* s)
{
  // s - [out]  The s[] char array must have length >= 37.  
  //            The returned char array will have a 36 
  //            character uuid in s[0..35] and a null in s[36].

  // NOTE WELL: 
  //   This code has to work on non-Windows OSs and on both big and
  //   little endian CPUs.  The result must satisfy
  //   uuid == ON_UuidFromString(ON_UuidToString(uuid,s))

  // 31 August 2005 Dale Lear
  //     Changed upper case to lower case so result is
  //     identical to the string returned by Windows' ::UuidToString().
  //static const char x[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  static const char x[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  static const int addhyphen[16] = {0,0,0,1, 0,1, 0,1, 0,1,  0, 0, 0, 0, 0, 0};
  const unsigned char* b = (const unsigned char*)&uuid;
  char* p;
  int i;
  
  static const int* rho = ( ON::big_endian == ON::Endian() ) 
                        ? big_endian_rho 
                        : little_endian_rho;

  // 5 December 2002 Dale Lear:
  //   There is either a bug in Purify (likely) or perhaps a bug in the 
  //   way Microsoft compiles  c>>4 when c is an unsigned char.  In any
  //   case, changing c to an unsigned int makes purify happy and should
  //   work just as well.
  //
  //unsigned char c;

  unsigned int c;

  if ( !s )
    return 0;
  p = s;
  for ( i = 0; i < 16; i++ ) {
    c = b[rho[i]];
    *p++ = x[c>>4];  // purify gripes here if c is an unsigned char - the code runs fine.
    *p++ = x[c&0x0F];
    if ( addhyphen[i] )
      *p++ = '-';
  }
  *p = 0;

#if defined(ON_DEBUG)
  {
    ON_UUID u = ON_UuidFromString(s);
    if ( ON_UuidCompare(&u,&uuid) ) {
      ON_ERROR("ON_UuidToString() bug"); // <- breakpoint here
    }
  }
#endif

  return s;
}
Beispiel #10
0
ON_BOOL32 ON_Light::IsValid( ON_TextLog* text_log ) const
{
  int s = Style();
  if ( s <= ON::unknown_light_style || s >= ON::light_style_count ) {
    ON_ERROR("ON_Light::IsValid(): illegal light style.");
    return false;
  }
  return true;
}
Beispiel #11
0
void log_write_packet(struct log_fd *fd, struct packet_object *po)
{
   struct log_header_packet hp;
   int c, zerr;

   memset(&hp, 0, sizeof(struct log_header_packet));
   
   /* adjust the timestamp */
   memcpy(&hp.tv, &po->ts, sizeof(struct timeval));
   hp.tv.tv_sec = htonl(hp.tv.tv_sec);
   hp.tv.tv_usec = htonl(hp.tv.tv_usec);
  
   memcpy(&hp.L2_src, &po->L2.src, MEDIA_ADDR_LEN);
   memcpy(&hp.L2_dst, &po->L2.dst, MEDIA_ADDR_LEN);
   
   memcpy(&hp.L3_src, &po->L3.src, sizeof(struct ip_addr));
   memcpy(&hp.L3_dst, &po->L3.dst, sizeof(struct ip_addr));
  
   hp.L4_flags = po->L4.flags;
   hp.L4_proto = po->L4.proto;
   hp.L4_src = po->L4.src;
   hp.L4_dst = po->L4.dst;
 
   /* the length of the payload */
   hp.len = htonl(po->DATA.disp_len);

   LOG_LOCK;
   
   if (fd->type == LOG_COMPRESSED) {
      c = gzwrite(fd->cfd, &hp, sizeof(hp));
      ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr));

      c = gzwrite(fd->cfd, po->DATA.disp_data, po->DATA.disp_len);
      ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr));
   } else {
      c = write(fd->fd, &hp, sizeof(hp));
      ON_ERROR(c, -1, "Can't write to logfile");

      c = write(fd->fd, po->DATA.disp_data, po->DATA.disp_len);
      ON_ERROR(c, -1, "Can't write to logfile");
   }
   
   LOG_UNLOCK;
}
bool ON_SubDArchiveIdMap::ConvertArchiveIdToRuntimeVertexPtr(
  unsigned int vertex_count,
  size_t vertex_capacity,
  ON_SubDVertex** vertex
  )
{
  if ( 0 == vertex_count )
    return true;
  if ( 0 == vertex_capacity || nullptr == vertex )
    return ON_SUBD_RETURN_ERROR(false);
  if ( vertex_count > vertex_capacity )
    return ON_SUBD_RETURN_ERROR(false);
  for (unsigned int i = 0; i < vertex_count; i++)
  {
    ON__UINT_PTR vptr = (ON__UINT_PTR)(vertex[i]);
    vertex[i] = nullptr;
    const unsigned int archive_id = ON_SubDArchiveIdMap::ArchiveIdFromComponentPtr(vptr);
    // future use // ON__UINT_PTR flags = ON_SUBD_ELEMENT_FLAGS(vptr);
    if (0 == archive_id || archive_id < m_archive_id_partition[0] || archive_id >= m_archive_id_partition[1])
    {
      ON_ERROR("Invalid vertex archive id.");
      continue;
    }
    const ON_SubDComponentPtr* eleptr = ComponentPtrFromArchiveId(archive_id);
    if (nullptr == eleptr)
    {
      ON_ERROR("null element pointer.");
      continue;
    }
    ON_SubDVertex* v = eleptr->Vertex();
    if (nullptr == v)
    {
      ON_ERROR("null vertex pointer.");
      continue;
    }
    if (archive_id != v->ArchiveId())
    {
      ON_ERROR("archive_id != v->ArchiveId().");
      continue;
    }
    vertex[i] = v;
  }
  return true;
}
Beispiel #13
0
int write_output(void)
{
   int fd;
   struct filter_op *fop;
   struct filter_header fh;
   size_t ninst, i, data_len;
   u_char pad = 0, *data = NULL;

   /* conver the tree to an array of filter_op */
   ninst = compile_tree(&fop);

   if (fop == NULL)
      return -E_NOTHANDLED;

   if (ninst == 0)
      return -E_INVALID;

   /* create the file */
   fd = open(GBL_OPTIONS->output_file, O_CREAT | O_RDWR | O_TRUNC | O_BINARY, 0644);
   ON_ERROR(fd, -1, "Can't create file %s", GBL_OPTIONS->output_file);

   /* display the message */
   fprintf(stdout, " Writing output to \'%s\' ", GBL_OPTIONS->output_file);
   fflush(stdout);
   
   /* compute the header */
   fh.magic = htons(EC_FILTER_MAGIC);
   strncpy(fh.version, EC_VERSION, sizeof(fh.version));
   fh.data = sizeof(fh);

   data_len = create_data_segment(&data, &fh, fop, ninst);
   
   /* write the header */
   write(fd, &fh, sizeof(struct filter_header));

   /* write the data segment */
   write(fd, data, data_len);
   
   /* write padding to next 8-byte boundary */
   for (i = 0; i < fh.code - (fh.data + data_len); i++)
      write(fd, &pad, 1);

   /* write the instructions */
   for (i = 0; i < ninst; i++) {
      print_progress_bar(&fop[i]);
      write(fd, &fop[i], sizeof(struct filter_op));
   }

   close(fd);
   
   fprintf(stdout, " done.\n\n");
  
   fprintf(stdout, " -> Script encoded into %d instructions.\n\n", (int)(i - 1));
   
   return E_SUCCESS;
}
Beispiel #14
0
void open_log(char *file)
{
   int zerr;
   
   GBL_LOGFILE = strdup(file);

   GBL_LOG_FD = gzopen(file, "rb");
   ON_ERROR(GBL_LOG_FD, NULL, "%s", gzerror(GBL_LOG_FD, &zerr));
 
}
unsigned int ON_3dmObjectAttributes::ApplyParentalControl( 
        const ON_3dmObjectAttributes& parents_attributes,
        unsigned int control_limits
        )
{
  ON_ERROR("Do not use deprecated version of ON_3dmObjectAttributes::ApplyParentalControl()");
  ON_Layer bogus_layer;
  bogus_layer.m_layer_index = -1;
  return ApplyParentalControl(parents_attributes,bogus_layer,control_limits);
}
Beispiel #16
0
void ON_FLT_SNAN( float* x)
{
  union 
  {
    float x;
    unsigned char b[4];
  } u;

#if   defined(ON_LITTLE_ENDIAN)
#define i3 3
#define i2 2
#elif defined(ON_BIG_ENDIAN)
#define i3 0
#define i2 1
#else
  unsigned int i3, i2;

  u.x = 2.0f; // sign = 0; mantissa = 0; exponent = 1000 0000

  if ( 0x40 == u.b[3] && 0 == u.b[0] && 0 == u.b[1] && 0 == u.b[2] )
  {
    // little endian doubles
    i3 = 3; i2 = 2;
  }
  else if ( 0x40 == u.b[0] && 0 == u.b[3] && 0 == u.b[1] && 0 == u.b[2] )
  {
    // big endian doubles
    i3 = 0; i2 = 1;
  }
  else
  {
    // this sitation is not handled by this algorithm
    // and that is a bug in the algorithm.
    ON_ERROR("CPU has unexpected bit pattern in float 2.0f.");
    memset(&x,0xFF,sizeof(*x));
    return;
  }
#endif

  // all exponent bits = 1
  // fraction bits = 011...1
  u.b[i3]   = 0x7F; // 0111 1111
  u.b[i2]   = 0xA0; // 1010 0000
  u.b[3-i2] = 0;    // 0...
  u.b[3-i3] = 0;

#if defined(i3)
#undef i3
#undef i2
#endif

  // must use memcpy().  On Intel FPU, assignment using x = u.x 
  // will set x to qnan and invalid op exception occures.
  memcpy(x,&u.x,sizeof(*x));
}
Beispiel #17
0
bool ON_BinaryArchive::ReadCompressedBuffer( // read and uncompress
  size_t sizeof__outbuffer,  // sizeof of uncompressed buffer to read
  void* outbuffer,           // uncompressed output data returned here
  int* bFailedCRC
  )
{
  bool rc = false;
  unsigned int buffer_crc0 = 0;
  unsigned int buffer_crc1 = 0;
  char method = 0;

  if ( bFailedCRC)
    *bFailedCRC = false;
  if ( !ReadMode() )
    return false;
  if ( 0 == sizeof__outbuffer )
    return true;
  if ( 0 == outbuffer )
    return false;

  if ( !ReadInt(&buffer_crc0) ) // 32 bit crc of uncompressed buffer
    return false;

  if ( !ReadChar(&method) )
    return false;

  if ( method != 0 && method != 1 )
    return false;

  switch(method)
  {
  case 0: // uncompressed
    rc = ReadByte(sizeof__outbuffer, outbuffer);
    break;
  case 1: // compressed
    rc = CompressionInit();
    if (rc)
      rc = ReadInflate( sizeof__outbuffer, outbuffer );
    CompressionEnd();
    break;
  }

  if (rc ) 
  {
    buffer_crc1 = ON_CRC32( 0, sizeof__outbuffer, outbuffer );
    if ( buffer_crc1 != buffer_crc0 ) 
    {
      ON_ERROR("ON_BinaryArchive::ReadCompressedBuffer() crc error");
      if ( bFailedCRC )
        *bFailedCRC = true;
    }
  }

  return rc;
}
Beispiel #18
0
void log_write_info_arp_icmp(struct log_fd *fd, struct packet_object *po)
{
   struct log_header_info hi;
   int c, zerr;

   memset(&hi, 0, sizeof(struct log_header_info));

   /* the mac address */
   memcpy(&hi.L2_addr, &po->L2.src, MEDIA_ADDR_LEN);
   
   /* the ip address */
   memcpy(&hi.L3_addr, &po->L3.src, sizeof(struct ip_addr));
  
   /* set the distance */
   if (po->L3.ttl > 1)
      hi.distance = TTL_PREDICTOR(po->L3.ttl) - po->L3.ttl + 1;
   else
      hi.distance = po->L3.ttl;
   
   /* resolve the host */
   host_iptoa(&po->L3.src, hi.hostname);
   
   /* local, non local ecc ecc */
   if (po->L3.proto == htons(LL_TYPE_ARP)) {
      hi.type |= LOG_ARP_HOST;
      hi.type |= FP_HOST_LOCAL;
   } else {
      hi.type = po->PASSIVE.flags;
   }
   
   LOG_LOCK;
   
   if (fd->type == LOG_COMPRESSED) {
      c = gzwrite(fd->cfd, &hi, sizeof(hi));
      ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr));
   } else {
      c = write(fd->fd, &hi, sizeof(hi));
      ON_ERROR(c, -1, "Can't write to logfile");
   }

   LOG_UNLOCK;
}
Beispiel #19
0
ON_InstanceDefinition::IDEF_UPDATE_TYPE ON_InstanceDefinition::IdefUpdateType() const
{
  if ( ON_InstanceDefinition::embedded_def == m_idef_update_type )
  {
    ON_ERROR("Using obsolete ON_InstanceDefinition::embedded_def value - fix code.");
    const_cast< ON_InstanceDefinition* >(this)->m_idef_update_type 
                                  = ( m_source_archive.Length() > 0 )
                                  ? ON_InstanceDefinition::linked_and_embedded_def
                                  : ON_InstanceDefinition::static_def;
  }
  return m_idef_update_type;
}
void ON_SetBinaryArchiveOpenNURBSVersion(ON_BinaryArchive& file, int value)
{
    if ( value >= 200012210 )
    {
        file.m_3dm_opennurbs_version = value;
    }
    else
    {
        ON_ERROR("ON_SetBinaryArchiveOpenNURBSVersion - invalid opennurbs version");
        file.m_3dm_opennurbs_version = 0;
    }
}
bool ON_Quaternion::GetRotation(ON_Xform& xform) const
{
  bool rc;
  ON_Quaternion q(*this);
  if ( q.Unitize() )
  {
    if (    fabs(q.a-a) <= ON_ZERO_TOLERANCE
         && fabs(q.b-b) <= ON_ZERO_TOLERANCE
         && fabs(q.c-c) <= ON_ZERO_TOLERANCE
         && fabs(q.d-d) <= ON_ZERO_TOLERANCE
         )
    {
      // "this" was already unitized - don't tweak bits
      q = *this;
    }
    xform[1][0] = 2.0*(q.b*q.c + q.a*q.d);
    xform[2][0] = 2.0*(q.b*q.d - q.a*q.c);
    xform[3][0] = 0.0;

    xform[0][1] = 2.0*(q.b*q.c - q.a*q.d);
    xform[2][1] = 2.0*(q.c*q.d + q.a*q.b);
    xform[3][1] = 0.0;

    xform[0][2] = 2.0*(q.b*q.d + q.a*q.c);
    xform[1][2] = 2.0*(q.c*q.d - q.a*q.b);
    xform[3][2] = 0.0;

    q.b = q.b*q.b;
    q.c = q.c*q.c;
    q.d = q.d*q.d;
    xform[0][0] = 1.0 - 2.0*(q.c + q.d);
    xform[1][1] = 1.0 - 2.0*(q.b + q.d);
    xform[2][2] = 1.0 - 2.0*(q.b + q.c);

    xform[0][3] = xform[1][3] = xform[2][3] = 0.0;
    xform[3][3] = 1.0;
    rc = true;
  }
  else if ( IsZero() )
  {
    xform.Zero();
    rc = false;
  }
  else
  {
    // something is seriously wrong
    ON_ERROR("ON_Quaternion::GetRotation(ON_Xform) quaternion is invalid");
    xform.Identity();
    rc = false;
  }

  return rc;
}
Beispiel #22
0
void disable_ip_forward(void)
{
   FILE *fd;
   
   fd = fopen("/proc/sys/net/ipv4/ip_forward", "r");
   ON_ERROR(fd, NULL, "failed to open /proc/sys/net/ipv4/ip_forward");

   fscanf(fd, "%c", &saved_status);
   fclose(fd);

   DEBUG_MSG("disable_ip_forward: old value = %c", saved_status);
 
   fd = fopen("/proc/sys/net/ipv4/ip_forward", "w");
   ON_ERROR(fd, NULL, "failed to open /proc/sys/net/ipv4/ip_forward");
   
   fprintf(fd, "0");
   fclose(fd);
   
   atexit(restore_ip_forward);
   atexit(regain_privs_atexit);
}
Beispiel #23
0
void disable_ipv6_forward(void)
{
   FILE *fd;
   char fpath_global[] = "/proc/sys/net/ipv6/conf/all/forwarding";
   char fpath_iface[64];
   
   /* global configuration */
   fd = fopen(fpath_global, "r");
   ON_ERROR(fd, NULL, "failed to open %s", fpath_global);
   
   fscanf(fd, "%c", &saved_status_v6_global);
   fclose(fd);

   /* interface specific configuration */
   snprintf(fpath_iface, 63, "/proc/sys/net/ipv6/conf/%s/forwarding", EC_GBL_OPTIONS->iface);

   fd = fopen(fpath_iface, "r");
   ON_ERROR(fd, NULL, "failed to open %s", fpath_iface);
   
   fscanf(fd, "%c", &saved_status_v6_iface);
   fclose(fd);

   fd = fopen(fpath_global, "w");
   ON_ERROR(fd, NULL, "failed to open %s", fpath_global);

   fprintf(fd, "0");
   fclose(fd);

   fd = fopen(fpath_iface, "w");
   ON_ERROR(fd, NULL, "failed to open %s", fpath_iface);

   fprintf(fd, "0");
   fclose(fd);

   DEBUG_MSG("disable_ipv6_forward: old value = %c/%c (global/interface %s)", 
         saved_status_v6_global, saved_status_v6_iface, EC_GBL_OPTIONS->iface);
 
   
   atexit(restore_ipv6_forward);
}
Beispiel #24
0
static ON_Curve* TuneupEdgeOrTrimRealCurve( ON_CurveProxy& curve, bool bEdge )
{
  const ON_Curve* real_curve = curve.ProxyCurve();
  if ( 0 == real_curve )
    return 0;

  ON_Curve* new_real_curve = 0;
  const ON_Interval curve_domain = curve.Domain();
  if (    curve.ProxyCurveIsReversed()
       || real_curve->Domain() != curve_domain 
       || curve.ProxyCurveDomain() != curve_domain 
     )
  {
    // The proxy is a subset or reversed real curve.
    // Make a new real curve that is the exact geometry
    // the edge or trim requires.

    if ( bEdge )
    {
      new_real_curve = curve.DuplicateCurve();
    }
    else
    {
      // Trim curves end up being converted to piecewise
      // bezier nurbs curves when their pbox is set, 
      // so do the conversion here and save time and
      // memory thrashing.
      ON_NurbsCurve* nurbs_curve = curve.NurbsCurve();
      if ( 0 == nurbs_curve )
      {
        // This is a serious error - investigate it.
        // If you need help, ask Dale Lear.
        ON_ERROR("trim.NurbsCurve() returned NULL");
        new_real_curve = curve.DuplicateCurve();
      }
      else
      {
        nurbs_curve->ChangeDimension(2);
        nurbs_curve->MakePiecewiseBezier();
        new_real_curve = nurbs_curve;
      }
    }

    if (0 != new_real_curve)
    {
      new_real_curve->SetDomain(curve_domain);
    }
  }

  return new_real_curve;
}
Beispiel #25
0
int log_write_header(struct log_fd *fd, int type)
{
   struct log_global_header lh;
   int c, zerr;
   
   DEBUG_MSG("log_write_header : type %d", type);

   memset(&lh, 0, sizeof(struct log_global_header));

   /* the magic number */
   lh.magic = htons(EC_LOG_MAGIC);
   
   /* the offset of the first header is equal to the size of this header */
   lh.first_header = htons(sizeof(struct log_global_header));
   
   strlcpy(lh.version, EC_GBL_VERSION, sizeof(lh.version));
   
   /* creation time of the file */
   gettimeofday(&lh.tv, 0);
   lh.tv.tv_sec = htonl(lh.tv.tv_sec);
   lh.tv.tv_usec = htonl(lh.tv.tv_usec);
      
   lh.type = htonl(type);

   LOG_LOCK;
   
   if (fd->type == LOG_COMPRESSED) {
      c = gzwrite(fd->cfd, &lh, sizeof(lh));
      ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr));
   } else {
      c = write(fd->fd, &lh, sizeof(lh));
      ON_ERROR(c, -1, "Can't write to logfile");
   }

   LOG_UNLOCK;
   
   return c;
}
Beispiel #26
0
/* 
 * if privacy extension for IPv6 is enabled, under certain
 * circumstances, an IPv6 socket can not be written exiting with
 * code -1 bytes written (Cannot assign requested address).
 * see pull request #245.(https://github.com/Ettercap/ettercap/pull/245) 
 * 
 * this usually happens after returning from hibernation
 * therefore we should warn users.
 * 
 * however investigation of the root cause continues but as long as 
 * it isn't identified and fixed, this function is being kept.
 */
void check_tempaddr(const char *iface)
{
   FILE *fd;
   int mode_global, mode_iface;
   char fpath_global[] = "/proc/sys/net/ipv6/conf/all/use_tempaddr";
   char fpath_iface[64];

   snprintf(fpath_iface, 63, "/proc/sys/net/ipv6/conf/%s/use_tempaddr", iface);
   
   fd = fopen(fpath_global, "r");
   ON_ERROR(fd, NULL, "failed to open %s", fpath_global);

   mode_global = fgetc(fd);
   ON_ERROR(mode_global, EOF, "failed to read value from %s", fpath_global);

   fclose(fd);

   DEBUG_MSG("check_tempaddr: %s = %c", fpath_global, mode_global);
 
   fd = fopen(fpath_iface, "r");
   ON_ERROR(fd, NULL, "failed to open %s", fpath_iface);

   mode_iface = fgetc(fd);
   ON_ERROR(mode_iface, EOF, "failed to read value from %s", fpath_iface);
   
   fclose(fd);
   
   DEBUG_MSG("check_tempaddr: %s = %c", fpath_iface, mode_iface);

   if (mode_global != '0')
      USER_MSG("Ettercap might not work correctly. %s is not set to 0.\n", 
            fpath_global);
 
   if (mode_iface != '0')
      USER_MSG("Ettercap might not work correctly. %s is not set to 0.\n", 
            fpath_iface);

}
bool ON_BezierCage::MakeRational()
{
  if ( !IsRational() ) 
  {
    ON_ERROR("TODO: fill in ON_BezierCage::MakeRational()");
    /*
    const int dim = Dimension();
    if ( m_order[0] > 0 && m_order[1] > 0 && m_order[2] > 0 && dim > 0 ) {
      const double* old_cv;
      double* new_cv;
      int cvi, cvj, j, cvstride;
      if ( m_cv_stride[0] < m_cv_stride[1] ) {
        cvstride = m_cv_stride[0] > dim ? m_cv_stride[0] : dim+1;
        ReserveCVCapacity( cvstride*m_order[0]*m_order[1] );
        new_cv = m_cv + cvstride*m_order[0]*m_order[1]-1;
				for ( cvj = m_order[1]-1; cvj >= 0; cvj-- ) {
          for ( cvi = m_order[0]-1; cvi >= 0; cvi-- ) {
            old_cv = CV(cvi,cvj)+dim-1;
            *new_cv-- = 1.0;
            for ( j = 0; j < dim; j++ ) {
              *new_cv-- = *old_cv--;
            }
          }
        }
        m_cv_stride[0] = dim+1;
        m_cv_stride[1] = (dim+1)*m_order[0];
      }
      else {
        cvstride = m_cv_stride[1] > dim ? m_cv_stride[1] : dim+1;
        ReserveCVCapacity( cvstride*m_order[0]*m_order[1] );
        new_cv = m_cv + cvstride*m_order[0]*m_order[1]-1;
        for ( cvi = m_order[0]-1; cvi >= 0; cvi-- ) {
          for ( cvj = m_order[1]-1; cvj >= 0; cvj-- ) {
            old_cv = CV(cvi,cvj)+dim-1;
            *new_cv-- = 1.0;
            for ( j = 0; j < dim; j++ ) {
              *new_cv-- = *old_cv--;
            }
          }
        }
        m_cv_stride[1] = dim+1;
        m_cv_stride[0] = (dim+1)*m_order[1];
      }
      m_is_rat = 1;
    }
    */
  }
  return IsRational();
}
Beispiel #28
0
static int w2c_size( int w_count, const wchar_t* w )
{
  // returns number of bytes used in wide conversion.  Does not
  // include NULL terminator.
  int rc = 0;
  if ( w ) {
    unsigned int error_status = 0;
    rc = ON_ConvertWideCharToUTF8(false,w,w_count,0,0,&error_status,0,0,0);
    if ( error_status )
    {
      ON_ERROR("Wide char string is not valid.");
    }
    if ( rc < 0 )
      rc = 0;
  }
  return rc;
}
bool ON_BezierCage::MakeNonRational()
{
  if ( IsRational() ) 
  {
    ON_ERROR("TODO: fill in ON_BezierCage::MakeNonRational()");
    /*
    const int dim = Dimension();
    if ( m_order[0] > 0 && m_order[1] > 0 && dim > 0 ) {
      double w;
      const double* old_cv;
      double* new_cv = m_cv;
      int cvi, cvj, j;
      if ( m_cv_stride[0] < m_cv_stride[1] ) {
        for ( cvj = 0; cvj < m_order[1]; cvj++ ) {
          for ( cvi = 0; cvi < m_order[0]; cvi++ ) {
            old_cv = CV(cvi,cvj);
            w = old_cv[dim];
            w = ( w != 0.0 ) ? 1.0/w : 1.0;
            for ( j = 0; j < dim; j++ ) {
              *new_cv++ = w*(*old_cv++);
            }
          }
        }
        m_cv_stride[0] = dim;
        m_cv_stride[1] = dim*m_order[0];
      }
      else {
        for ( cvi = 0; cvi < m_order[0]; cvi++ ) {
          for ( cvj = 0; cvj < m_order[1]; cvj++ ) {
            old_cv = CV(cvi,cvj);
            w = old_cv[dim];
            w = ( w != 0.0 ) ? 1.0/w : 1.0;
            for ( j = 0; j < dim; j++ ) {
              *new_cv++ = w*(*old_cv++);
            }
          }
        }
        m_cv_stride[1] = dim;
        m_cv_stride[0] = dim*m_order[1];
      }
      m_is_rat = 0;
    }
    */
  }
  return ( !IsRational() ) ? true : false;
}
Beispiel #30
0
void capture_init(void)
{
   pcap_t *pd;
   u_int32 net, mask;
   struct bpf_program bpf;
   char pcap_errbuf[PCAP_ERRBUF_SIZE];
   
   DEBUG_MSG("capture_init");
   
   GBL_PCAP->snaplen = 1500 + SLL_HDR_LEN;
   
   /*
    * set the offset of the link layer header to SLL_HDR_LEN
    * because we open "any" interface, our packet will have a fake
    * header... look in sad_sarp.h
    */

   GBL_PCAP->offset = SLL_HDR_LEN;
   
   pd = pcap_open_live(PCAP_IFACE, GBL_PCAP->snaplen, PCAP_PROMISC, 
                   PCAP_TIMEOUT, pcap_errbuf);
   ON_ERROR(pd, "%s", pcap_errbuf);
 
   if (pcap_lookupnet(PCAP_IFACE, &net, &mask, pcap_errbuf) == -1)
      ERROR_MSG("%s", pcap_errbuf);

   if (pcap_compile(pd, &bpf, PCAP_FILTER, 1, mask) < 0) 
      ERROR_MSG("%s", pcap_errbuf);
   
   if (pcap_setfilter(pd, &bpf) == -1) 
      ERROR_MSG("pcap_setfilter");
   
   GBL_PCAP->fd = pd;               
 
   atexit(capture_close);
   
   /*
    * and now fill the GBL_PCAP->ifs with the list of network interfaces
    */
   
   load_ifs();

}