Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145982058
D9588.id25235.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
9 KB
Referenced Files
None
Subscribers
None
D9588.id25235.diff
View Options
Index: usr.bin/sockstat/sockstat.c
===================================================================
--- usr.bin/sockstat/sockstat.c
+++ usr.bin/sockstat/sockstat.c
@@ -88,9 +88,9 @@
static int *ports;
-#define INT_BIT (sizeof(int)*CHAR_BIT)
-#define SET_PORT(p) do { ports[p / INT_BIT] |= 1 << (p % INT_BIT); } while (0)
-#define CHK_PORT(p) (ports[p / INT_BIT] & (1 << (p % INT_BIT)))
+#define INT_BIT (sizeof(int)*CHAR_BIT)
+#define SET_PORT(p) do { ports[p / INT_BIT] |= 1 << (p % INT_BIT); } while (0)
+#define CHK_PORT(p) (ports[p / INT_BIT] & (1 << (p % INT_BIT)))
struct addr {
struct sockaddr_storage address;
@@ -111,7 +111,7 @@
struct sock *next;
};
-#define HASHSIZE 1009
+#define HASHSIZE 1009
static struct sock *sockhash[HASHSIZE];
static struct xfile *xfiles;
@@ -131,7 +131,6 @@
return (len);
}
-
static int
get_proto_type(const char *proto)
{
@@ -147,7 +146,6 @@
return (pent->p_proto);
}
-
static void
init_protos(int num)
{
@@ -167,7 +165,6 @@
numprotos = proto_count;
}
-
static int
parse_protos(char *protospec)
{
@@ -190,7 +187,6 @@
return (proto_index);
}
-
static void
parse_ports(const char *portspec)
{
@@ -359,27 +355,27 @@
err(1, "malloc()");
switch (xladdr->address.sa.sa_family) {
case AF_INET:
-#define __IN_IS_ADDR_LOOPBACK(pina) \
+#define __IN_IS_ADDR_LOOPBACK(pina) \
((ntohl((pina)->s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
- if (!__IN_IS_ADDR_LOOPBACK(&xladdr->address.sin.sin_addr))
+ if (!__IN_IS_ADDR_LOOPBACK(
+ &xladdr->address.sin.sin_addr))
local_all_loopback = 0;
-#undef __IN_IS_ADDR_LOOPBACK
- sockaddr(&laddr->address,
- AF_INET,
- &xladdr->address.sin.sin_addr,
- htons(xinpcb->local_port));
+#undef __IN_IS_ADDR_LOOPBACK
+ sockaddr(&laddr->address, AF_INET,
+ &xladdr->address.sin.sin_addr,
+ htons(xinpcb->local_port));
break;
case AF_INET6:
- if (!IN6_IS_ADDR_LOOPBACK(&xladdr->address.sin6.sin6_addr))
+ if (!IN6_IS_ADDR_LOOPBACK(
+ &xladdr->address.sin6.sin6_addr))
local_all_loopback = 0;
- sockaddr(&laddr->address,
- AF_INET6,
- &xladdr->address.sin6.sin6_addr,
- htons(xinpcb->local_port));
+ sockaddr(&laddr->address, AF_INET6,
+ &xladdr->address.sin6.sin6_addr,
+ htons(xinpcb->local_port));
break;
default:
errx(1, "address family %d not supported",
- xladdr->address.sa.sa_family);
+ xladdr->address.sa.sa_family);
}
laddr->next = NULL;
if (prev_laddr == NULL)
@@ -389,33 +385,38 @@
prev_laddr = laddr;
}
if (sock->laddr == NULL) {
- if ((sock->laddr = calloc(1, sizeof(struct addr))) == NULL)
+ if ((sock->laddr =
+ calloc(1, sizeof(struct addr))) == NULL)
err(1, "malloc()");
sock->laddr->address.ss_family = sock->family;
if (sock->family == AF_INET)
- sock->laddr->address.ss_len = sizeof(struct sockaddr_in);
+ sock->laddr->address.ss_len =
+ sizeof(struct sockaddr_in);
else
- sock->laddr->address.ss_len = sizeof(struct sockaddr_in6);
+ sock->laddr->address.ss_len =
+ sizeof(struct sockaddr_in6);
local_all_loopback = 0;
}
if ((sock->faddr = calloc(1, sizeof(struct addr))) == NULL)
err(1, "malloc()");
sock->faddr->address.ss_family = sock->family;
if (sock->family == AF_INET)
- sock->faddr->address.ss_len = sizeof(struct sockaddr_in);
+ sock->faddr->address.ss_len =
+ sizeof(struct sockaddr_in);
else
- sock->faddr->address.ss_len = sizeof(struct sockaddr_in6);
+ sock->faddr->address.ss_len =
+ sizeof(struct sockaddr_in6);
no_stcb = 1;
while (offset < len) {
xstcb = (struct xsctp_tcb *)(void *)(buf + offset);
offset += sizeof(struct xsctp_tcb);
if (no_stcb) {
- if (opt_l &&
- (sock->vflag & vflag) &&
+ if (opt_l && (sock->vflag & vflag) &&
(!opt_L || !local_all_loopback) &&
((xinpcb->flags & SCTP_PCB_FLAGS_UDPTYPE) ||
(xstcb->last == 1))) {
- hash = (int)((uintptr_t)sock->socket % HASHSIZE);
+ hash = (int)((uintptr_t)sock->socket %
+ HASHSIZE);
sock->next = sockhash[hash];
sockhash[hash] = sock;
} else {
@@ -448,37 +449,40 @@
prev_laddr = NULL;
local_all_loopback = 1;
while (offset < len) {
- xladdr = (struct xsctp_laddr *)(void *)(buf + offset);
+ xladdr = (struct xsctp_laddr *)(void *)(buf +
+ offset);
offset += sizeof(struct xsctp_laddr);
if (xladdr->last == 1)
break;
if (!opt_c)
continue;
- if ((laddr = calloc(1, sizeof(struct addr))) == NULL)
+ if ((laddr =
+ calloc(1, sizeof(struct addr))) == NULL)
err(1, "malloc()");
switch (xladdr->address.sa.sa_family) {
case AF_INET:
-#define __IN_IS_ADDR_LOOPBACK(pina) \
+#define __IN_IS_ADDR_LOOPBACK(pina) \
((ntohl((pina)->s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
- if (!__IN_IS_ADDR_LOOPBACK(&xladdr->address.sin.sin_addr))
+ if (!__IN_IS_ADDR_LOOPBACK(
+ &xladdr->address.sin.sin_addr))
local_all_loopback = 0;
-#undef __IN_IS_ADDR_LOOPBACK
- sockaddr(&laddr->address,
- AF_INET,
- &xladdr->address.sin.sin_addr,
- htons(xstcb->local_port));
+#undef __IN_IS_ADDR_LOOPBACK
+ sockaddr(&laddr->address, AF_INET,
+ &xladdr->address.sin.sin_addr,
+ htons(xstcb->local_port));
break;
case AF_INET6:
- if (!IN6_IS_ADDR_LOOPBACK(&xladdr->address.sin6.sin6_addr))
+ if (!IN6_IS_ADDR_LOOPBACK(
+ &xladdr->address.sin6.sin6_addr))
local_all_loopback = 0;
- sockaddr(&laddr->address,
- AF_INET6,
- &xladdr->address.sin6.sin6_addr,
- htons(xstcb->local_port));
+ sockaddr(&laddr->address, AF_INET6,
+ &xladdr->address.sin6.sin6_addr,
+ htons(xstcb->local_port));
break;
default:
- errx(1, "address family %d not supported",
- xladdr->address.sa.sa_family);
+ errx(1,
+ "address family %d not supported",
+ xladdr->address.sa.sa_family);
}
laddr->next = NULL;
if (prev_laddr == NULL)
@@ -490,37 +494,40 @@
prev_faddr = NULL;
foreign_all_loopback = 1;
while (offset < len) {
- xraddr = (struct xsctp_raddr *)(void *)(buf + offset);
+ xraddr = (struct xsctp_raddr *)(void *)(buf +
+ offset);
offset += sizeof(struct xsctp_raddr);
if (xraddr->last == 1)
break;
if (!opt_c)
continue;
- if ((faddr = calloc(1, sizeof(struct addr))) == NULL)
+ if ((faddr =
+ calloc(1, sizeof(struct addr))) == NULL)
err(1, "malloc()");
switch (xraddr->address.sa.sa_family) {
case AF_INET:
-#define __IN_IS_ADDR_LOOPBACK(pina) \
+#define __IN_IS_ADDR_LOOPBACK(pina) \
((ntohl((pina)->s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
- if (!__IN_IS_ADDR_LOOPBACK(&xraddr->address.sin.sin_addr))
+ if (!__IN_IS_ADDR_LOOPBACK(
+ &xraddr->address.sin.sin_addr))
foreign_all_loopback = 0;
-#undef __IN_IS_ADDR_LOOPBACK
- sockaddr(&faddr->address,
- AF_INET,
- &xraddr->address.sin.sin_addr,
- htons(xstcb->remote_port));
+#undef __IN_IS_ADDR_LOOPBACK
+ sockaddr(&faddr->address, AF_INET,
+ &xraddr->address.sin.sin_addr,
+ htons(xstcb->remote_port));
break;
case AF_INET6:
- if (!IN6_IS_ADDR_LOOPBACK(&xraddr->address.sin6.sin6_addr))
+ if (!IN6_IS_ADDR_LOOPBACK(
+ &xraddr->address.sin6.sin6_addr))
foreign_all_loopback = 0;
- sockaddr(&faddr->address,
- AF_INET6,
- &xraddr->address.sin6.sin6_addr,
- htons(xstcb->remote_port));
+ sockaddr(&faddr->address, AF_INET6,
+ &xraddr->address.sin6.sin6_addr,
+ htons(xstcb->remote_port));
break;
default:
- errx(1, "address family %d not supported",
- xraddr->address.sa.sa_family);
+ errx(1,
+ "address family %d not supported",
+ xraddr->address.sa.sa_family);
}
faddr->next = NULL;
if (prev_faddr == NULL)
@@ -532,8 +539,10 @@
if (opt_c) {
if ((sock->vflag & vflag) &&
(!opt_L ||
- !(local_all_loopback || foreign_all_loopback))) {
- hash = (int)((uintptr_t)sock->socket % HASHSIZE);
+ !(local_all_loopback ||
+ foreign_all_loopback))) {
+ hash = (int)((uintptr_t)sock->socket %
+ HASHSIZE);
sock->next = sockhash[hash];
sockhash[hash] = sock;
} else {
@@ -646,13 +655,13 @@
if ((inp->inp_fport == 0 && !opt_l) ||
(inp->inp_fport != 0 && !opt_c))
continue;
-#define __IN_IS_ADDR_LOOPBACK(pina) \
+#define __IN_IS_ADDR_LOOPBACK(pina) \
((ntohl((pina)->s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
if (opt_L &&
(__IN_IS_ADDR_LOOPBACK(&inp->inp_faddr) ||
__IN_IS_ADDR_LOOPBACK(&inp->inp_laddr)))
continue;
-#undef __IN_IS_ADDR_LOOPBACK
+#undef __IN_IS_ADDR_LOOPBACK
} else if (inp->inp_vflag & INP_IPV6) {
if ((inp->inp_fport == 0 && !opt_l) ||
(inp->inp_fport != 0 && !opt_c))
@@ -1003,7 +1012,7 @@
case AF_UNIX:
if ((laddr == NULL) || (faddr == NULL))
errx(1, "laddr = %p or faddr = %p is NULL",
- (void *)laddr, (void *)faddr);
+ (void *)laddr, (void *)faddr);
/* server */
if (laddr->address.ss_len > 0) {
pos += printaddr(&laddr->address);
@@ -1018,15 +1027,14 @@
pos += xprintf("-> ");
for (hash = 0; hash < HASHSIZE; ++hash) {
for (s_tmp = sockhash[hash];
- s_tmp != NULL;
- s_tmp = s_tmp->next)
+ s_tmp != NULL;
+ s_tmp = s_tmp->next)
if (s_tmp->pcb == p)
break;
if (s_tmp != NULL)
break;
}
- if (s_tmp == NULL ||
- s_tmp->laddr == NULL ||
+ if (s_tmp == NULL || s_tmp->laddr == NULL ||
s_tmp->laddr->address.ss_len == 0)
pos += xprintf("??");
else
@@ -1144,7 +1152,6 @@
return (pindex);
}
-
static void
usage(void)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 27, 6:06 PM (19 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29038083
Default Alt Text
D9588.id25235.diff (9 KB)
Attached To
Mode
D9588: Fix usr.bin/sockstat/sockstat.c style(9)
Attached
Detach File
Event Timeline
Log In to Comment