nslookup implementation

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-10-14 19:21:59 +02:00
parent 0cb9503b70
commit 038ec56a31
8 changed files with 27 additions and 14 deletions

View file

@ -1598,6 +1598,7 @@ module = {
module = { module = {
name = net; name = net;
common = net/net.c; common = net/net.c;
common = net/dns.c;
common = net/bootp.c; common = net/bootp.c;
common = net/ip.c; common = net/ip.c;
common = net/udp.c; common = net/udp.c;

View file

@ -541,7 +541,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
return err; return err;
} }
static grub_command_t cmd_dhcp, cmd_getdhcp, cmd_bootp; static grub_command_t cmd_getdhcp, cmd_bootp;
void void
grub_bootp_init (void) grub_bootp_init (void)
@ -549,9 +549,6 @@ grub_bootp_init (void)
cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp, cmd_bootp = grub_register_command ("net_bootp", grub_cmd_bootp,
"[CARD]", "[CARD]",
N_("perform a bootp autoconfiguration")); N_("perform a bootp autoconfiguration"));
cmd_dhcp = grub_register_command ("net_dhcp", grub_cmd_bootp,
"[CARD]",
N_("perform a bootp autoconfiguration"));
cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt, cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt,
N_("VAR INTERFACE NUMBER DESCRIPTION"), N_("VAR INTERFACE NUMBER DESCRIPTION"),
N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value.")); N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value."));
@ -561,6 +558,5 @@ void
grub_bootp_fini (void) grub_bootp_fini (void)
{ {
grub_unregister_command (cmd_getdhcp); grub_unregister_command (cmd_getdhcp);
grub_unregister_command (cmd_dhcp);
grub_unregister_command (cmd_bootp); grub_unregister_command (cmd_bootp);
} }

View file

@ -1491,6 +1491,7 @@ GRUB_MOD_INIT(net)
cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs, cmd_lsaddr = grub_register_command ("net_ls_addr", grub_cmd_listaddrs,
"", N_("list network addresses")); "", N_("list network addresses"));
grub_bootp_init (); grub_bootp_init ();
grub_dns_init ();
grub_fs_register (&grub_net_fs); grub_fs_register (&grub_net_fs);
grub_net_open = grub_net_open_real; grub_net_open = grub_net_open_real;
@ -1503,6 +1504,7 @@ GRUB_MOD_INIT(net)
GRUB_MOD_FINI(net) GRUB_MOD_FINI(net)
{ {
grub_bootp_fini (); grub_bootp_fini ();
grub_dns_fini ();
grub_unregister_command (cmd_addaddr); grub_unregister_command (cmd_addaddr);
grub_unregister_command (cmd_deladdr); grub_unregister_command (cmd_deladdr);
grub_unregister_command (cmd_addroute); grub_unregister_command (cmd_addroute);

View file

@ -279,6 +279,7 @@ tftp_open (struct grub_file *file, const char *filename)
tftp_data_t data; tftp_data_t data;
grub_err_t err; grub_err_t err;
grub_uint8_t *nbd; grub_uint8_t *nbd;
grub_net_network_level_address_t addr;
data = grub_zalloc (sizeof (*data)); data = grub_zalloc (sizeof (*data));
if (!data) if (!data)
@ -335,7 +336,14 @@ tftp_open (struct grub_file *file, const char *filename)
if (!data->pq) if (!data->pq)
return grub_errno; return grub_errno;
data->sock = grub_net_udp_open (file->device->net->server, err = grub_net_resolve_address (file->device->net->server, &addr);
if (err)
{
destroy_pq (data);
return err;
}
data->sock = grub_net_udp_open (addr,
TFTP_SERVER_PORT, tftp_receive, TFTP_SERVER_PORT, tftp_receive,
file); file);
if (!data->sock) if (!data->sock)

View file

@ -59,7 +59,7 @@ grub_net_udp_close (grub_net_udp_socket_t sock)
} }
grub_net_udp_socket_t grub_net_udp_socket_t
grub_net_udp_open (char *server, grub_net_udp_open (grub_net_network_level_address_t addr,
grub_uint16_t out_port, grub_uint16_t out_port,
grub_err_t (*recv_hook) (grub_net_udp_socket_t sock, grub_err_t (*recv_hook) (grub_net_udp_socket_t sock,
struct grub_net_buff *nb, struct grub_net_buff *nb,
@ -67,17 +67,12 @@ grub_net_udp_open (char *server,
void *recv_hook_data) void *recv_hook_data)
{ {
grub_err_t err; grub_err_t err;
grub_net_network_level_address_t addr;
struct grub_net_network_level_interface *inf; struct grub_net_network_level_interface *inf;
grub_net_network_level_address_t gateway; grub_net_network_level_address_t gateway;
grub_net_udp_socket_t socket; grub_net_udp_socket_t socket;
static int in_port = 25300; static int in_port = 25300;
grub_net_link_level_address_t ll_target_addr; grub_net_link_level_address_t ll_target_addr;
err = grub_net_resolve_address (server, &addr);
if (err)
return NULL;
if (addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4 if (addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
&& addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6) && addr.type != GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6)
{ {

View file

@ -65,7 +65,8 @@ typedef enum
GRUB_ERR_NET_PORT_CLOSED, GRUB_ERR_NET_PORT_CLOSED,
GRUB_ERR_NET_INVALID_RESPONSE, GRUB_ERR_NET_INVALID_RESPONSE,
GRUB_ERR_NET_UNKNOWN_ERROR, GRUB_ERR_NET_UNKNOWN_ERROR,
GRUB_ERR_NET_PACKET_TOO_BIG GRUB_ERR_NET_PACKET_TOO_BIG,
GRUB_ERR_NET_NO_DOMAIN
} }
grub_err_t; grub_err_t;

View file

@ -446,6 +446,9 @@ grub_net_poll_cards (unsigned time);
void grub_bootp_init (void); void grub_bootp_init (void);
void grub_bootp_fini (void); void grub_bootp_fini (void);
void grub_dns_init (void);
void grub_dns_fini (void);
static inline void static inline void
grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter) grub_net_network_level_interface_unregister (struct grub_net_network_level_interface *inter)
{ {
@ -472,6 +475,13 @@ grub_err_t
grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf, grub_net_link_layer_resolve (struct grub_net_network_level_interface *inf,
const grub_net_network_level_address_t *proto_addr, const grub_net_network_level_address_t *proto_addr,
grub_net_link_level_address_t *hw_addr); grub_net_link_level_address_t *hw_addr);
grub_err_t
grub_net_dns_lookup (const char *name,
const struct grub_net_network_level_address *servers,
grub_size_t n_servers,
grub_size_t *naddresses,
struct grub_net_network_level_address **addresses,
int cache);
extern char *grub_net_default_server; extern char *grub_net_default_server;

View file

@ -33,7 +33,7 @@ struct grub_net_udp_socket;
typedef struct grub_net_udp_socket *grub_net_udp_socket_t; typedef struct grub_net_udp_socket *grub_net_udp_socket_t;
grub_net_udp_socket_t grub_net_udp_socket_t
grub_net_udp_open (char *server, grub_net_udp_open (grub_net_network_level_address_t addr,
grub_uint16_t out_port, grub_uint16_t out_port,
grub_err_t (*recv_hook) (grub_net_udp_socket_t sock, grub_err_t (*recv_hook) (grub_net_udp_socket_t sock,
struct grub_net_buff *nb, struct grub_net_buff *nb,