示例#1
0
/*
 * Drop a tcp connection.
 */
int
main(int argc, char *argv[])
{
	char *lport, *fport;
	bool dropall;
	int ch;

	dropall = false;

	while ((ch = getopt(argc, argv, "al")) != -1) {
		switch (ch) {
		case 'a':
			dropall = true;
			break;
		case 'l':
			tcpdrop_list_commands = true;
			break;
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (dropall) {
		if (argc != 0)
			usage();
		if (!tcpdropall())
			exit(1);
		exit(0);
	}

	if ((argc != 2 && argc != 4) || tcpdrop_list_commands)
		usage();

	if (argc == 2) {
		lport = findport(argv[0]);
		fport = findport(argv[1]);
		if (lport == NULL || lport[1] == '\0' || fport == NULL ||
		    fport[1] == '\0')
			usage();
		*lport++ = '\0';
		*fport++ = '\0';
		if (!tcpdropbyname(argv[0], lport, argv[1], fport))
			exit(1);
	} else if (!tcpdropbyname(argv[0], argv[1], argv[2], argv[3]))
		exit(1);

	exit(0);
}
示例#2
0
/* Translate all depends from names into PORT *s */
static void
translateport(PORT ** pp, size_t pplen, PORT * p)
{
	size_t i;

	for (i = 0; i < p->n_edep; i++)
		p->edep[i].p = findport(pp, 0, pplen, p->edep[i].name, p->portdir);
	for (i = 0; i < p->n_pdep; i++)
		p->pdep[i].p = findport(pp, 0, pplen, p->pdep[i].name, p->portdir);
	for (i = 0; i < p->n_fdep; i++)
		p->fdep[i].p = findport(pp, 0, pplen, p->fdep[i].name, p->portdir);
	for (i = 0; i < p->n_bdep; i++)
		p->bdep[i].p = findport(pp, 0, pplen, p->bdep[i].name, p->portdir);
	for (i = 0; i < p->n_rdep; i++)
		p->rdep[i].p = findport(pp, 0, pplen, p->rdep[i].name, p->portdir);
}
示例#3
0
文件: dbf.c 项目: hailynch/jnos2
int dbf_fields(int s, char *file, int OF)
{
   FILE *f;
   dbf_header dbfinfo;
   int i,port;
   char *p,Gdir[64];

   output_format = OF;        /* ASCIITEXT or CSOTEXT */

   p = j2strdup(file);
   if (p == NULL)
   {
     tprintf("j2strdup() failed: dbf_fields()\n");
     return 0;
   }

   /* open the file */
   if ((f = fopen(file, "rb")) == NULL)
   {
     tprintf("Cannot open file.\n");
     return(1);
   }

   /* get info from the file header */
   dbf_getheader(f, &dbfinfo);

   /* fill field info structure */
   dbf_getfields(f, &dbfinfo);

   gnamefix(s,p);
   for (i=1; i<=dbfinfo.nflds; i++)
   {
      if (output_format == CSOTEXT)
      {
	 usprintf(s, "-200:%d:%s:max %d Indexed Lookup Public Default",
			  i, fields[i].name, fields[i].length);

	  usputc(s, 10);
	 usprintf(s, "-200:%d:%s:%s.",
			  i, fields[i].name, fields[i].name);
	 usputc(s, 10);
      }
      else
      {
	port = findport(s,Gdir,'g');
	usprintf(s, "7%s\tq%s~%s\t%s\t%u\n",
		 fields[i].name, p, fields[i].name, Hostname,port);
      }
   }
   free(p);
   fclose(f);

   return 0;
}
示例#4
0
/* Translate a port directory name into a (PORT *), and free the name */
static PORT *
findport(PORT ** pp, size_t st, size_t en, char * name, char * from)
{
	size_t mid;
	int r;

	if (st == en)
		errx(1, "%s: no entry for %s", from, name);

	mid = (st + en) / 2;
	r = portcompare(pp[mid]->portdir, name);

	if (r == 0) {
		free(name);
		return pp[mid];
	} else if (r < 0)
		return findport(pp, mid + 1, en, name, from);
	else
		return findport(pp, st, mid, name, from);
}
示例#5
0
/*! This is the sensor process, it takes a simulated input ( a keyboard press )
    and passes it to the Light control process via IPC
 */
void
main(int argc, char* argv[]) {
    long send_port;

    if (ALL_OK != createprocess(1)) {
        printat(MAIN_DEBUG_LINE, 0, 
		"Sensor control: createprocess of Light control failed.\n");
        return;
    }

    // Locating the send port of the light control process
    send_port = findport(0, 1);
    if (send_port < 0) {
        printat(MAIN_DEBUG_LINE, 0, 
		"Sensor control: findport() failed (Light control) ");
        return;
    }

    printat(0, 0, "Welcome to VRTTCS (very realtime traffic control system)");
    printat(MAIN_DEBUG_LINE, 0, "Sensor control: ");

    while (1) {
        register long scan_code = getscancode();
        if (0x1c == scan_code) {
            struct message msg;
            printat(MAIN_DEBUG_LINE, 0, "Sensor control: Got sensor input");
            if (ALL_OK != send(send_port, &msg)) {
                printat(MAIN_DEBUG_LINE, 0, 
			"Sensor control: send() failed");
                return;
            } else {
                /* We let the debug message display some time*/
                pause(500);
                printat(MAIN_DEBUG_LINE, 0, "Sensor control:                                 ");
            }
        }
    }
}