Exemple #1
0
int scamper_if_getmac(const int ifindex, uint8_t *mac)
{
  scamper_fd_t *fd = NULL;
  struct ifreq ifr;

  if(if_indextoname(ifindex, ifr.ifr_name) == NULL)
    {
      printerror(errno, strerror, __func__, "could not if_indextoname");
      goto err;
    }

  if((fd = scamper_fd_ifsock()) == NULL)
    {
      printerror(errno, strerror, __func__, "could not get ifsock");
      goto err;
    }

  if(ioctl(scamper_fd_fd_get(fd), SIOCGIFHWADDR, &ifr) == -1)
    {
      printerror(errno, strerror, __func__, "could not SIOCGIFHWADDR");
      goto err;
    }
  memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);

  scamper_fd_free(fd);
  return 0;

 err:
  if(fd != NULL) scamper_fd_free(fd);
  return -1;
}
Exemple #2
0
/**
 * \brief Start the minstack_tcp in parameter
 * \param mt the minstack_tcp that have to be started
 * \return 0 if the minstack_tcp stack started correctly
 */
int minstack_tcp_start(minstack_tcp *mt) {
    int retval = 0;
    if (!mt || mt->status != IDLE) {
        printerror("Cannot start while already started\n");
        return -1;
    }
    switch (mt->type) {
    case NONE:
        printwarning("the minstack_tcp is not initialized\n");
        return -1;
    case SERVER:
        retval = minstack_tcp_boot_server(mt);
        break;
    case CLIENT:
        retval = minstack_tcp_boot_client(mt);
        break;
    default:
        printerror("Unknow enum type %d\n",mt->type);
        break;
    }
    if (!retval) {
        mt->status = STARTED;
        printmessage("%s is now started\n",mt->name);
    }
    return retval;
}
Exemple #3
0
int 
vot_addFieldMeta (int handle, fitsfile *fp, int index)
{
    char  *ucd, *utype, *id, keyw[SZ_FNAME];
    int   status = 0;


    if ( (ucd = vot_getAttr (handle, "ucd")) ) {	/* UCD attribute     */
        memset (keyw, 0, SZ_FNAME);
        sprintf (keyw, "TUCD%d", index);
        if (fits_update_key (fp, TSTRING, keyw, ucd, "UCD attribute", &status))
	    printerror ( status );
    }

    if ( (utype = vot_getAttr (handle, "utype")) ) {	/* UTYPE attribute   */
        memset (keyw, 0, SZ_FNAME);
        sprintf (keyw, "TUTYPE%d", index);
        if (fits_update_key (fp, TSTRING, keyw, utype, "UTYPE attribute",
	    &status))
	        printerror ( status );
    }

    if ( (id = vot_getAttr (handle, "id")) ) {		/* ID attribute     */
        memset (keyw, 0, SZ_FNAME);
        sprintf (keyw, "TID%d", index);
        if (fits_update_key (fp, TSTRING, keyw, id, "ID attribute", &status))
	    printerror ( status );
    }

    return (0);
}
Exemple #4
0
static void mousemoveevent(int x, int y) {
    char* error;
    if (!luastate_PushFunctionArgumentToMainstate_Double(x)) {
        printerror("Error when pushing func args to blitwizard.onMouseMove");
        fatalscripterror();
        main_Quit(1);
        return;
    }
    if (!luastate_PushFunctionArgumentToMainstate_Double(y)) {
        printerror("Error when pushing func args to blitwizard.onMouseMove");
        fatalscripterror();
        main_Quit(1);
        return;
    }
    if (!luastate_CallFunctionInMainstate("blitwizard.onMouseMove",
    2, 1, 1, &error, NULL, NULL)) {
        luacfuncs_onError("blitwizard.onMouseMove", error);
        if (error) {
            free(error);
        }
    }
#ifdef USE_GRAPHICS
    luacfuncs_objectgraphics_processMouseMove(x, y);
#endif
}
Exemple #5
0
int scamper_ip4_openraw(void)
{
    int fd = -1;

#if defined(WITHOUT_PRIVSEP)
    int hdr = 1;
    if((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1)
    {
        printerror(errno, strerror, __func__, "could not open socket");
        goto err;
    }

    if(setsockopt(fd, IPPROTO_IP, IP_HDRINCL, (void *)&hdr, sizeof(hdr)) == -1)
    {
        printerror(errno, strerror, __func__, "could not IP_HDRINCL");
        goto err;
    }
#else
    if((fd = scamper_privsep_open_rawip()) == -1)
    {
        printerror(errno, strerror, __func__, "could not open socket");
        goto err;
    }
#endif

    return fd;

err:
    if(fd != -1) scamper_ip4_close(fd);
    return -1;
}
Exemple #6
0
int main ( int argc, char **argv )
{
	Argvs cmd = ParseCommandLine ( argc, argv );
	if ( cmd.mode == OP_KEYGEN ) {
		if ( keygen ( cmd.t ) != 0 ) {
			printerror ( "Unknown keygen error" );
		}
	} else if ( cmd.mode == OP_CRYPT ) {
		if ( crypt ( cmd.file1, cmd.file2 ) != 0 ) {
			printerror ( "Unknown crypt error" );
		}
		free ( cmd.file1 );
		free ( cmd.file2 );
	} else if ( cmd.mode == OP_INVKEY ) {
		if ( invkey ( cmd.file1 ) != 0 ) {
			printerror ( "unknown invkey error" );
		}
		free ( cmd.file1 );
	} else if ( cmd.mode == OP_HISTO ) {
		if ( histo ( cmd.t, cmd.i, cmd.file1 ) != 0 ) {
			printerror ( "unknown histo error" );
		}
		free ( cmd.file1 );
	} else if ( cmd.mode == OP_SOLVE ) {
		if ( solve ( cmd.l, cmd.file1 ) != 0 ) {
			printerror ( "unknown solve error" );
		}
		free ( cmd.file1 );
	}
	return 0;
}
static void rtmsg_dump(const uint8_t *buf, size_t len)
{
  char str[80];
  size_t i, off = 0;
  int k = 0;

  for(i=0; i<len; i++)
    {
      if(k == 20)
	{
	  printerror(0, NULL, __func__, "%s", str);
	  k = 0;
	  off = 0;
	}

      if(k != 0 && (k % 4) == 0)
	string_concat(str, sizeof(str), &off, " ");
      string_concat(str, sizeof(str), &off, "%02x", buf[i]);
      k++;
    }

  if(k != 0)
    printerror(0, NULL, __func__, "%s", str);
  return;
}
Exemple #8
0
static void keyboardevent(const char* key, int release) {
    char* error;

    // We handle key up and key down,
    // and for both we ask a hidden (undocumented)
    // event function for the templates whether they
    // want to have the key event.
    //
    // (This will allow for a neat transparent
    // addition of an ingame developer console)
    const char onkeyup[] = "blitwizard.onKeyUp";
    const  char onkeyup_templates[] = "blitwizard._onKeyUp_Templates";
    const char* funcname = "blitwizard.onKeyDown";
    const char* funcname_templates = "blitwizard._onKeyDown_Templates";
    if (release) {
        funcname = onkeyup;
        funcname_templates = onkeyup_templates;
    }

    // Call function template function first:
    int returnboolean = 0;
    if (!luastate_PushFunctionArgumentToMainstate_String(key)) {
        printerror("Error when pushing func args to %s", funcname_templates);
        fatalscripterror();
        main_Quit(1);
    }
    if (!luastate_CallFunctionInMainstate(funcname_templates, 1, 1, 1, &error,
    NULL, &returnboolean)) {
        luacfuncs_onError(funcname_templates, error);
        if (error) {
            free(error);
        }
        return;
    }

    // if the templates event function has returned true, it handles
    // the event and we don't propagate it further:
    if (returnboolean) {
        return;
    }

    // otherwise, call the regular event function now:
    if (!luastate_PushFunctionArgumentToMainstate_String(key)) {
        printerror("Error when pushing func args to %s", funcname);
        fatalscripterror();
        main_Quit(1);
        return;
    }
    if (!luastate_CallFunctionInMainstate(funcname, 1, 1, 1, &error, NULL,
    NULL)) {
        luacfuncs_onError(funcname, error);
        if (error) {
            free(error);
        }
        return;
    }
}
Exemple #9
0
void __fastcall TForm1::BGuardarClick(TObject *Sender)
{
  fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */
  int status;
  AnsiString N;

  ejex = X2;
  ejey = Y2;
  long n = X2*Y2;
  if(SD1->Execute())
  {
    status = 0;
    N = SD1->FileName + ".fit";
    if(ffinit(&fptr, N.c_str(), &status))
    {
      printerror( status );
      status = 0;
      if ( fits_open_file(&fptr, N.c_str(), READWRITE, &status) )
      {
         printerror(status);
        return;
      }
    }
  }
  else
    return;

  long axes[2];
  axes[0] = ejex;
  axes[1] = ejey;
  if(ffcrim(fptr, 16, 2, axes, &status))
  {
    printerror(status);
    return;
  }

  unsigned short *datos;

  datos = new unsigned short [ejex*ejey];
  memset(datos, 0, ejex*ejey*2);
  for(int py = 0; py < ejey; py++)
  {
    for (int px = ejex; px > 0; px--)
    {
      datos[n--] = Foto[py][px];
    }
  }

  status = 0;
  if(fits_write_img(fptr, TSHORT, 1, ejex*ejey, datos, &status))
  {
    printerror( status );
  }
  delete datos;
  return;
}
Exemple #10
0
static int fds_kqueue(struct timeval *tv)
{
  scamper_fd_t *fdp;
  struct timespec ts, *tsp = NULL;
  struct kevent *kev;
  int fd, i, c;

  if((c = dlist_count(read_fds) + dlist_count(write_fds)) >= kevlistlen)
    {
      c += 8;
      if(realloc_wrap((void **)&kevlist, sizeof(struct kevent) * c) != 0)
	{
	  if(kevlistlen == 0)
	    {
	      printerror(errno, strerror, __func__, "could not alloc kevlist");
	      return -1;
	    }
	}
      else
	{
	  kevlistlen = c;
	}
    }

  if(tv != NULL)
    {
      ts.tv_sec  = tv->tv_sec;
      ts.tv_nsec = tv->tv_usec * 1000;
      tsp = &ts;
    }

  if((c = kevent(kq, NULL, 0, kevlist, kevlistlen, tsp)) == -1)
    {
      printerror(errno, strerror, __func__, "kevent failed");
      return -1;
    }

  for(i=0; i<c; i++)
    {
      kev = &kevlist[i];
      fd = kev->ident;

      if(fd < 0 || fd >= fd_array_s)
	continue;
      if((fdp = fd_array[fd]) == NULL)
	continue;
      if(kev->filter == EVFILT_READ)
	fdp->read.cb(fd, fdp->read.param);
      else if(kev->filter == EVFILT_WRITE)
	fdp->write.cb(fd, fdp->write.param);
    }

  return 0;
}
Exemple #11
0
/*  This routine provides simple FITS writer. It uses the routines
 *  provided by the fitsTcl/cfitsio libraries
 *
 *  NOTE : It will fail if the image already exists
 */
int ApogeeAltaManager::saveimage(unsigned short *src_buffer, char *filename, int nx, int ny)
{
	fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */
	long  fpixel, nelements;
	unsigned short *array;
	unsigned short *simg;
	int status;
	/* initialize FITS image parameters */
	int bitpix   =  USHORT_IMG; /* 16-bit unsigned short pixel values       */
	long naxis    =   2;  /* 2-dimensional image                            */
	long naxes[2];

	naxes[0] = nx-bcols;
	naxes[1] = ny;
	array = src_buffer;
	status = 0;         /* initialize status before calling fitsio routines */
	simg = (unsigned short *)CCD_locate_buffer(const_cast<char *>("stemp"),2,nx-bcols,ny,1,1);

	if (fits_create_file(&fptr, filename, &status)) /* create new FITS file */
		printerror( status );           /* call printerror if error occurs */

	/* write the required keywords for the primary array image.     */
	/* Since bitpix = USHORT_IMG, this will cause cfitsio to create */
	/* a FITS image with BITPIX = 16 (signed short integers) with   */
	/* BSCALE = 1.0 and BZERO = 32768.  This is the convention that */
	/* FITS uses to store unsigned integers.  Note that the BSCALE  */
	/* and BZERO keywords will be automatically written by cfitsio  */
	/* in this case.                                                */

	if ( fits_create_img(fptr,  bitpix, naxis, naxes, &status) )
		printerror( status );

	fpixel = 1;                               /* first pixel to write      */
	nelements = naxes[0] * naxes[1];          /* number of pixels to write */

	if (bcols > 0)
	{
		dobiassubtract(src_buffer,simg,naxes[0],naxes[1]);

		/* write the array of unsigned integers to the FITS file */
		if ( fits_write_img(fptr, TUSHORT, fpixel, nelements, simg, &status) )
			printerror( status );
	} else
	{
		/* write the array of unsigned integers to the FITS file */
		if ( fits_write_img(fptr, TUSHORT, fpixel, nelements, src_buffer, &status) )
			printerror( status );
	}

	if ( fits_close_file(fptr, &status) )                /* close the file */
		printerror( status );

	return(status);
}
Exemple #12
0
int execute(char **argv, int argc, char *infile, char*outfile, int bg){
	argv[argc] = NULL;
	int pid;
	int status;
	int saved_out;
	int saved_in;
	int in;
	int out;
	
	if(infile!= NULL){
		saved_in = dup(0);
		in = open(infile, O_RDONLY);
		dup2(in, 0);
		close(in);
	}
	if(outfile){
		saved_out = dup(1);
		out = open(outfile, O_WRONLY | O_TRUNC);
		if(out == -1){
			mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
			creat(outfile,mode);
			out = open(outfile,O_WRONLY | O_TRUNC );
		}
		dup2(out,1);
		close(out);
		
	}

	if((pid = fork()) < 0){
		printerror();
	}				
	else if (pid == 0){//child
		
		if(execvp(*argv,argv) < 0){
			printf("exec\n");
			printerror();
		}
		exit(1);
	}
	else{
		waitpid(-1, &status, 0);
		if (infile){
			close(0);
			dup2(saved_in, 0);
		}
		if (outfile){
			close(1);
			dup2(saved_out,1);
		}
	}	
}
Exemple #13
0
static int addr2mac_add(const int ifindex, const int type, const void *ipraw,
			const void *macraw, const time_t expire)
{
  const int mt = SCAMPER_ADDR_TYPE_ETHERNET;
  scamper_addr_t *mac = NULL;
  scamper_addr_t *ip  = NULL;
  addr2mac_t *addr2mac = NULL;
  char ipstr[128], macstr[128];

  if((ip = scamper_addrcache_get(addrcache, type, ipraw)) == NULL)
    {
      printerror(errno, strerror, __func__, "could not get ip");
      goto err;
    }

  if((mac = scamper_addrcache_get(addrcache, mt, macraw)) == NULL)
    {
      printerror(errno, strerror, __func__, "could not get mac");
      goto err;
    }

  if((addr2mac = addr2mac_alloc(ifindex, ip, mac, expire)) == NULL)
    {
      goto err;
    }

  scamper_addr_free(ip);  ip  = NULL;
  scamper_addr_free(mac); mac = NULL;

  if(splaytree_insert(tree, addr2mac) == NULL)
    {
      printerror(errno, strerror, __func__, "could not add %s:%s to tree",
		 scamper_addr_tostr(addr2mac->ip, ipstr, sizeof(ipstr)),
		 scamper_addr_tostr(addr2mac->mac, macstr, sizeof(macstr)));
      goto err;
    }

  scamper_debug(__func__, "ifindex %d ip %s mac %s expire %d", ifindex,
		scamper_addr_tostr(addr2mac->ip, ipstr, sizeof(ipstr)),
		scamper_addr_tostr(addr2mac->mac, macstr, sizeof(macstr)),
		expire);
  return 0;

 err:
  if(addr2mac != NULL) addr2mac_free(addr2mac);
  if(mac != NULL) scamper_addr_free(mac);
  if(ip != NULL) scamper_addr_free(ip);
  return -1;
}
Exemple #14
0
int main(int argc, char *argv[])
{
    fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */

    int status, nkeys, keypos, hdutype, ii, jj;
    char filename[FLEN_FILENAME];    /* input FITS file */
    char card[FLEN_CARD];   /* standard string lengths defined in fitsioc.h */

    status = 0;

    if (argc == 1)
        strcpy(filename, "-");  /* no command line name, so assume stdin */
    else
        strcpy(filename, argv[1] );   /* name of file to list */


    if ( fits_open_file(&fptr, filename, READONLY, &status) ) 
         printerror( status );

    /* get the current HDU number */
    fits_get_hdu_num(fptr, &ii);

    /* attempt to move to next HDU, until we get an EOF error */
    for (; !(fits_movabs_hdu(fptr, ii, &hdutype, &status) ); ii++) 
    {
        /* get no. of keywords */
        if (fits_get_hdrpos(fptr, &nkeys, &keypos, &status) )
            printerror( status );

        printf("Header listing for HDU #%d:\n", ii);
        for (jj = 1; jj <= nkeys; jj++)  {
            if ( fits_read_record(fptr, jj, card, &status) )
                 printerror( status );

            printf("%s\n", card); /* print the keyword card */
        }
        printf("END\n\n");  /* terminate listing with END */
    }

    if (status == END_OF_FILE)   /* status values are defined in fitsio.h */
        status = 0;              /* got the expected EOF error; reset = 0  */
    else
       printerror( status );     /* got an unexpected error                */

    if ( fits_close_file(fptr, &status) )
         printerror( status );

    return(0);
}
Exemple #15
0
Score MAP::set(int x, int y, OBJECT *obj)
{
   Score ret;
   if (x>=w || y >= h)
      printerror("object set out of map bounds");


   if (obj->idx == OBJ_UNDEFINED)
      printerror("undefined object : %s",obj->name);


   for (int i=0;i<MAX_OBJ_PERTILE;i++)
       if (the_map[x][y][i] == obj)
          return ret; // it was already there
          
   for (int i=0;i<MAX_OBJ_PERTILE;i++)
   {
      if (!(the_map[x][y][i]))
      {
         the_map[x][y][i] = obj;
         if (obj)
         {
          obj->mapx = x;
          obj->mapy = y;
         }
         ret = playfield->someone_arrived(x,y,obj);
         
         wakeup(x-1,y);
         wakeup(x+1,y);
         wakeup(x,y-1);
         wakeup(x,y+1);
         wakeup(x,y); // make sure evrybody here is awake too
         
         return ret;
      }
   }


   allegro_exit();

   for (int i=0;i<MAX_OBJ_PERTILE;i++)
       printf("%s\n",the_map[x][y][i]->name);
   printf("tile overfull\n");
   exit(1);
       
   printerror("tile overfull");

   return ret;
}
Exemple #16
0
int scamper_debug_open(const char *file)
{
  mode_t mode;
  int flags, fd;

#if defined(WITHOUT_PRIVSEP) && !defined(_WIN32)
  uid_t uid = getuid();
#endif

#ifndef _WIN32
  mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
#else
  mode = _S_IREAD | _S_IWRITE;
#endif

  if(scamper_option_debugfileappend() == 0)
    flags = O_WRONLY | O_CREAT | O_TRUNC;
  else
    flags = O_WRONLY | O_CREAT | O_APPEND;

#ifndef WITHOUT_PRIVSEP
  fd = scamper_privsep_open_file(file, flags, mode);
#else
  fd = open(file, flags, mode);
#endif

  if(fd == -1)
    {
      printerror(errno, strerror, __func__,
		 "could not open debugfile %s", file);
      return -1;
    }

  if((debugfile = fdopen(fd, "a")) == NULL)
    {
      printerror(errno, strerror, __func__,
		 "could not fdopen debugfile %s", file);
      return -1;
    }

#if defined(WITHOUT_PRIVSEP) && !defined(_WIN32)
  if(uid != geteuid() && fchown(fd, uid, -1) != 0)
    {
      printerror(errno, strerror, __func__, "could not fchown");
    }
#endif

  return 0;
}
Exemple #17
0
int 
vot_addFITSMeta (int handle, fitsfile *fp, char *meta, int index)
{
    char  *id, *nam, *val, *unit, keyw[SZ_FNAME], comment[SZ_FNAME];
    int   status = 0;


    if ( (id = vot_getAttr (handle, "id")) ) {		/* ID attribute	      */
        memset (keyw, 0, SZ_FNAME);
        memset (comment, 0, SZ_FNAME);
        sprintf (keyw, "%3.3sID%d", meta, index);
        sprintf (comment, "%s id attribute", meta);
        if (fits_update_key (fp, TSTRING, keyw, id, comment, &status))
	    printerror ( status );
    }

    if ( (nam = vot_getAttr (handle, "name")) ) {	/* NAME attribute    */
        memset (keyw, 0, SZ_FNAME);
        memset (comment, 0, SZ_FNAME);
        sprintf (keyw, "%3.3sNAM%d", meta, index);
        sprintf (comment, "%s name attribute", meta);

        if (fits_update_key (fp, TSTRING, keyw, nam, comment, &status))
	    printerror ( status );
    }

    if ( (val = vot_getAttr (handle, "value")) ) {	/* VALUE attribute   */
        memset (keyw, 0, SZ_FNAME);
        memset (comment, 0, SZ_FNAME);
        sprintf (keyw, "%3.3sVAL%d", meta, index);
        sprintf (comment, "%s val attribute", meta);

        if (fits_update_key (fp, TSTRING, keyw, val, comment, &status))
	    printerror ( status );
    }

    if ( (unit = vot_getAttr (handle, "unit")) ) {	/* UNIT attribute   */
        memset (keyw, 0, SZ_FNAME);
        memset (comment, 0, SZ_FNAME);
        sprintf (keyw, "%3.3sUNI%d", meta, index);
        sprintf (comment, "%s unit attribute", meta);

        if (fits_update_key (fp, TSTRING, keyw, unit, comment, &status))
	    printerror ( status );
    }

    return (0);
}
Exemple #18
0
static void firewall_rule_delete(scamper_firewall_entry_t *entry)
{
#if defined(HAVE_IPFW)
  int af;

  if(entry->rule->sfw_5tuple_src->type == SCAMPER_ADDR_TYPE_IPV4)
    af = AF_INET;
  else
    af = AF_INET6;

#ifdef WITHOUT_PRIVSEP
  scamper_firewall_ipfw_del(entry->slot, af);
#else
  scamper_privsep_ipfw_del(entry->slot, af);
#endif
#endif

  /* put the rule back into the freeslots heap */
  if(heap_insert(freeslots, entry) == NULL)
    {
      printerror(errno, strerror, __func__,
		 "could not add entry %d", entry->slot);
      firewall_entry_free(entry);
    }

  /* free up the firewall rule associated with the entry */
  firewall_rule_free(entry->rule);
  entry->rule = NULL;

  return;
}
/*
 * scamper_task_alloc
 *
 * allocate and initialise a task object.
 */
scamper_task_t *scamper_task_alloc(void *data, scamper_task_funcs_t *funcs)
{
  scamper_task_t *task;

  assert(data  != NULL);
  assert(funcs != NULL);

  if((task = malloc_zero(sizeof(scamper_task_t))) == NULL)
    {
      printerror(errno, strerror, __func__, "could not malloc task");
      goto err;
    }

  if((task->queue = scamper_queue_alloc(task)) == NULL)
    goto err;

  if((task->siglist = slist_alloc()) == NULL)
    goto err;

  task->funcs = funcs;
  task->data = data;

  return task;

 err:
  scamper_task_free(task);
  return NULL;
}
Exemple #20
0
/**
 * \brief write a message to a client
 * \param mt is the minstack_tcp stack
 * \param cid is the client ID to whom send the message, if 0 the message is broadcast to the clients
 * \param message is the message
 * \param len_message is the length of the message
 * \return 0 if OK
 */
int minstack_tcp_write_to_client(minstack_tcp *mt, int cid, char *message,
        int len_message) {
    //without cid we send the message to all the clients
    if (!mt) {
        //printerror("the minstack_tcp is NULL\n");
        return -100;
    }
    if (mt->type != SERVER) {
        printwarning("The minstack is not a server...\n");
        return -1;
    }
    if (mt->status != STARTED) {
        printwarning("The server is not started yet\n");
        return -1;
    }
    if (cid)
        return minstack_tcp_write(mt, cid, message, len_message);
    else {
        int i, retval = 0;
        for (i = 0; i < mt->sockets.connected_client_nb; i++) {
            retval = minstack_tcp_write(mt, mt->sockets.client_socket_fd[0],
                    message, len_message);
            if (retval) {
                printerror("We had a problem sending to the client %d\n",i);
                return retval;
            }
        }
    }
    return 0;
}
Exemple #21
0
int scamper_addr2mac_add(int ifindex, scamper_addr_t *ip, scamper_addr_t *mac)
{
  addr2mac_t *a2m = NULL;
  char ipstr[128], macstr[128];

  if(scamper_addr2mac_whohas(ifindex, ip) != NULL)
    return 0;

  if((a2m = addr2mac_alloc(ifindex, ip, mac, 0)) == NULL)
    return -1;

  if(splaytree_insert(tree, a2m) == NULL)
    {
      printerror(errno, strerror, __func__, "could not add %s:%s to tree",
		 scamper_addr_tostr(a2m->ip, ipstr, sizeof(ipstr)),
		 scamper_addr_tostr(a2m->mac, macstr, sizeof(macstr)));
      addr2mac_free(a2m);
      return -1;
    }

  scamper_debug(__func__, "ifindex %d ip %s mac %s", ifindex,
		scamper_addr_tostr(a2m->ip, ipstr, sizeof(ipstr)),
		scamper_addr_tostr(a2m->mac, macstr, sizeof(macstr)));
  return 0;
}
/*
 * get_timeout
 * returns the amount of time that select should block for before returning
 * whether some packets have arrived or not
 */
static int get_timeout(struct timeval *tv)
{
  struct timeval  temp;
  int64_t         min_diff = 1000, temp_diff;

  if(tv == NULL)
    {
      return 0;
    }

  bzero(&temp, sizeof(temp));
  bzero(&tz,   sizeof(tz));
  if(gettimeofday(&temp, &tz) != 0)
    {
      printerror(errno, strerror, "could not gettimeofday");
      return 0;
    }

  if(wait_between > 0)
    {
      temp_diff = timeval_diff_msec(&wait_between_tv, &temp);
      if(temp_diff >= 0 && temp_diff < min_diff) min_diff = temp_diff;
    }

  tv->tv_sec  = 0;
  tv->tv_usec = 0;
  timeval_add(tv, min_diff);

  return 1;
}
Exemple #23
0
OBJECT *MAP::get(int x, int y, int nr)
{
   if (x>=w || y >= h || nr >= MAX_OBJ_PERTILE)
      printerror("object asked out of map bounds");
      
   return the_map[x][y][nr];
}
Exemple #24
0
/*
 * alloc_list
 *
 * helper function to allocate a list for scamper_fds_init
 */
static dlist_t *alloc_list(char *name)
{
  dlist_t *list;
  if((list = dlist_alloc()) == NULL)
    printerror(errno, strerror, __func__, "alloc %s failed", name);
  return list;
}
Exemple #25
0
bool Fits2D::readStringKeyword(string keyword, string &value){

    char *ptr = NULL;

    int status = 0;

    fitsfile *fptr;

    const char * filename;

    char v[40];

    filename = mFitsPath.c_str();


    if(fits_open_file(&fptr, filename, READONLY, &status)){

        printerror(status);
        return false;

    }

    char * key = new char[keyword.length()+1];
    strcpy(key,keyword.c_str());

    if(fits_read_key(fptr, TSTRING, key, v, NULL, &status)){


        printerror(status);
        delete key;
        return false;

    }

    value = string(v);

    delete key;

    if(fits_close_file(fptr, &status)){

        printerror(status);
        return false;

    }

    return true;
}
static int open_ipmp_sockets4()
{
  char      addr[128];
  struct    sockaddr_in *sin;

#if defined(__FreeBSD__)
  int    mib[]  = {CTL_NET, PF_INET, IPPROTO_IP, IPCTL_DEFTTL};
  u_int  miblen = 4;
  size_t len    = sizeof(ipv4_ttl);
#elif defined(__linux__)
  int    mib[]  = {CTL_NET, NET_IPV4, NET_IPV4_DEFAULT_TTL};
  u_int  miblen = 3;
  size_t len    = sizeof(ipv4_ttl);
#endif

  ipmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_IPMP);
  if(ipmp_sock == -1)
    {
      printerror(errno, strerror, "could not open IPMP IPv4 raw socket");
      return 0;
    }

  if((options & OPT_SRCADDR) && source->sa_family == AF_INET)
    {
      if(bind(ipmp_sock, source, sizeof(struct sockaddr_in)) == -1)
	{
	  sin = (struct sockaddr_in *)source;
	  inet_ntop(AF_INET, &sin->sin_addr, addr, sizeof(addr));

	  printerror(errno, strerror, "could not bind to %s", addr);
	  return 0;
	}
    }

#if defined(__NetBSD__)
  ipv4_ttl = 255;
#else
  if(sysctl(mib, miblen, &ipv4_ttl, &len, NULL, 0) == -1)
    {
      printerror(errno, strerror, "could not find out default ipv4 ttl");
      return 0;
    }
#endif

  return 1;
}
Exemple #27
0
/**
 * \brief Write the message with the length len_message to the cid
 * \param mt is the minstack_tcp stack
 * \param cid is the client ID to whom send the message
 * \param message the message to send
 * \param len_message the message length
 * \return 0 if the minstack_tcp stack stopped correctly
 */
