sockaddr: add X.25 socket address decoding support
* sockaddr.c: Include <linux/x25.h>. (print_sockaddr_data_x25): New function. (sa_printers) <[AF_X25]>: New socket address handler. * tests/net-sockaddr.c (check_x25): New function. (main): Call check_x25 in order to check X.25 socket address decoding.
This commit is contained in:
parent
fc9b2b76e3
commit
98bfc2f997
1
defs.h
1
defs.h
@ -881,6 +881,7 @@ extern bool
|
||||
decode_inet_addr(struct tcb *, kernel_ulong_t addr,
|
||||
unsigned int len, int family, const char *var_name);
|
||||
extern void print_ax25_addr(const void /* ax25_address */ *addr);
|
||||
extern void print_x25_addr(const void /* struct x25_address */ *addr);
|
||||
extern const char *get_sockaddr_by_inode(struct tcb *, int fd, unsigned long inode);
|
||||
extern bool print_sockaddr_by_inode(struct tcb *, int fd, unsigned long inode);
|
||||
extern void print_dirfd(struct tcb *, int);
|
||||
|
@ -189,6 +189,12 @@
|
||||
print_ax25_addr(&(where_).field_); \
|
||||
} while (0)
|
||||
|
||||
#define PRINT_FIELD_X25_ADDR(prefix_, where_, field_) \
|
||||
do { \
|
||||
STRACE_PRINTF("%s%s=", (prefix_), #field_); \
|
||||
print_x25_addr(&(where_).field_); \
|
||||
} while (0)
|
||||
|
||||
#define PRINT_FIELD_NET_PORT(prefix_, where_, field_) \
|
||||
STRACE_PRINTF("%s%s=htons(%u)", (prefix_), #field_, \
|
||||
ntohs((where_).field_))
|
||||
|
20
sockaddr.c
20
sockaddr.c
@ -43,6 +43,7 @@
|
||||
#include <linux/if_packet.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/x25.h>
|
||||
|
||||
#ifdef HAVE_NETIPX_IPX_H
|
||||
# include <netipx/ipx.h>
|
||||
@ -365,6 +366,24 @@ print_sockaddr_data_ipx(const void *const buf, const int addrlen)
|
||||
PRINT_FIELD_0X("], ", *sa_ipx, sipx_type);
|
||||
}
|
||||
|
||||
void
|
||||
print_x25_addr(const void /* struct x25_address */ *addr_void)
|
||||
{
|
||||
const struct x25_address *addr = addr_void;
|
||||
|
||||
tprints("{x25_addr=");
|
||||
print_quoted_cstring(addr->x25_addr, sizeof(addr->x25_addr));
|
||||
tprints("}");
|
||||
}
|
||||
|
||||
static void
|
||||
print_sockaddr_data_x25(const void *const buf, const int addrlen)
|
||||
{
|
||||
const struct sockaddr_x25 *const sa_x25 = buf;
|
||||
|
||||
PRINT_FIELD_X25_ADDR("", *sa_x25, sx25_addr);
|
||||
}
|
||||
|
||||
static void
|
||||
print_sockaddr_data_nl(const void *const buf, const int addrlen)
|
||||
{
|
||||
@ -587,6 +606,7 @@ static const struct {
|
||||
[AF_INET] = { print_sockaddr_data_in, sizeof(struct sockaddr_in) },
|
||||
[AF_AX25] = { print_sockaddr_data_ax25, sizeof(struct sockaddr_ax25) },
|
||||
[AF_IPX] = { print_sockaddr_data_ipx, sizeof(struct sockaddr_ipx) },
|
||||
[AF_X25] = { print_sockaddr_data_x25, sizeof(struct sockaddr_x25) },
|
||||
[AF_INET6] = { print_sockaddr_data_in6, SIN6_MIN_LEN },
|
||||
[AF_NETLINK] = { print_sockaddr_data_nl, SIZEOF_SA_FAMILY + 1 },
|
||||
[AF_PACKET] = { print_sockaddr_data_ll, sizeof(struct sockaddr_ll) },
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/if_packet.h>
|
||||
#include <linux/x25.h>
|
||||
#include <linux/ipx.h>
|
||||
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
|
||||
# include <bluetooth/bluetooth.h>
|
||||
@ -425,6 +426,38 @@ check_ax25(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_x25(void)
|
||||
{
|
||||
static const struct sockaddr_x25 c_x25 = {
|
||||
.sx25_family = AF_X25,
|
||||
.sx25_addr = { "0123456789abcdef" },
|
||||
};
|
||||
void *x25_void = tail_memdup(&c_x25, sizeof(c_x25) + 1);
|
||||
struct sockaddr_x25 *x25 = x25_void;
|
||||
long rc;
|
||||
|
||||
rc = connect(-1, x25, sizeof(c_x25) - 1);
|
||||
printf("connect(-1, {sa_family=AF_X25"
|
||||
", sa_data=\"0123456789abcde\"}, %zu) = %s\n",
|
||||
sizeof(c_x25) - 1, sprintrc(rc));
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
rc = connect(-1, x25, sizeof(c_x25) + i);
|
||||
printf("connect(-1, {sa_family=AF_X25"
|
||||
", sx25_addr={x25_addr=\"0123456789abcde\"...}"
|
||||
"}, %zu) = %s\n",
|
||||
sizeof(c_x25) + i, sprintrc(rc));
|
||||
}
|
||||
|
||||
x25->sx25_addr.x25_addr[10] = '\0';
|
||||
rc = connect(-1, x25, sizeof(c_x25));
|
||||
printf("connect(-1, {sa_family=AF_X25"
|
||||
", sx25_addr={x25_addr=\"0123456789\"}"
|
||||
"}, %zu) = %s\n",
|
||||
sizeof(c_x25), sprintrc(rc));
|
||||
}
|
||||
|
||||
static void
|
||||
check_nl(void)
|
||||
{
|
||||
@ -691,6 +724,7 @@ main(void)
|
||||
check_in6();
|
||||
check_ipx();
|
||||
check_ax25();
|
||||
check_x25();
|
||||
check_nl();
|
||||
check_ll();
|
||||
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user