netutils/netlib/netlib_getarptab.c: Misc fixes from initial testing with the 'arp -t' commeand.
This commit is contained in:
parent
400995dec6
commit
b65c3dac0e
@ -313,7 +313,7 @@ int netlib_get_arpmapping(FAR const struct sockaddr_in *inaddr,
|
|||||||
int netlib_set_arpmapping(FAR const struct sockaddr_in *inaddr,
|
int netlib_set_arpmapping(FAR const struct sockaddr_in *inaddr,
|
||||||
FAR const uint8_t *macaddr);
|
FAR const uint8_t *macaddr);
|
||||||
#ifdef CONFIG_NETLINK_ROUTE
|
#ifdef CONFIG_NETLINK_ROUTE
|
||||||
struct arp_enty_s;
|
struct arp_entry_s;
|
||||||
ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab,
|
ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab,
|
||||||
unsigned int nentries);
|
unsigned int nentries);
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,6 +99,9 @@ ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab, unsigned int nentrie
|
|||||||
{
|
{
|
||||||
FAR struct netlib_recvfrom_response_s *resp;
|
FAR struct netlib_recvfrom_response_s *resp;
|
||||||
struct netlib_sendto_request_s req;
|
struct netlib_sendto_request_s req;
|
||||||
|
struct sockaddr_nl addr;
|
||||||
|
static unsigned int seqno = 0;
|
||||||
|
unsigned int thiseq;
|
||||||
unsigned int allocsize;
|
unsigned int allocsize;
|
||||||
ssize_t nsent;
|
ssize_t nsent;
|
||||||
ssize_t nrecvd;
|
ssize_t nrecvd;
|
||||||
@ -107,14 +110,14 @@ ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab, unsigned int nentrie
|
|||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Allocate a buffer to hold the response */
|
/* Pre-allocate a buffer to hold the response */
|
||||||
|
|
||||||
maxsize = CONFIG_NET_ARPTAB_SIZE * sizeof(struct arp_entry_s);
|
maxsize = CONFIG_NET_ARPTAB_SIZE * sizeof(struct arp_entry_s);
|
||||||
allocsize = SIZEOF_NETLIB_RECVFROM_RESPONSE_S(maxsize);
|
allocsize = SIZEOF_NETLIB_RECVFROM_RESPONSE_S(maxsize);
|
||||||
resp = (FAR struct netlib_recvfrom_response_s *)malloc(allocsize);
|
resp = (FAR struct netlib_recvfrom_response_s *)malloc(allocsize);
|
||||||
if (resp == NULL)
|
if (resp == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: Faile to allocat response buffer\n");
|
fprintf(stderr, "ERROR: Failed to allocate response buffer\n");
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@ -130,11 +133,29 @@ ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab, unsigned int nentrie
|
|||||||
goto errout_with_resp;
|
goto errout_with_resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Bind the socket so that we can use send() and receive() */
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(struct sockaddr_nl));
|
||||||
|
addr.nl_family = AF_NETLINK;
|
||||||
|
addr.nl_groups = RTM_GETNEIGH;
|
||||||
|
|
||||||
|
ret = bind(fd, &addr, sizeof( struct sockaddr_nl));
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
int errcode = errno;
|
||||||
|
fprintf(stderr, "ERROR: bind() failed: %d\n", errcode);
|
||||||
|
ret = -errcode;
|
||||||
|
goto errout_with_socket;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the request */
|
/* Initialize the request */
|
||||||
|
|
||||||
|
thiseq = ++seqno;
|
||||||
|
|
||||||
memset(&req, 0, sizeof(req));
|
memset(&req, 0, sizeof(req));
|
||||||
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
||||||
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_REQUEST;
|
req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_REQUEST;
|
||||||
|
req.hdr.nlmsg_seq = thiseq;
|
||||||
req.hdr.nlmsg_type = RTM_GETNEIGH;
|
req.hdr.nlmsg_type = RTM_GETNEIGH;
|
||||||
req.msg.ndm_family = AF_INET;
|
req.msg.ndm_family = AF_INET;
|
||||||
|
|
||||||
@ -147,6 +168,20 @@ ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab, unsigned int nentrie
|
|||||||
goto errout_with_socket;
|
goto errout_with_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize the response buffer.
|
||||||
|
* REVISIT: Linux examples that I have seen just pass a raw buffer. I am
|
||||||
|
* not sure how they associate the requested data to the recv() without a
|
||||||
|
* sequence number.
|
||||||
|
*/
|
||||||
|
|
||||||
|
memset(&resp->hdr, 0, sizeof(resp->hdr));
|
||||||
|
resp->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
||||||
|
resp->hdr.nlmsg_seq = thiseq;
|
||||||
|
resp->hdr.nlmsg_type = RTM_GETNEIGH;
|
||||||
|
|
||||||
|
memset(&resp->msg, 0, sizeof(resp->msg));
|
||||||
|
resp->msg.ndm_family = AF_INET;
|
||||||
|
|
||||||
nrecvd = recv(fd, resp, allocsize, 0);
|
nrecvd = recv(fd, resp, allocsize, 0);
|
||||||
if (nrecvd < 0)
|
if (nrecvd < 0)
|
||||||
{
|
{
|
||||||
@ -179,6 +214,7 @@ ssize_t netlib_get_arptable(FAR struct arp_entry_s *arptab, unsigned int nentrie
|
|||||||
|
|
||||||
errout_with_socket:
|
errout_with_socket:
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
errout_with_resp:
|
errout_with_resp:
|
||||||
free(resp);
|
free(resp);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -208,7 +208,7 @@ int tftp_parseerrpacket(const uint8_t *buffer)
|
|||||||
|
|
||||||
if (opcode == TFTP_ERR)
|
if (opcode == TFTP_ERR)
|
||||||
{
|
{
|
||||||
ninfo("ERR message: %s (%d)\n", errmsg, errcode);
|
nwarn("WARNING: ERR message: %s (%d)\n", errmsg, errcode);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/nshlib/nsh_command.c
|
* apps/nshlib/nsh_command.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2018 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2019 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
Loading…
Reference in New Issue
Block a user