コード例 #1
0
/*
 * Send file(s).
 */
void
put(int argc, char *argv[])
{
	int fd;
	register int n;
	register char *ccp, *targ;

	if (argc < 2) {
		strcpy(line, "send ");
		printf("(file) ");
		fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin);
		makeargv();
		argc = margc;
		argv = margv;
	}
	if (argc < 2) {
		putusage(argv[0]);
		return;
	}
	targ = argv[argc - 1];
	if (index(argv[argc - 1], ':')) {
		char *cp;
		struct hostent *hp;

		for (n = 1; n < argc - 1; n++)
			if (index(argv[n], ':')) {
				putusage(argv[0]);
				return;
			}
		cp = argv[argc - 1];
		targ = index(cp, ':');
		*targ++ = 0;
		hp = gethostbyname(cp);
		if (hp == NULL) {
			fprintf(stderr, "tftp: %s: ", cp);
			herror((char *)NULL);
			return;
		}
		if (hp->h_length > (int)sizeof(s_inn.sin_addr)) {
			hp->h_length = sizeof(s_inn.sin_addr);
		}
		memcpy(&s_inn.sin_addr, hp->h_addr, hp->h_length);
		s_inn.sin_family = hp->h_addrtype;
		connected = 1;
		strncpy(hostname, hp->h_name, sizeof(hostname));
		hostname[sizeof(hostname)-1] = 0;
	}
	if (!connected) {
		printf("No target machine specified.\n");
		return;
	}
	if (argc < 4) {
		ccp = argc == 2 ? tail(targ) : argv[1];
		fd = open(ccp, O_RDONLY);
		if (fd < 0) {
			fprintf(stderr, "tftp: "); 
			perror(ccp);
			return;
		}
		if (verbose)
			printf("putting %s to %s:%s [%s]\n",
				ccp, hostname, targ, mode);
		s_inn.sin_port = port;
		sendfile(fd, targ, mode);
		return;
	}
				/* this assumes the target is a directory */
				/* on a remote unix system.  hmmmm.  */
	ccp = targ+strlen(targ);
	*ccp++ = '/';
	for (n = 1; n < argc - 1; n++) {
		strcpy(ccp, tail(argv[n]));
		fd = open(argv[n], O_RDONLY);
		if (fd < 0) {
			fprintf(stderr, "tftp: "); perror(argv[n]);
			continue;
		}
		if (verbose)
			printf("putting %s to %s:%s [%s]\n",
				argv[n], hostname, targ, mode);
		s_inn.sin_port = port;
		sendfile(fd, targ, mode);
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: darksoul42/bitrig
/*
 * Send file(s).
 */
void
put(int argc, char *argv[])
{
	int	 fd;
	int	 n;
	char	*cp, *targ;

	if (argc < 2) {
		strlcpy(line, "put ", sizeof(line));
		printf("(file) ");
		readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin);
		if (makeargv())
			return;
		argc = margc;
		argv = margv;
	}
	if (argc < 2) {
		putusage(argv[0]);
		return;
	}
	targ = argv[argc - 1];
	if (strrchr(argv[argc - 1], ':')) {

		for (n = 1; n < argc - 1; n++)
			if (strchr(argv[n], ':')) {
				putusage(argv[0]);
				return;
			}
		cp = argv[argc - 1];
		targ = strrchr(cp, ':');
		*targ++ = 0;
		if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') {
			cp[strlen(cp) - 1] = '\0';
			cp++;
		}
		setpeer(cp, NULL);
	}
	if (!connected) {
		printf("No target machine specified.\n");
		return;
	}
	if (argc < 4) {
		cp = argc == 2 ? tail(targ) : argv[1];
		fd = open(cp, O_RDONLY);
		if (fd < 0) {
			warn("open: %s", cp);
			return;
		}
		if (verbose)
			printf("putting %s to %s:%s [%s]\n",
			    cp, hostname, targ, mode);
		sendfile(fd, targ, mode);
		return;
	}

	/*
	 * this assumes the target is a directory on
	 * on a remote unix system.  hmmmm.
	 */
	for (n = 1; n < argc - 1; n++) {
		if (asprintf(&cp, "%s/%s", targ, tail(argv[n])) == -1)
			err(1, "asprintf");
		fd = open(argv[n], O_RDONLY);
		if (fd < 0) {
			warn("open: %s", argv[n]);
			free(cp);
			continue;
		}
		if (verbose)
			printf("putting %s to %s:%s [%s]\n",
			    argv[n], hostname, cp, mode);
		sendfile(fd, cp, mode);
		free(cp);
	}
}
コード例 #3
0
ファイル: tftp.c プロジェクト: DanielMSchmidt/it-sec
/*
 * Send file(s).
 */
void
put (int argc, char *argv[])
{
  int fd;
  register int n;
  register char *cp, *targ;

  if (argc < 2)
    get_args ("send", "(file) ", &argc, &argv);

  if (argc < 2)
    {
      putusage (argv[0]);
      return;
    }
  targ = argv[argc - 1];
  if (strchr (argv[argc - 1], ':'))
    {
      char *cp;

      for (n = 1; n < argc - 1; n++)
	if (strchr (argv[n], ':'))
	  {
	    putusage (argv[0]);
	    return;
	  }
      cp = argv[argc - 1];
      targ = strchr (cp, ':');
      *targ++ = 0;
      if (resolve_name (cp, 0) != RESOLVE_OK)
	return;
    }
  if (!connected)
    {
      printf ("No target machine specified.\n");
      return;
    }
  if (argc < 4)
    {
      cp = argc == 2 ? tail (targ) : argv[1];
      fd = open (cp, O_RDONLY);
      if (fd < 0)
	{
	  fprintf (stderr, "tftp: ");
	  perror (cp);
	  return;
	}
      if (verbose)
	printf ("putting %s to %s:%s [%s]\n", cp, hostname, targ, mode);
      peeraddr.sin_port = port ? port : sp->s_port;
      send_file (fd, targ, mode);
      return;
    }
  /* this assumes the target is a directory */
  /* on a remote unix system.  hmmmm.  */
  cp = strchr (targ, '\0');
  *cp++ = '/';
  for (n = 1; n < argc - 1; n++)
    {
      strcpy (cp, tail (argv[n]));
      fd = open (argv[n], O_RDONLY);
      if (fd < 0)
	{
	  fprintf (stderr, "tftp: ");
	  perror (argv[n]);
	  continue;
	}
      if (verbose)
	printf ("putting %s to %s:%s [%s]\n", argv[n], hostname, targ, mode);
      peeraddr.sin_port = port ? port : sp->s_port;
      send_file (fd, targ, mode);
    }
}
コード例 #4
0
/*
 * Send file(s).
 */
