~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to slirp/slirp.c

  • Committer: blueswir1
  • Date: 2007-11-25 08:48:16 UTC
  • Revision ID: git-v1:b76482e76560345c00e7d6c89199ced204a926d2
 Fix buffer mux handling for unconnected serial ports


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3737 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * libslirp glue
3
 
 *
4
 
 * Copyright (c) 2004-2008 Fabrice Bellard
5
 
 *
6
 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 
 * of this software and associated documentation files (the "Software"), to deal
8
 
 * in the Software without restriction, including without limitation the rights
9
 
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 
 * copies of the Software, and to permit persons to whom the Software is
11
 
 * furnished to do so, subject to the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice shall be included in
14
 
 * all copies or substantial portions of the Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 
 * THE SOFTWARE.
23
 
 */
24
1
#include "slirp.h"
25
2
 
26
3
/* host address */
39
16
    0x52, 0x54, 0x00, 0x12, 0x35, 0x00
40
17
};
41
18
 
42
 
/* ARP cache for the guest IP addresses (XXX: allow many entries) */
43
19
uint8_t client_ethaddr[6];
44
 
static struct in_addr client_ipaddr;
45
 
 
46
 
static const uint8_t zero_ethaddr[6] = { 0, 0, 0, 0, 0, 0 };
47
20
 
48
21
int do_slowtimo;
49
22
int link_up;
111
84
static int get_dns_addr(struct in_addr *pdns_addr)
112
85
{
113
86
    char buff[512];
114
 
    char buff2[257];
 
87
    char buff2[256];
115
88
    FILE *f;
116
89
    int found = 0;
117
90
    struct in_addr tmp_addr;
581
554
        unsigned char           ar_tip[4];              /* target IP address            */
582
555
};
583
556
 
584
 
static void arp_input(const uint8_t *pkt, int pkt_len)
 
557
void arp_input(const uint8_t *pkt, int pkt_len)
585
558
{
586
559
    struct ethhdr *eh = (struct ethhdr *)pkt;
587
560
    struct arphdr *ah = (struct arphdr *)(pkt + ETH_HLEN);
624
597
            slirp_output(arp_reply, sizeof(arp_reply));
625
598
        }
626
599
        break;
627
 
    case ARPOP_REPLY:
628
 
        /* reply to request of client mac address ? */
629
 
        if (!memcmp(client_ethaddr, zero_ethaddr, ETH_ALEN) &&
630
 
            !memcmp(ah->ar_sip, &client_ipaddr.s_addr, 4)) {
631
 
            memcpy(client_ethaddr, ah->ar_sha, ETH_ALEN);
632
 
        }
633
 
        break;
634
600
    default:
635
601
        break;
636
602
    }
675
641
 
676
642
    if (ip_data_len + ETH_HLEN > sizeof(buf))
677
643
        return;
678
 
    
679
 
    if (!memcmp(client_ethaddr, zero_ethaddr, ETH_ALEN)) {
680
 
        uint8_t arp_req[ETH_HLEN + sizeof(struct arphdr)];
681
 
        struct ethhdr *reh = (struct ethhdr *)arp_req;
682
 
        struct arphdr *rah = (struct arphdr *)(arp_req + ETH_HLEN);
683
 
        const struct ip *iph = (const struct ip *)ip_data;
684
644
 
685
 
        /* If the client addr is not known, there is no point in
686
 
           sending the packet to it. Normally the sender should have
687
 
           done an ARP request to get its MAC address. Here we do it
688
 
           in place of sending the packet and we hope that the sender
689
 
           will retry sending its packet. */
690
 
        memset(reh->h_dest, 0xff, ETH_ALEN);
691
 
        memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 1);
692
 
        reh->h_source[5] = CTL_ALIAS;
693
 
        reh->h_proto = htons(ETH_P_ARP);
694
 
        rah->ar_hrd = htons(1);
695
 
        rah->ar_pro = htons(ETH_P_IP);
696
 
        rah->ar_hln = ETH_ALEN;
697
 
        rah->ar_pln = 4;
698
 
        rah->ar_op = htons(ARPOP_REQUEST);
699
 
        /* source hw addr */
700
 
        memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN - 1);
701
 
        rah->ar_sha[5] = CTL_ALIAS;
702
 
        /* source IP */
703
 
        memcpy(rah->ar_sip, &alias_addr, 4);
704
 
        /* target hw addr (none) */
705
 
        memset(rah->ar_tha, 0, ETH_ALEN);
706
 
        /* target IP */
707
 
        memcpy(rah->ar_tip, &iph->ip_dst, 4);
708
 
        client_ipaddr = iph->ip_dst;
709
 
        slirp_output(arp_req, sizeof(arp_req));
710
 
    } else {
711
 
        memcpy(eh->h_dest, client_ethaddr, ETH_ALEN);
712
 
        memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1);
713
 
        /* XXX: not correct */
714
 
        eh->h_source[5] = CTL_ALIAS;
715
 
        eh->h_proto = htons(ETH_P_IP);
716
 
        memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len);
717
 
        slirp_output(buf, ip_data_len + ETH_HLEN);
718
 
    }
 
645
    memcpy(eh->h_dest, client_ethaddr, ETH_ALEN);
 
646
    memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1);
 
647
    /* XXX: not correct */
 
648
    eh->h_source[5] = CTL_ALIAS;
 
649
    eh->h_proto = htons(ETH_P_IP);
 
650
    memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len);
 
651
    slirp_output(buf, ip_data_len + ETH_HLEN);
719
652
}
720
653
 
721
654
int slirp_redir(int is_udp, int host_port,