Esempio n. 1
0
int sr_send_packet(struct sr_instance* sr /* borrowed */, 
                         uint8_t* buf /* borrowed */ ,
                         unsigned int len, 
                         const char* iface /* borrowed */)
{
    c_packet_header *sr_pkt;
    unsigned int total_len =  len + (sizeof(c_packet_header));

    /* REQUIRES */
    assert(sr);
    assert(buf);
    assert(iface);

    /* don't waste my time ... */
    if ( len < sizeof(struct sr_ethernet_hdr) )
    {
        fprintf(stderr , "** Error: packet is wayy to short \n");
        return -1;
    }

    /* Create packet */
    sr_pkt = (c_packet_header *)malloc(len +
            sizeof(c_packet_header));
    assert(sr_pkt);
    sr_pkt->mLen  = htonl(total_len);
    sr_pkt->mType = htonl(VNSPACKET);
    strncpy(sr_pkt->mInterfaceName,iface,16);
    memcpy(((uint8_t*)sr_pkt) + sizeof(c_packet_header),
            buf,len);

    /* -- log packet -- */
    sr_log_packet(sr,buf,len);
    printf("\n<<<< Sending packet of length %d \n",len);
    dump_raw(buf,len);

    if ( ! sr_ether_addrs_match_interface( sr, buf, iface) )
    {
        fprintf( stderr, "*** Error: problem with ethernet header, check log\n");
        free ( sr_pkt );
        return -1; 
    }

    if( write(sr->sockfd, sr_pkt, total_len) < total_len ) 
    {
        fprintf(stderr, "Error writing packet\n");
        free(sr_pkt);
        return -1;
    }

    free(sr_pkt);

    return 0;
} /* -- sr_send_packet -- */
Esempio n. 2
0
//dump_raw wrapper
int syn_dump_raw(
    const char* fname,
    int width,
    int depth,
    const svOpenArrayHandle red,
    const svOpenArrayHandle green,
    const svOpenArrayHandle blue)
{

  int i;
  unsigned  char  *red_arry_ptr;
  unsigned  char  *green_arry_ptr;
  unsigned  char  *blue_arry_ptr;

  printf("[syn_dump_raw] fname : %s\twidth : %1d\tdepth : %1d\n",fname,width,depth);

  red_arry_ptr    = malloc((width*depth)*sizeof(unsigned char));
  green_arry_ptr  = malloc((width*depth)*sizeof(unsigned char));
  blue_arry_ptr   = malloc((width*depth)*sizeof(unsigned char));

  //Convert from svOpenArrayHandle type to unsigned char type
  for (i= svLeft(red,1); i <= svRight(red,1); i++) {
      red_arry_ptr[i] = *(unsigned char*)svGetArrElemPtr1(red, i);
  }
  
  for (i= svLeft(green,1); i <= svRight(green,1); i++) {
      green_arry_ptr[i] = *(unsigned char*)svGetArrElemPtr1(green, i);
  }

  for (i= svLeft(blue,1); i <= svRight(blue,1); i++) {
      blue_arry_ptr[i] = *(unsigned char*)svGetArrElemPtr1(blue, i);
  }


  return  dump_raw(
                    fname,
                    width,
                    depth,
                    red_arry_ptr,
                    green_arry_ptr,
                    blue_arry_ptr
                  );

}
Esempio n. 3
0
int dump_roms(byte **rom, int nroms, int abits, int fmt)
{
  char fname[MAXFILENAME];
  int ix;
  FILE *ofp;
  unsigned int romsize = (1 << abits);

  fprintf(stderr, "%d ROM images to be written, %u bytes per image\n",
          nroms, romsize);

  for(ix = 0; ix < nroms; ix++) {
    if(rom[ix] != NULL) {
      sprintf(fname, g_ftmpl, ix);

      if((ofp = fopen(fname, "w")) == NULL) {
        fprintf(stderr, "Unable to open output file '%s' for writing\n",
                fname);
        return 0;
      }

      fprintf(stderr, "Writing ROM #%d to file '%s'\n", ix, fname);
      switch(fmt) {
      case BINARY_FMT:
        dump_raw(rom[ix], romsize, ofp);
        break;
      case TEXT_FMT:
        dump_text(rom[ix], romsize, ofp);
        break;
      default:
        dump_intel(rom[ix], romsize, ofp);
        break;
      }
      fclose(ofp);
    }
  }

  return 1;

} /* end dump_roms() */
Esempio n. 4
0
/*
 * Style: 0 = auto
 *       -1 = hex
 *       -2 = raw
 *       +? = that format number
 */
int dumpABIBlock(abi_index_t *ind, int style, int separator, int date_sep,
		 int line_sep) {
    if (style == -2) {
	dump_raw(ind->data, ind->size);
    } else {
	int hex = (style == -1);

	/*
	 * Guess some style. PBAS, APrX, MODL etc are type 2 (1-byte char),
	 * but are really strings. Conversly PCON is also type 2 and is a
	 * series of numbers.
	 */
	if (style == 0 && ind->format == 2) {
	    int i;
	    for (i = 0; i < ind->size; i++)
		if (!(isprint(ind->data[i]) || isspace(ind->data[i])))
		    break;
	    if (i == ind->size)
		style = 19; /* C-string */
	}


	if (style <= 0)
	    style = ind->format;

	switch(style) {
	case 2:
	    dump_int1(ind->data, ind->size, hex, separator);
	    break;
	    
	case 4:
	    dump_int2(ind->data, ind->size, hex, separator);
	    break;
	    
	case 5:
	    dump_int4(ind->data, ind->size, hex, separator);
	    break;
	    
	case 7:
	    dump_float(ind->data, ind->size, hex, separator);
	    break;
	    
	case 8:
	    dump_double(ind->data, ind->size, hex, separator);
	    break;
	    
	case 10:
	    dump_date(ind->data, ind->size, hex, separator, date_sep);
	    break;
	    
	case 11:
	    dump_time(ind->data, ind->size, hex, separator, date_sep);
	    break;
	    
	case 18:
	    dump_pstr(ind->data, ind->size, hex, separator);
	    break;
	    
	case 19:
	    dump_cstr(ind->data, ind->size, hex, separator);
	    break;
	    
	default:
	    /* Default to hex dump for unknown ones */
	    dump_int1(ind->data, ind->size, 1, separator);
	    break;
	}
    }

    if (separator != '\n')
	putchar(line_sep);

    return 0;
}