Changeset 1742

Show
Ignore:
Timestamp:
03/21/07 21:34:13 (22 months ago)
Author:
aturner
Message:

switch to using interface alias lookup code. refs #113

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/tcpbridge.c

    • Property svn:keywords changed from Makefile to Id HeadURL Author Rev Date
    r1736 r1742  
    1 /* $Id: tcpbridge.c 1573 2006-08-05 20:26:08Z aturner $ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    164164{ 
    165165    char ebuf[SENDPACKET_ERRBUF_SIZE]; 
     166    char *intname; 
     167    interface_list_t *intlist = get_interface_list(); 
     168 
    166169     
    167170#ifdef DEBUG 
     
    189192        options.limit_send = OPT_VALUE_LIMIT; /* default is -1 */ 
    190193 
    191     options.intf1 = safe_strdup(OPT_ARG(INTF1)); 
    192  
    193     if (HAVE_OPT(INTF2))  
    194         options.intf2 = safe_strdup(OPT_ARG(INTF2)); 
    195  
     194 
     195    if ((intname = get_interface(intlist, OPT_ARG(INTF1))) == NULL) 
     196        errx(1, "Invalid interface name/alias: %s", OPT_ARG(INTF1)); 
     197     
     198    options.intf1 = safe_strdup(intname); 
     199 
     200    if (HAVE_OPT(INTF2)) { 
     201        if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) 
     202            errx(1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); 
     203     
     204        options.intf2 = safe_strdup(intname); 
     205    } 
    196206     
    197207 
  • trunk/src/tcpreplay.c

    • Property svn:keywords changed from Makefile to Id HeadURL Author Rev Date
    r1734 r1742  
    1 /* $Id: tcpreplay.c 1556 2006-07-31 06:12:01Z aturner $ */ 
     1/* $Id$ */ 
    22 
    33/* 
     
    157157    dlt = sendpacket_get_dlt(options.intf1); 
    158158    if ((dlt > 0) && (dlt != pcap_datalink(pcap))) 
    159         warnx("%s DLT does not match that of the outbound interface: %s", path, options.intf1->device); 
     159        warnx("%s DLT (%s) does not match that of the outbound interface: %s (%s)",  
     160            path, pcap_datalink_val_to_name(pcap_datalink(pcap)),  
     161            options.intf1->device, pcap_datalink_val_to_name(dlt)); 
    160162         
    161163    send_packets(pcap); 
     
    205207post_args(void) 
    206208{ 
    207     char *temp; 
     209    char *temp, *intname; 
    208210    char ebuf[SENDPACKET_ERRBUF_SIZE]; 
    209211    int int1dlt, int2dlt; 
    210      
     212    interface_list_t *intlist = get_interface_list(); 
     213 
    211214 
    212215#ifdef DEBUG 
     
    255258        warn("--pktlen may cause problems.  Use with caution."); 
    256259     
    257     options.intf1_name = (char *)safe_malloc(strlen(OPT_ARG(INTF1)) + 1); 
    258     strncpy(options.intf1_name, OPT_ARG(INTF1), strlen(OPT_ARG(INTF1))); 
     260     
     261    if ((intname = get_interface(intlist, OPT_ARG(INTF1))) == NULL) 
     262        errx(1, "Invalid interface name/alias: %s", OPT_ARG(INTF1)); 
     263     
     264    options.intf1_name = safe_strdup(intname); 
    259265     
    260266    /* open interfaces for writing */ 
     
    265271     
    266272    if (HAVE_OPT(INTF2)) { 
    267         options.intf2_name = (char *)safe_malloc(strlen(OPT_ARG(INTF2)) + 1); 
    268         strncpy(options.intf2_name, OPT_ARG(INTF2), strlen(OPT_ARG(INTF2))); 
     273        if ((intname = get_interface(intlist, OPT_ARG(INTF2))) == NULL) 
     274            errx(1, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); 
     275             
     276        options.intf2_name = safe_strdup(intname); 
    269277         
    270278        /* open interface for writing */ 
     
    274282        int2dlt = sendpacket_get_dlt(options.intf2); 
    275283        if (int2dlt != int1dlt) 
    276             errx(1, "DLT type missmatch for %s and %s", options.intf1_name, options.intf2_name); 
     284            errx(1, "DLT type missmatch for %s (%s) and %s (%s)",  
     285                options.intf1_name, pcap_datalink_val_to_name(int1dlt),  
     286                options.intf2_name, pcap_datalink_val_to_name(int2dlt)); 
    277287    } 
    278288 
  • trunk/src/tcpreplay_opts.def

    r1731 r1742  
    196196        flag-code       = <<- EOFlag 
    197197         
    198     char ebuf[PCAP_ERRBUF_SIZE]; 
    199     pcap_if_t *pcap_if, *pcap_if_ptr; 
    200         int i = 0; 
    201  
    202     if (pcap_findalldevs(&pcap_if, ebuf) < 0) 
    203         errx(1, "Error: %s", ebuf); 
    204              
    205     pcap_if_ptr = pcap_if; 
    206     printf("%s", "Available network interfaces:\n"); 
    207 #ifdef HAVE_WIN32  /* Win32 has alias/name/description */ 
    208         printf("Alias\tName\n"); 
    209 #else 
    210         /* Unix just has a warning about being root */ 
    211         if (geteuid() != 0) 
    212                 printf("Warning!  Need to run as root to get complete list.\n"); 
    213 #endif 
    214  
    215     while (pcap_if_ptr != NULL) { 
    216         if (! pcap_if_ptr->flags & PCAP_IF_LOOPBACK) { 
    217 #ifdef HAVE_WIN32 
    218             printf("%%%d\t%s\n\t%s\n", i, pcap_if_ptr->name, pcap_if_ptr->description); 
    219 #else 
    220                         printf("%s\n", pcap_if_ptr->name); 
    221 #endif 
    222                         i ++; 
    223                 } 
    224         pcap_if_ptr = pcap_if_ptr->next; 
    225     } 
    226     pcap_freealldevs(pcap_if); 
     198        interface_list_t *list = get_interface_list(); 
     199        list_interfaces(list); 
     200        free(list); 
    227201    exit(0); 
    228202