int minstack_tcp_write(minstack_tcp *mt, int cid, char *message, int len_message) {
    if (!mt) {
        printerror("the minstack_tcp is NULL\n");
        return -100;
    }
    //if (write(cid, message, len_message) < 0) {
    if(send(cid, message, len_message,0) < 0){
#ifdef WIN32
    	printerror("ERROR writing to socket %d with erro :%d\n",cid,WSAGetLastError());
#else
        printerror("ERROR writing to socket %d\n",cid);
#endif
        return -1;
    }
    printmessage("%s sent:%s length:%d to cid:%d\n",mt->name,message,len_message,cid);
    return 0;
}
Exemple #28
0
unsigned char reladr(int aadr) {
    int result;

    result=aadr-(codeorig+destadr+2);
    if(result<-128 || result>127)
        printerror("Address out of range for branch instruction");
    return(result&0xFF);
}
Exemple #29
0
int read_key(char filename[], char keyword[], char value[], char type[],
		char comment[])
{
 fitsfile *fptr;
 int status=0;
 int datatype;
 unsigned short usvalue;
 int ivalue;
 float fvalue;
 double dvalue;

 /* transform type to cfitsio code */
 datatype = get_type(type);

 /* open FITS file */
 if ( fits_open_file(&fptr, filename, READONLY, &status) )
 	printerror( status );

 /* read entry */
 switch (datatype) {
   case TSTRING:
   	if ( fits_read_key(fptr, datatype, keyword, value, comment, &status) )
		printerror( status );
	break;
   case TUSHORT:
   	if ( fits_read_key(fptr, datatype, keyword, &usvalue, comment, &status) )
		printerror( status );
	sprintf(value,"%d",usvalue);
	break;
   case TINT:
   	if ( fits_read_key(fptr, datatype, keyword, &ivalue, comment, &status) )
		printerror( status );
	sprintf(value,"%d",ivalue);
	break;
   case TFLOAT:
   	if ( fits_read_key(fptr, datatype, keyword, &fvalue, comment, &status) )
		printerror( status );
	sprintf(value,"%f",fvalue);
	break;
   case TDOUBLE:
   	if ( fits_read_key(fptr, datatype, keyword, &dvalue, comment, &status) )
		printerror( status );
	sprintf(value,"%lf",dvalue);
	break;
   default:
   	printerror( BAD_DATATYPE );
	break;
 }

 /* close FITS file */
 if ( fits_close_file(fptr, &status) )
 	printerror( status );

 return(0);
}
Exemple #30
0
void push(int value)
{
	array[stacksize]= value;
	stacksize = stacksize + 1;
	if(stacksize > SIZE)
	{
		printerror("Stack Overflow");
	}
}