home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
sun
/
volume3
/
strace
/
part02
/
net.c
next >
Wrap
C/C++ Source or Header
|
1992-03-02
|
9KB
|
458 lines
/*
* @(#)net.c 2.5 92/01/21 - communications system calls
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "defs.h"
static Xlat domains[] = {
PF_UNIX, "PF_UNIX",
PF_INET, "PF_INET",
#ifdef PF_IMPLINK
PF_IMPLINK, "PF_IMPLINK",
#endif
0, NULL,
};
static Xlat socktypes[] = {
SOCK_STREAM, "STREAM",
SOCK_DGRAM, "DGRAM",
SOCK_RAW, "RAW",
#ifdef SOCK_SEQPACKET
SOCK_SEQPACKET, "SEQ_PKT",
#endif
#ifdef SOCK_RDM
SOCK_RDM, "RDM",
#endif
0, NULL,
};
static Xlat protocols[] = {
IPPROTO_IP, "IPPROTO_IP",
IPPROTO_ICMP, "IPPROTO_ICMP",
IPPROTO_TCP, "IPPROTO_TCP",
IPPROTO_UDP, "IPPROTO_UDP",
#ifdef IPPROTO_IGMP
IPPROTO_IGMP, "IPPROTO_IGMP",
#endif
#ifdef IPPROTO_GGP
IPPROTO_GGP, "IPPROTO_GGP",
#endif
#ifdef IPPROTO_EGP
IPPROTO_EGP, "IPPROTO_EGP",
#endif
#ifdef IPPROTO_PUP
IPPROTO_PUP, "IPPROTO_PUP",
#endif
#ifdef IPPROTO_IDP
IPPROTO_IDP, "IPPROTO_IDP",
#endif
#ifdef IPPROTO_HELLO
IPPROTO_HELLO, "IPPROTO_HELLO",
#endif
#ifdef IPPROTO_ND
IPPROTO_ND, "IPPROTO_ND",
#endif
#ifdef IPPROTO_RAW
IPPROTO_RAW, "IPPROTO_RAW",
#endif
0, NULL,
};
static Xlat msg_flags[] = {
MSG_OOB, "OOB",
MSG_DONTROUTE, "DONTROUTE",
0, NULL,
};
static Xlat sockoptions[] = {
SO_DEBUG, "DEBUG",
SO_ACCEPTCONN, "ACCEPTCONN",
SO_REUSEADDR, "REUSEADDR",
SO_KEEPALIVE, "KEEPALIVE",
SO_DONTROUTE, "DONTROUTE",
SO_BROADCAST, "BROADCAST",
SO_USELOOPBACK, "USELOOPBACK",
SO_LINGER, "LINGER",
SO_OOBINLINE, "OOBINLINE",
SO_SNDBUF, "SNDBUF",
SO_RCVBUF, "RCVBUF",
SO_SNDLOWAT, "SNDLOWAT",
SO_RCVLOWAT, "RCVLOWAT",
SO_SNDTIMEO, "SNDTIMEO",
SO_RCVTIMEO, "RCVTIMEO",
SO_ERROR, "ERROR",
SO_TYPE, "TYPE",
0, NULL,
};
void
printsock(pid, addr)
{
struct sockaddr sa;
struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
struct sockaddr_un sau;
if (addr == 0 || umove(pid, addr, sizeof sa, (char *)&sa) < 0) {
tprintf("(struct sockaddr *)%#x", addr);
return;
}
switch (sa.sa_family) {
case AF_UNIX:
if (umove(pid, addr, sizeof sau, (char *)&sau) < 0)
sau.sun_path[0] = '\0';
tprintf("AF_UNIX(%s)", sau.sun_path);
break;
case AF_INET:
tprintf("AF_INET(%u, %s)",
ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
break;
default:
tprintf("PF_UNSPEC");
break;
}
}
static void
printmsghdr(pid, addr)
{
struct msghdr msg;
if (addr == 0 || umove(pid, addr, sizeof msg, (char *)&msg) < 0) {
tprintf("(struct msghdr *)%#x", addr);
return;
}
tprintf("[name %s len %u iovec %#x iovlen %u acc %#x acclen %u]",
msg.msg_name, msg.msg_namelen,
msg.msg_iov, msg.msg_iovlen,
msg.msg_accrights, msg.msg_accrightslen);
}
int
sys_socket(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
printxval(domains, tcp->u_args[0], "PF_???");
tprintf(", ");
printxval(socktypes, tcp->u_args[1], "SOCK_???");
tprintf(", ");
if (tcp->u_args[0] == PF_INET) {
printxval(protocols, tcp->u_args[2], "IPPROTO_???");
} else {
tprintf("%u", tcp->u_args[2]);
}
}
return 0;
}
int
sys_bind(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
printsock(tcp->pid, tcp->u_args[1]);
tprintf(", %u", tcp->u_args[2]);
}
return 0;
}
int
sys_connect(tcp)
struct tcb *tcp;
{
return sys_bind(tcp);
}
int
sys_listen(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, %u", tcp->u_args[0], tcp->u_args[1]);
}
return 0;
}
int
sys_accept(tcp)
struct tcb *tcp;
{
int len;
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
} else {
if (tcp->u_args[2] == 0 || umove(tcp->pid, tcp->u_args[2],
sizeof len, (char *)&len) < 0) {
tprintf("(struct sockaddr *)%#x, (int *)0",
tcp->u_args[1]);
return 0;
}
if (syserror(tcp)) {
tprintf("%#x, %u", tcp->u_args[1], len);
} else {
printsock(tcp->pid, tcp->u_args[1]);
tprintf(", %u", len);
}
}
return 0;
}
int
sys_send(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
(void)printstr(tcp->pid, tcp->u_args[1], tcp->u_args[2]);
/* flags */
tprintf(", ");
if (printflags(msg_flags, tcp->u_args[3]) == 0)
tprintf("0");
}
return 0;
}
int
sys_sendto(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
(void)printstr(tcp->pid, tcp->u_args[1], tcp->u_args[2]);
/* flags */
tprintf(", %u, ", tcp->u_args[2]);
if (printflags(msg_flags, tcp->u_args[3]) == 0)
tprintf("0");
/* to address */
tprintf(", ");
printsock(tcp->pid, tcp->u_args[4]);
/* to length */
tprintf(", %u", tcp->u_args[5]);
}
return 0;
}
int
sys_sendmsg(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
printmsghdr(tcp->pid, tcp->u_args[1]);
/* flags */
tprintf(", ");
if (printflags(msg_flags, tcp->u_args[2]) == 0)
tprintf("0");
}
return 0;
}
int
sys_recv(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
} else {
if (syserror(tcp))
tprintf("%#x", tcp->u_args[1]);
else
(void)printstr(tcp->pid, tcp->u_args[1], tcp->u_rval);
tprintf(", %u, ", tcp->u_args[2]);
if (printflags(msg_flags, tcp->u_args[3]) == 0)
tprintf("0");
}
return 0;
}
int
sys_recvfrom(tcp)
struct tcb *tcp;
{
int fromlen;
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
} else {
if (syserror(tcp)) {
tprintf("%#x, %u, %u, %#x, %#x",
tcp->u_args[1], tcp->u_args[2], tcp->u_args[3],
tcp->u_args[4], tcp->u_args[5]);
}
/* buf */
(void)printstr(tcp->pid, tcp->u_args[1], tcp->u_rval);
/* len */
tprintf(", %u, ", tcp->u_args[2]);
/* flags */
if (printflags(msg_flags, tcp->u_args[3]) == 0)
tprintf("0");
/* from address, len */
if (tcp->u_args[5] == 0 || umove(tcp->pid, tcp->u_args[5],
sizeof fromlen, (char *)&fromlen) < 0) {
tprintf(", (struct sockaddr *)%#x, (int *)0",
tcp->u_args[4]);
return 0;
}
tprintf(", ");
printsock(tcp->pid, tcp->u_args[4]);
tprintf(", %u", fromlen);
}
return 0;
}
int
sys_recvmsg(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
} else {
if (syserror(tcp))
tprintf("(struct msghdr *)%#x", tcp->u_args[1]);
else
printmsghdr(tcp->pid, tcp->u_args[1]);
/* flags */
tprintf(", ");
if (printflags(msg_flags, tcp->u_args[2]) == 0)
tprintf("0");
}
return 0;
}
int
sys_shutdown(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
switch (tcp->u_args[1]) {
case 0:
tprintf("%s", "RECEIVE");
break;
case 1:
tprintf("%s", "SEND");
break;
case 2:
tprintf("%s", "SEND/RECEIVE");
break;
default:
tprintf("???(%u)", tcp->u_args[1]);
break;
}
}
return 0;
}
int
sys_getsockname(tcp)
struct tcb *tcp;
{
return sys_accept(tcp);
}
int
sys_getpeername(tcp)
struct tcb *tcp;
{
return sys_accept(tcp);
}
int
sys_pipe(tcp)
struct tcb *tcp;
{
if (exiting(tcp)) {
tprintf("[%u,%u]", tcp->u_rval, getrval2(tcp->pid));
}
return 0;
}
int
sys_socketpair(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
printxval(domains, tcp->u_args[0], "PF_???");
tprintf(", ");
printxval(socktypes, tcp->u_args[1], "SOCK_???");
tprintf(", ");
if (tcp->u_args[0] == PF_INET) {
printxval(protocols, tcp->u_args[2], "IPPROTO_???");
} else {
tprintf("%u", tcp->u_args[2]);
}
} else {
if (!syserror(tcp))
tprintf(", [%u,%u]", tcp->u_rval, getrval2(tcp->pid));
}
return 0;
}
int
sys_getsockopt(tcp)
struct tcb *tcp;
{
int optlen;
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
if (tcp->u_args[1] == SOL_SOCKET) {
tprintf("SOL_SOCKET, ");
printxval(sockoptions, tcp->u_args[2], "SO_???");
tprintf(", ");
} else {
/* XXX - should know socket family here */
printxval(protocols, tcp->u_args[1], "IPPROTO_???");
tprintf(", %u, ", tcp->u_args[2]);
}
} else {
if (syserror(tcp)) {
tprintf("%#x, %#x", tcp->u_args[3], tcp->u_args[4]);
return 0;
}
if (tcp->u_args[4] == 0 || umove(tcp->pid, tcp->u_args[4],
sizeof optlen, (char *)&optlen) < 0) {
tprintf("%#x, (int *)%#x",
tcp->u_args[3], tcp->u_args[4]);
return 0;
}
(void)printstr(tcp->pid, tcp->u_args[3], optlen);
tprintf(", %u", tcp->u_args[4]);
}
return 0;
}
int
sys_setsockopt(tcp)
struct tcb *tcp;
{
if (entering(tcp)) {
tprintf("%u, ", tcp->u_args[0]);
if (tcp->u_args[1] == SOL_SOCKET) {
tprintf("SOL_SOCKET, ");
printxval(sockoptions, tcp->u_args[2], "SO_???");
tprintf(", ");
} else {
/* XXX - should know socket family here */
printxval(protocols, tcp->u_args[1], "IPPROTO_???");
tprintf(", %u, ", tcp->u_args[2]);
}
(void)printstr(tcp->pid, tcp->u_args[3], tcp->u_args[4]);
tprintf(", %u", tcp->u_args[4]);
}
return 0;
}