Revision 9bf05444 vl.c

b/vl.c
1382 1382
    return 0;
1383 1383
}
1384 1384

  
1385
static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
1386
{
1387
    const char *p, *p1;
1388
    int len;
1389
    p = *pp;
1390
    p1 = strchr(p, sep);
1391
    if (!p1)
1392
        return -1;
1393
    len = p1 - p;
1394
    p1++;
1395
    if (buf_size > 0) {
1396
        if (len > buf_size - 1)
1397
            len = buf_size - 1;
1398
        memcpy(buf, p, len);
1399
        buf[len] = '\0';
1400
    }
1401
    *pp = p1;
1402
    return 0;
1403
}
1404

  
1405
static void net_slirp_redir(const char *redir_str)
1406
{
1407
    int is_udp;
1408
    char buf[256], *r;
1409
    const char *p;
1410
    struct in_addr guest_addr;
1411
    int host_port, guest_port;
1412
    
1413
    if (!slirp_inited) {
1414
        slirp_inited = 1;
1415
        slirp_init();
1416
    }
1417

  
1418
    p = redir_str;
1419
    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0)
1420
        goto fail;
1421
    if (!strcmp(buf, "tcp")) {
1422
        is_udp = 0;
1423
    } else if (!strcmp(buf, "udp")) {
1424
        is_udp = 1;
1425
    } else {
1426
        goto fail;
1427
    }
1428

  
1429
    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0)
1430
        goto fail;
1431
    host_port = strtol(buf, &r, 0);
1432
    if (r == buf)
1433
        goto fail;
1434

  
1435
    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0)
1436
        goto fail;
1437
    if (buf[0] == '\0') {
1438
        pstrcpy(buf, sizeof(buf), "10.0.2.15");
1439
    }
1440
    if (!inet_aton(buf, &guest_addr))
1441
        goto fail;
1442
    
1443
    guest_port = strtol(p, &r, 0);
1444
    if (r == p)
1445
        goto fail;
1446
    
1447
    if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) {
1448
        fprintf(stderr, "qemu: could not set up redirection\n");
1449
        exit(1);
1450
    }
1451
    return;
1452
 fail:
1453
    fprintf(stderr, "qemu: syntax: -redir [tcp|udp]:host-port:[guest-host]:guest-port\n");
1454
    exit(1);
1455
}
1456

  
1385 1457
#endif /* CONFIG_SLIRP */
1386 1458

  
1387 1459
#if !defined(_WIN32)
......
2334 2406
           "-tun-fd fd      use this fd as already opened tap/tun interface\n"
2335 2407
#ifdef CONFIG_SLIRP
2336 2408
           "-user-net       use user mode network stack [default if no tap/tun script]\n"
2337
           "-tftp prefix    allow tftp access to files starting with prefix [only with -user-net enabled]\n"
2409
           "-tftp prefix    allow tftp access to files starting with prefix [-user-net]\n"
2410
           "-redir [tcp|udp]:host-port:[guest-host]:guest-port\n"
2411
           "                redirect TCP or UDP connections from host to guest [-user-net]\n"
2338 2412
#endif
2339 2413
           "-dummy-net      use dummy network stack\n"
2340 2414
           "\n"
......
2410 2484
    QEMU_OPTION_tun_fd,
2411 2485
    QEMU_OPTION_user_net,
2412 2486
    QEMU_OPTION_tftp,
2487
    QEMU_OPTION_redir,
2413 2488
    QEMU_OPTION_dummy_net,
2414 2489

  
2415 2490
    QEMU_OPTION_kernel,
......
2463 2538
#ifdef CONFIG_SLIRP
2464 2539
    { "user-net", 0, QEMU_OPTION_user_net },
2465 2540
    { "tftp", HAS_ARG, QEMU_OPTION_tftp },
2541
    { "redir", HAS_ARG, QEMU_OPTION_redir },
2466 2542
#endif
2467 2543
    { "dummy-net", 0, QEMU_OPTION_dummy_net },
2468 2544

  
......
2756 2832
                break;
2757 2833
#ifdef CONFIG_SLIRP
2758 2834
            case QEMU_OPTION_tftp:
2759
	      {
2760
		extern const char *tftp_prefix;
2761 2835
		tftp_prefix = optarg;
2762
	      }
2763
	      break;
2836
                break;
2764 2837
            case QEMU_OPTION_user_net:
2765 2838
                net_if_type = NET_IF_USER;
2766 2839
                break;
2840
            case QEMU_OPTION_redir:
2841
                net_slirp_redir(optarg);                
2842
                break;
2767 2843
#endif
2768 2844
            case QEMU_OPTION_dummy_net:
2769 2845
                net_if_type = NET_IF_DUMMY;

Also available in: Unified diff