4
* Copyright (c) 2004-2008 Fabrice Bellard
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:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
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
39
16
0x52, 0x54, 0x00, 0x12, 0x35, 0x00
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;
46
static const uint8_t zero_ethaddr[6] = { 0, 0, 0, 0, 0, 0 };
624
597
slirp_output(arp_reply, sizeof(arp_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);
676
642
if (ip_data_len + ETH_HLEN > sizeof(buf))
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;
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;
698
rah->ar_op = htons(ARPOP_REQUEST);
700
memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN - 1);
701
rah->ar_sha[5] = CTL_ALIAS;
703
memcpy(rah->ar_sip, &alias_addr, 4);
704
/* target hw addr (none) */
705
memset(rah->ar_tha, 0, ETH_ALEN);
707
memcpy(rah->ar_tip, &iph->ip_dst, 4);
708
client_ipaddr = iph->ip_dst;
709
slirp_output(arp_req, sizeof(arp_req));
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);
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);
721
654
int slirp_redir(int is_udp, int host_port,