3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #define DEFAULT_IP_ADDRESS NET_IPV4_TO_ADDR (192,168,1,50)
31 #define DEFAULT_GW_ADDRESS NET_IPV4_TO_ADDR (192,168,1,1)
33 netif_t
*netif_findbyname (char *name
)
36 for (netif
= netif_list
.next
; netif
!= &netif_list
; netif
= netif
->next
) {
37 if (!strcmp (netif
->dev
->name
, name
))
44 unsigned netif_ip_addr (netif_t
*netif
, net_ipv4 ip
)
54 unsigned netif_ipv6_addr (netif_t
*netif
, net_ipv6 ip
)
59 memcpy (netif
->ipv6
, ip
, sizeof (net_ipv6
));
64 unsigned netif_gw_addr (netif_t
*netif
, net_ipv4 gw
)
74 netif_t
*netif_create (struct netdev_t
*dev
)
81 /* alloc and init context */
82 netif
= (netif_t
*) kmalloc (sizeof (netif_t
));
87 /* init 6 bytes for MAC address */
88 netif
->addr
= (struct netaddr_t
*) kmalloc (sizeof (struct netaddr_t
));
98 netif_ip_addr (netif
, DEFAULT_IP_ADDRESS
);
99 netif_gw_addr (netif
, DEFAULT_GW_ADDRESS
);
102 NET_IPV6_TO_ADDR (ipv6
, 0xfc00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10);
103 //NET_IPV6_TO_ADDR (ipv6, 0x2002, 0x470, 0x1f0a, 0x4d3, 0x0, 0x0, 0x0, 0x1);
105 netif_ipv6_addr (netif
, ipv6
);
108 netif
->next
= &netif_list
;
109 netif
->prev
= netif_list
.prev
;
110 netif
->prev
->next
= netif
;
111 netif
->next
->prev
= netif
;
116 void iflist_display ()
119 for (netif
= netif_list
.next
; netif
!= &netif_list
; netif
= netif
->next
) {
123 printf ("if: %s - MAC addr: %02x:%02x:%02x:%02x:%02x:%02x\n\tRx bytes: %lu\tTx bytes: %lu\n", netif
->dev
->name
,
124 netif
->dev
->dev_addr
[0], netif
->dev
->dev_addr
[1], netif
->dev
->dev_addr
[2],
125 netif
->dev
->dev_addr
[3], netif
->dev
->dev_addr
[4], netif
->dev
->dev_addr
[5],
126 netif
->dev
->info_rx
, netif
->dev
->info_tx
);
127 printf ("\tEthernet IP address:\t"); net_proto_ip_print (netif
->ip
);
128 printf ("\n\t\t\t\t"); net_proto_ipv6_print (netif
->ipv6
);
129 printf ("\n\tGateway IP address:\t"); net_proto_ip_print (netif
->gw
);
131 if (tun6_addr_get ()) {
132 printf ("\n\tTunnel IP address:\t::"); net_proto_ip_print (tun6_addr_get ());
139 unsigned netif_read (struct netdev_t
*dev
, char *buf
)
145 unsigned init_netif ()
147 netif_list
.next
= &netif_list
;
148 netif_list
.prev
= &netif_list
;
150 if (!init_proto_arp ())
153 if (!init_proto_ndp ())