コード例 #1
0
ファイル: netcat.c プロジェクト: jezze/fudge
void main(void)
{

    struct ctrl_conheader header;
    char buffer[FUDGE_BSIZE];
    struct ipv4_arpentry entry;
    struct ipv4_socket socket;

    if (!file_walk(FILE_L0, "/system/ethernet/ipv4/arptable"))
        return;

    file_open(FILE_L0);
    file_readall(FILE_L0, &entry, sizeof (struct ipv4_arpentry));
    file_close(FILE_L0);

    socket.address[0] = entry.paddress[0];
    socket.address[1] = entry.paddress[1];
    socket.address[2] = entry.paddress[2];
    socket.address[3] = entry.paddress[3];
    socket.port[0] = 0x1F;
    socket.port[1] = 0x90;

    if (!file_walk(FILE_L0, "/system/con/con:0"))
        return;

    if (!file_walkfrom(FILE_L1, FILE_L0, "ctrl"))
        return;

    file_open(FILE_L1);
    file_writeall(FILE_L1, &socket, sizeof (struct ipv4_socket));
    file_close(FILE_L1);

    if (!file_walkfrom(FILE_L1, FILE_L0, "data"))
        return;

    file_open(FILE_PO);
    file_open(FILE_L1);

    while (file_readall(FILE_L1, &header, sizeof (struct ctrl_conheader)))
    {

        file_readall(FILE_L1, buffer, header.count);
        file_writeall(FILE_PO, buffer, header.count);
        send(&socket, &header.sender, "ack\n", 4);

    }

    file_close(FILE_L1);
    file_close(FILE_PO);

}
コード例 #2
0
ファイル: initnet.c プロジェクト: jezze/fudge
void main(void)
{

    struct ipv4_arpentry entry;

    if (!file_walk2(FILE_L0, "/system/ethernet/if:0/addr"))
        return;

    file_open(FILE_L0);
    file_readall(FILE_L0, &entry.haddress, 6);
    file_close(FILE_L0);

    entry.paddress[0] = 10;
    entry.paddress[1] = 0;
    entry.paddress[2] = 5;
    entry.paddress[3] = entry.haddress[4];

    if (!file_walk2(FILE_L0, "/system/ethernet/ipv4/arptable"))
        return;

    file_open(FILE_L0);
    file_writeall(FILE_L0, &entry, sizeof (struct ipv4_arpentry));
    file_close(FILE_L0);

}
コード例 #3
0
ファイル: ls.c プロジェクト: jezze/fudge
static void list(struct event_channel *channel, unsigned int descriptor)
{

    struct record record;

    file_open(descriptor);
    event_reply(channel, EVENT_DATA);

    while (file_readall(descriptor, &record, sizeof (struct record)))
    {

        if (event_avail(&channel->o) < record.length + 1)
        {

            event_place(channel->o.header.target, &channel->o);
            event_reset(&channel->o);

        }

        event_append(&channel->o, record.length, record.name);
        event_append(&channel->o, 1, "\n");

        if (!file_step(descriptor))
            break;

    }

    event_place(channel->o.header.target, &channel->o);
    file_close(descriptor);

}
コード例 #4
0
ファイル: mbr.c プロジェクト: jezze/fudge
void main(void)
{

    struct mbr mbr;
    unsigned int i;

    file_open(FILE_PI);
    file_readall(FILE_PI, &mbr, 512);
    file_close(FILE_PI);

    if (mbr.signature[0] != 0x55 || mbr.signature[1] != 0xAA)
        return;

    file_open(FILE_PO);

    for (i = 0; i < 4; i++)
    {

        unsigned int start = (mbr.partition[i].sectorlba[3] << 24) | (mbr.partition[i].sectorlba[2] << 16) | (mbr.partition[i].sectorlba[1] << 8) | (mbr.partition[i].sectorlba[0]);
        unsigned int sectors = (mbr.partition[i].sectortotal[3] << 24) | (mbr.partition[i].sectortotal[2] << 16) | (mbr.partition[i].sectortotal[1] << 8) | (mbr.partition[i].sectortotal[0]);
        unsigned int cstart = mbr.partition[i].cylinderbase | ((mbr.partition[i].sectorbase & 0xC0) << 8);
        unsigned int cend = mbr.partition[i].cylinderlimit | ((mbr.partition[i].sectorlimit & 0xC0) << 8);
        unsigned int hstart = mbr.partition[i].headbase;
        unsigned int hend = mbr.partition[i].headlimit;
        unsigned int sstart = mbr.partition[i].sectorbase & 0x2F;
        unsigned int send = mbr.partition[i].sectorlimit & 0x2F;
        char data[64];
        unsigned int count;

        write_keydec(FILE_PO, "Partition", i);

        if (!mbr.partition[i].systemid)
            continue;

        write_keyhex(FILE_PO, "    Boot", mbr.partition[i].boot);
        write_keyhex(FILE_PO, "    Id", mbr.partition[i].systemid);
        write_keydec(FILE_PO, "    Start", start);
        write_keydec(FILE_PO, "    End", start + sectors - 1);
        write_keydec(FILE_PO, "    Sectors", sectors);

        count = 0;
        count += ascii_wvalue(data + count, 64, cstart, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, hstart, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, sstart, 10);

        write_keybuffer(FILE_PO, "    Start-C/H/S", data, count);

        count = 0;
        count += ascii_wvalue(data + count, 64, cend, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, hend, 10);
        count += memory_write(data, 64, "/", 1, count);
        count += ascii_wvalue(data + count, 64, send, 10);

        write_keybuffer(FILE_PO, "    End-C/H/S", data, count);

    }

    file_close(FILE_PO);

}
コード例 #5
0
ファイル: spawn.c プロジェクト: Gujs/tvheadend
int
spawn_and_store_stdout(const char *prog, char *const argv[], char **outp)
{
  pid_t p;
  int fd[2], f;
  const char *local_argv[2];

  if(argv == NULL) {
    local_argv[0] = prog;
    local_argv[1] = NULL;
    argv = (void *)local_argv;
  }

  pthread_mutex_lock(&fork_lock);

  if(pipe(fd) == -1) {
    pthread_mutex_unlock(&fork_lock);
    return -1;
  }

  p = fork();

  if(p == -1) {
    pthread_mutex_unlock(&fork_lock);
    syslog(LOG_ERR, "spawn: Unable to fork() for \"%s\" -- %s",
	   prog, strerror(errno));
    return -1;
  }

  if(p == 0) {
    close(0);
    close(2);
    close(fd[0]);
    dup2(fd[1], 1);
    close(fd[1]);

    f = open("/dev/null", O_RDWR);
    if(f == -1) {
      syslog(LOG_ERR, 
	     "spawn: pid %d cannot open /dev/null for redirect %s -- %s",
	     getpid(), prog, strerror(errno));
      exit(1);
    }

    dup2(f, 0);
    dup2(f, 2);
    close(f);

    execve(prog, argv, environ);
    syslog(LOG_ERR, "spawn: pid %d cannot execute %s -- %s",
	   getpid(), prog, strerror(errno));
    exit(1);
  }

  pthread_mutex_unlock(&fork_lock);

  spawn_enq(prog, p);

  close(fd[1]);

  return file_readall(fd[0], outp);
}
コード例 #6
0
ファイル: xmltv.c プロジェクト: InuSasha/tvheadend
static void _xmltv_load_grabbers ( void )
{
  int outlen = -1, rd = -1;
  size_t i, p, n;
  char *outbuf;
  char name[1000];
  char *tmp, *tmp2 = NULL, *path;

  /* Load data */
  if (spawn_and_give_stdout(XMLTV_FIND, NULL, NULL, &rd, NULL, 1) >= 0)
    outlen = file_readall(rd, &outbuf);
  if (rd >= 0)
    close(rd);

  /* Process */
  if ( outlen > 0 ) {
    p = n = i = 0;
    while ( i < outlen ) {
      if ( outbuf[i] == '\n' || outbuf[i] == '\0' ) {
        outbuf[i] = '\0';
        sprintf(name, "XMLTV: %s", &outbuf[n]);
        epggrab_module_int_create(NULL, NULL, &outbuf[p], name, 3, &outbuf[p],
                                  NULL, _xmltv_parse, NULL, NULL);
        p = n = i + 1;
      } else if ( outbuf[i] == '\\') {
        memmove(outbuf, outbuf + 1, strlen(outbuf));
        if (outbuf[i])
          i++;
        continue;
      } else if ( outbuf[i] == '|' ) {
        outbuf[i] = '\0';
        n = i + 1;
      }
      i++;
    }
    free(outbuf);

  /* Internal search */
  } else if ((tmp = getenv("PATH"))) {
    tvhdebug("epggrab", "using internal grab search");
    char bin[256];
    char *argv[] = {
      NULL,
      (char *)"--description",
      NULL
    };
    path = strdup(tmp);
    tmp  = strtok_r(path, ":", &tmp2);
    while (tmp) {
      DIR *dir;
      struct dirent *de;
      struct stat st;
      if ((dir = opendir(tmp))) {
        while ((de = readdir(dir))) {
          if (strstr(de->d_name, XMLTV_GRAB) != de->d_name) continue;
          snprintf(bin, sizeof(bin), "%s/%s", tmp, de->d_name);
          if (epggrab_module_find_by_id(bin)) continue;
          if (stat(bin, &st)) continue;
          if (!(st.st_mode & S_IEXEC)) continue;
          if (!S_ISREG(st.st_mode)) continue;
          rd = -1;
          if (spawn_and_give_stdout(bin, argv, NULL, &rd, NULL, 1) >= 0 &&
              (outlen = file_readall(rd, &outbuf)) > 0) {
            close(rd);
            if (outbuf[outlen-1] == '\n') outbuf[outlen-1] = '\0';
            snprintf(name, sizeof(name), "XMLTV: %s", outbuf);
            epggrab_module_int_create(NULL, NULL, bin, name, 3, bin,
                                      NULL, _xmltv_parse, NULL, NULL);
            free(outbuf);
          } else {
            if (rd >= 0)
              close(rd);
          }
        }
        closedir(dir);
      }
      tmp = strtok_r(NULL, ":", &tmp2);
    }
    free(path);
  }
}
コード例 #7
0
ファイル: way.c プロジェクト: timechanges/GitHub_08
void way_add_arb(LIST_T*head)
{
	int get,count;
	FILE*stt_fp,*way_fp;
	LIST_T*stt_head;
	STT_T*stt_data;
	char str=' ';
	WAY_T*data,*fdata,*ldata;
	char filename[15]=" ";
	int sum=list_count(head);
	stt_head=list_init();
	stt_fp=file_open("station.txt");
	file_readall(stt_fp,stt_head,ISTT);
	data=(WAY_T*)malloc(IWAY);
	memset(data,0,IWAY);
	fdata=(WAY_T*)malloc(IWAY);
	memset(fdata,0,IWAY);
	ldata=(WAY_T*)malloc(IWAY);
	memset(ldata,0,IWAY);
	while(1)
	{
		count=way_printpage(head);
		if (count==27)
		{
			return;
		}
		if (count==sum)
		{
			gotoXY(18,16);
			printf("不能在终点站后插入站点");
			Sleep(1000);
			continue;
		}
		fdata=list_search_count(count,head);
		ldata=list_search_count(count+1,head);
		break;
	}
	data->tickctnum=((WAY_T*)(head->pnext->data))->tickctnum;
	print_way_add();	
	strcpy(data->id,((WAY_T*)(head->pnext->data))->id);
	while(1)
	{
		gotoXY(26,3);
		get=glb_putString(data->stt,4,10,1);
		if(get==27)
		{
			return ;
		}
		if(list_search_name(data->stt,head,way_sttmatch)!=NULL)
		{
			gotoXY(20,20);
			printf("该车次已有该站点");
			Sleep(1000);
			gotoXY(20,20);
			printf("          ");
			gotoXY(26,3);
			printf("          ");
			continue;
		}
		else if(list_search_name(data->stt,stt_head,stt_namematch)==NULL)
		{
			gotoXY(20,20);
			printf("没有该站点");
			Sleep(1000);
			gotoXY(20,20);
			printf("          ");
			gotoXY(26,3);
			printf("          ");
			continue;
		}
		else if (list_search_name(data->stt,head,way_sttmatch)!=NULL)
		{
			gotoXY(20,20);
			printf("该站点已经在该车次中出现");
			Sleep(1000);
			gotoXY(20,20);
			printf("                         ");
			gotoXY(26,3);
			printf("          ");
			continue;

		}
		else
		{
			break;
		}
	
	}
	while (1)
	{
		gotoXY(26,5);
		get=glb_putTime(data->btime);
		if(get==27)
		{
			return ;
		}
		gotoXY(26,7);
		get=glb_putTime(data->etime);
		if(get==27)
		{
			return ;
		}
		if(!(trn_usetime(data->btime,fdata->etime)<0&&trn_usetime(ldata->btime,data->etime)<0))
		{
			gotoXY(17,17);
			printf("该时间不合法");	
			Sleep(1000);
			gotoXY(17,17);
			printf("            ");
			gotoXY(26,5);
			printf("        ");
			gotoXY(26,7);
			printf("        ");
			continue;
		}
		break ;
	}
	data->usetime=trn_usetime(data->btime,data->etime);
	gotoXY(26,9);
	printf("%d:%d",data->usetime/60,data->usetime%60);
	while (1)
	{	
		gotoXY(26,11);
		get=data->distance=glb_putNumber(4);
		if(get==0)
		{
			return ;
		}
		if(!(data->distance>fdata->distance&&data->distance<ldata->distance))
		{
			gotoXY(17,17);
			printf("该里程不合法");	
			Sleep(1000);
			gotoXY(17,17);
			printf("            ");
			gotoXY(26,11);
			printf("        ");
			continue;
		}
		break;
	}
	gotoXY(26,13);
	data->price=data->distance*1.2;
	printf("%.2f",data->price);
	list_add_count(head,count,data);
	gotoXY(20,18);
	printf("成功增加途径站点");
	sprintf(filename,"%s.txt",((WAY_T*)(head->pnext->data))->id);
	file_writeall(head,IWAY,filename);
	way_fp=file_open(filename);
	fclose(way_fp);
	stt_data=list_search_name(data->stt,stt_head,stt_search);
	stt_data->isdelete++;
	file_writeall(stt_head,ISTT,"station.txt");
	fclose(stt_fp);
	Sleep(1000);
	return ;
}