Patch by Hugo Santos:

* added additional address family names
* support dumping the contents of ifreq (only interface name right now)
  and of ifconf (dumps the maximum of 8 interfaces)
* added <sys/sockio.h> ioctl names and type handling


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20448 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-03-28 15:26:37 +00:00
parent b8ba8f58d7
commit 492271435a
4 changed files with 117 additions and 10 deletions

View File

@ -107,7 +107,7 @@ format_pointer_value(Context &context, void *address)
{
Type data;
if (obtain_pointer_data(context, &data, address,Context::COMPLEX_STRUCTS))
if (obtain_pointer_data(context, &data, address, Context::COMPLEX_STRUCTS))
return "{" + format_pointer(context, &data) + "}";
return context.FormatPointer(address);
@ -129,9 +129,18 @@ static string
format_socket_family(Context &context, int family)
{
if (context.GetContents(Context::ENUMERATIONS)) {
#define SOCKET_FAMILY(family) \
case family: \
return #family
switch (family) {
case AF_INET:
return "AF_INET";
SOCKET_FAMILY(AF_UNSPEC);
SOCKET_FAMILY(AF_INET);
SOCKET_FAMILY(AF_APPLETALK);
SOCKET_FAMILY(AF_ROUTE);
SOCKET_FAMILY(AF_LINK);
SOCKET_FAMILY(AF_INET6);
SOCKET_FAMILY(AF_LOCAL);
}
}
@ -378,6 +387,60 @@ format_pointer(Context &context, msghdr *h)
return r;
}
static string
format_pointer(Context &context, ifreq *ifr)
{
return string(ifr->ifr_name) + ", ...";
}
static string
format_pointer(Context &context, ifconf *conf)
{
unsigned char buffer[sizeof(ifreq) * 8];
int maxData = sizeof(buffer);
int32 bytesRead;
if (conf->ifc_len < maxData)
maxData = conf->ifc_len;
string r = "len = " + context.FormatSigned(conf->ifc_len);
if (conf->ifc_len == 0)
return r;
status_t err = context.Reader().Read(conf->ifc_buf, buffer,
maxData, bytesRead);
if (err != B_OK)
return r + ", buf = " + context.FormatPointer(conf->ifc_buf);
r += ", [";
uint8 *current = buffer, *bufferEnd = buffer + bytesRead;
for (int i = 0; i < 8; i++) {
if ((bufferEnd - current) < (IF_NAMESIZE + 1))
break;
ifreq *ifr = (ifreq *)current;
int size = IF_NAMESIZE + ifr->ifr_addr.sa_len;
if ((bufferEnd - current) < size)
break;
if (i > 0)
r += ", ";
r += "{" + string(ifr->ifr_name) + ", {"
+ format_pointer(context, &ifr->ifr_addr) + "}}";
current += size;
}
if (current < bufferEnd)
r += ", ...";
return r + "]";
}
template<typename Type>
class SpecializedPointerTypeHandler : public TypeHandler {
string GetParameterValue(Context &context, Parameter *,
@ -410,3 +473,5 @@ POINTER_TYPE(transfer_args_ptr, struct transfer_args);
POINTER_TYPE(sockopt_args_ptr, struct sockopt_args);
POINTER_TYPE(socket_args_ptr, struct socket_args);
POINTER_TYPE(msghdr_ptr, struct msghdr);
POINTER_TYPE(ifreq_ptr, struct ifreq);
POINTER_TYPE(ifconf_ptr, struct ifconf);

View File

@ -93,6 +93,9 @@ static
string
read_string(Context &context, void *data)
{
if (data == NULL || !context.GetContents(Context::STRINGS))
return context.FormatPointer(data);
char buffer[256];
int32 bytesRead;
status_t error = context.Reader().Read(data, buffer, sizeof(buffer), bytesRead);
@ -140,19 +143,14 @@ string
TypeHandlerImpl<const char*>::GetParameterValue(Context &context, Parameter *,
const void *address)
{
void *data = *(void **)address;
if (data != NULL && context.GetContents(Context::STRINGS))
return read_string(context, data);
return context.FormatPointer(data);
return read_string(context, *(void **)address);
}
template<>
string
TypeHandlerImpl<const char*>::GetReturnValue(Context &context, uint64 value)
{
void *ptr = (void *)value;
return GetParameterValue(context, NULL, (const void *)&ptr);
return read_string(context, (void *)value);
}
EnumTypeHandler::EnumTypeHandler(const EnumMap &m) : fMap(m) {}

View File

@ -102,6 +102,8 @@ DEFINE_FACTORY(sockaddr_args_ptr, struct sockaddr_args *);
DEFINE_FACTORY(transfer_args_ptr, struct transfer_args *);
DEFINE_FACTORY(sockopt_args_ptr, struct sockopt_args *);
DEFINE_FACTORY(socket_args_ptr, struct socket_args *);
DEFINE_FACTORY(ifreq_ptr, struct ifreq *);
DEFINE_FACTORY(ifconf_ptr, struct ifconf *);
DEFINE_FACTORY(int_ptr, int *);
DEFINE_FACTORY(long_ptr, long *);

View File

@ -7,6 +7,7 @@
*/
#include <net_stack_driver.h>
#include <sys/sockio.h>
#include <termios.h>
#include "strace.h"
@ -47,6 +48,47 @@ static const ioctl_info kIOCtls[] = {
IOCTL_INFO_ENTRY(NET_STACK_SOCKETPAIR),
IOCTL_INFO_ENTRY(NET_STACK_NOTIFY_SOCKET_EVENT),
// <sys/sockio.h>
IOCTL_INFO_ENTRY(SIOCADDRT),
IOCTL_INFO_ENTRY(SIOCDELRT),
IOCTL_INFO_ENTRY_TYPE(SIOCSIFADDR, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFADDR, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCSIFDSTADDR, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFDSTADDR, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCSIFFLAGS, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFFLAGS, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFBRDADDR, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCSIFBRDADDR, struct ifreq *),
IOCTL_INFO_ENTRY(SIOCGIFCOUNT),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFCONF, struct ifconf *),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFINDEX, struct ifreq *),
IOCTL_INFO_ENTRY(SIOCGIFNAME),
IOCTL_INFO_ENTRY(SIOCGIFNETMASK),
IOCTL_INFO_ENTRY(SIOCSIFNETMASK),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFMETRIC, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCSIFMETRIC, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCDIFADDR, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCAIFADDR, struct ifreq *),
IOCTL_INFO_ENTRY(SIOCADDMULTI),
IOCTL_INFO_ENTRY(SIOCDELMULTI),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFMTU, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCSIFMTU, struct ifreq *),
IOCTL_INFO_ENTRY(SIOCSIFMEDIA),
IOCTL_INFO_ENTRY(SIOCGIFMEDIA),
IOCTL_INFO_ENTRY(SIOCGRTSIZE),
IOCTL_INFO_ENTRY(SIOCGRTTABLE),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFSTATS, struct ifreq *),
IOCTL_INFO_ENTRY_TYPE(SIOCGIFPARAM, struct ifreq *),
IOCTL_INFO_ENTRY(SIOCGIFTYPE),
IOCTL_INFO_ENTRY(SIOCSPACKETCAP),
IOCTL_INFO_ENTRY(SIOCCPACKETCAP),
IOCTL_INFO_ENTRY(SIOCSHIWAT),
IOCTL_INFO_ENTRY(SIOCGHIWAT),
IOCTL_INFO_ENTRY(SIOCSLOWAT),
IOCTL_INFO_ENTRY(SIOCGLOWAT),
IOCTL_INFO_ENTRY(SIOCATMARK),
IOCTL_INFO_ENTRY(SIOCSPGRP),
// termios ioctls
IOCTL_INFO_ENTRY(TCGETA),
IOCTL_INFO_ENTRY(TCSETA),