Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 322601
Collapse All | Expand All

(-)atftp-0.7/tftp.c~ (-7 / +29 lines)
Lines 18-33 Link Here
18
#include "config.h"
18
#include "config.h"
19
19
20
#include <stdio.h>
20
#include <stdio.h>
21
#include <stdlib.h>
21
#include <stdlib.h>
22
#include <string.h>
22
#include <string.h>
23
#include <unistd.h>
23
#include <unistd.h>
24
#include <getopt.h>
24
#include <getopt.h>
25
#include <string.h>
25
#include <string.h>
26
#include <stdarg.h>
26
27
27
#include <sys/types.h>
28
#include <sys/types.h>
28
#include <sys/socket.h>
29
#include <sys/socket.h>
29
#include <netinet/in.h>
30
#include <netinet/in.h>
30
#include <arpa/inet.h>
31
#include <arpa/inet.h>
31
#include <netdb.h>
32
#include <netdb.h>
32
33
33
#include <signal.h> 
34
#include <signal.h> 
Lines 344-359 Link Here
344
     
345
     
345
     /* If no names matched, then return NULL. */
346
     /* If no names matched, then return NULL. */
346
     return NULL;
347
     return NULL;
347
}
348
}
348
# endif
349
# endif
349
#endif
350
#endif
350
351
351
/*
352
/*
353
 * set argc/argv from variadic string arguments
354
*/
355
void make_arg_vector(int *argc, char***argv, ...)
356
{
357
  char **p;
358
  char *s;
359
  va_list argp;
360
  
361
  // how many args?
362
  *argc = 0;
363
  va_start(argp, argv);
364
  while ( (s=va_arg(argp, char*)) )
365
    ++*argc;
366
367
  // allocate storage
368
  *argv = malloc(*argc * sizeof (char*));
369
370
  // store args
371
  p = *argv;
372
  va_start(argp, argv);
373
  while ( (s=va_arg(argp, char*)) )
374
    *p++ = s;
375
}
376
377
/*
352
 * Split a string into args.
378
 * Split a string into args.
353
 */
379
 */
354
void make_arg(char *string, int *argc, char ***argv)
380
void make_arg(char *string, int *argc, char ***argv)
355
{
381
{
356
     static char *tmp = NULL;
382
     static char *tmp = NULL;
357
     size_t argz_len;
383
     size_t argz_len;
358
384
359
     /* split the string to an argz vector */
385
     /* split the string to an argz vector */
Lines 1142-1171 Link Here
1142
                                       argv[optind+1]);
1168
                                       argv[optind+1]);
1143
          make_arg(string, &ac, &av);
1169
          make_arg(string, &ac, &av);
1144
          process_cmd(ac, av);
1170
          process_cmd(ac, av);
1145
     }
1171
     }
1146
     
1172
     
1147
     if (!interactive)
1173
     if (!interactive)
1148
     {
1174
     {
1149
          if (action == PUT)
1175
          if (action == PUT)
1150
               snprintf(string, sizeof(string), "put %s %s", local_file,
1176
               make_arg_vector(&ac,&av,"put",local_file,remote_file,NULL);
1151
                        remote_file);
1152
          else if (action == GET)
1177
          else if (action == GET)
1153
               snprintf(string, sizeof(string), "get %s %s", remote_file,
1178
               make_arg_vector(&ac,&av,"get",remote_file,local_file,NULL);
1154
                        local_file);
1155
          else if (action == MGET)
1179
          else if (action == MGET)
1156
               snprintf(string, sizeof(string), "mget %s %s", remote_file,
1180
               make_arg_vector(&ac,&av,"mget",remote_file,local_file,NULL);
1157
                        local_file);
1158
          else
1181
          else
1159
          {
1182
          {
1160
               fprintf(stderr, "No action specified in batch mode!\n");
1183
               fprintf(stderr, "No action specified in batch mode!\n");
1161
               exit(ERR);
1184
               exit(ERR);
1162
          }
1185
          }
1163
          make_arg(string, &ac, &av);
1164
          if (process_cmd(ac, av) == ERR)
1186
          if (process_cmd(ac, av) == ERR)
1165
               exit(ERR);
1187
               exit(ERR);
1166
     }
1188
     }
1167
     return OK;
1189
     return OK;
1168
}
1190
}
1169
1191
1170
void tftp_usage(void)
1192
void tftp_usage(void)
1171
{
1193
{

Return to bug 322601