void
put(int argc, char *argv[])
{
	int	 fd;
	int	 n;
	char	*cp, *targ;

	if (argc < 2) {
		strlcpy(line, "send ", sizeof(line));
		printf("(file) ");
		readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin);
		if (makeargv())
			return;
		argc = margc;
		argv = margv;
	}
	if (argc < 2) {
		putusage(argv[0]);
		return;
	}
	targ = argv[argc - 1];
	if (strchr(argv[argc - 1], ':')) {
		struct hostent	*hp;

		for (n = 1; n < argc - 1; n++)
			if (strchr(argv[n], ':')) {
				putusage(argv[0]);
				return;
			}
		cp = argv[argc - 1];
		targ = strchr(cp, ':');
		*targ++ = 0;
		hp = gethostbyname(cp);
		if (hp == NULL) {
			warnx("%s: %s", cp, hstrerror(h_errno));
			return;
		}
		bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr, hp->h_length);
		peeraddr.sin_family = hp->h_addrtype;
		connected = 1;
		port = sp->s_port;
		strlcpy(hostname, hp->h_name, sizeof(hostname));
	}
	if (!connected) {
		printf("No target machine specified.\n");
		return;
	}
	if (argc < 4) {
		cp = argc == 2 ? tail(targ) : argv[1];
		fd = open(cp, O_RDONLY);
		if (fd < 0) {
			warn("open: %s", cp);
			return;
		}
		if (verbose)
			printf("putting %s to %s:%s [%s]\n",
			    cp, hostname, targ, mode);
		peeraddr.sin_port = port;
		sendfile(fd, targ, mode);
		return;
	}

	/*
	 * this assumes the target is a directory on
	 * on a remote unix system.  hmmmm.
	 */
	for (n = 1; n < argc - 1; n++) {
		if (asprintf(&cp, "%s/%s", targ, tail(argv[n])) == -1)
			err(1, "asprintf");
		fd = open(argv[n], O_RDONLY);
		if (fd < 0) {
			warn("open: %s", argv[n]);
			free(cp);
			continue;
		}
		if (verbose)
			printf("putting %s to %s:%s [%s]\n",
			    argv[n], hostname, cp, mode);
		peeraddr.sin_port = port;
		sendfile(fd, cp, mode);
		free(cp);
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: 274914765/C
/*
 * Send file(s).
 */
void put (int argc, char *argv[])
{
    int fd;

    int n;

    char *cp, *targ;

    if (argc < 2)
    {
        getmoreargs ("send ", "(file) ");
        makeargv ();
        argc = margc;
        argv = margv;
    }
    if (argc < 2)
    {
        putusage (argv[0]);
        return;
    }
    targ = argv[argc - 1];
    if (strchr (argv[argc - 1], ':'))
    {
        struct hostent *hp;

        for (n = 1; n < argc - 1; n++)
            if (strchr (argv[n], ':'))
            {
                putusage (argv[0]);
                return;
            }
        cp = argv[argc - 1];
        targ = strchr (cp, ':');
        *targ++ = 0;
        hp = gethostbyname (cp);
        if (hp == NULL)
        {
            fprintf (stderr, "tftp: %s: ", cp);
            herror ((char *) NULL);
            return;
        }
        bcopy (hp->h_addr, (caddr_t) & peeraddr.sin_addr, hp->h_length);
        peeraddr.sin_family = hp->h_addrtype;
        connected = 1;
        hostname = xstrdup (hp->h_name);
    }
    if (!connected)
    {
        printf ("No target machine specified.\n");
        return;
    }
    if (argc < 4)
    {
        cp = argc == 2 ? tail (targ) : argv[1];
        fd = open (cp, O_RDONLY | mode->m_openflags);
        if (fd < 0)
        {
            fprintf (stderr, "tftp: ");
            perror (cp);
            return;
        }
        if (verbose)
            printf ("putting %s to %s:%s [%s]\n", cp, hostname, targ, mode->m_mode);
        peeraddr.sin_port = port;
        tftp_sendfile (fd, targ, mode->m_mode);
        return;
    }
    /* this assumes the target is a directory */
    /* on a remote unix system.  hmmmm.  */
    cp = strchr (targ, '\0');
    *cp++ = '/';
    for (n = 1; n < argc - 1; n++)
    {
        strcpy (cp, tail (argv[n]));
        fd = open (argv[n], O_RDONLY | mode->m_openflags);
        if (fd < 0)
        {
            fprintf (stderr, "tftp: ");
            perror (argv[n]);
            continue;
        }
        if (verbose)
            printf ("putting %s to %s:%s [%s]\n", argv[n], hostname, targ, mode->m_mode);
        peeraddr.sin_port = port;
        tftp_sendfile (fd, targ, mode->m_mode);
    }
}