inet.c (303267) | inet.c (311670) |
---|---|
1/*- 2 * Copyright (c) 1983, 1988, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 30#if 0 31#ifndef lint 32static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; 33#endif /* not lint */ 34#endif 35 36#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1983, 1988, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 20 unchanged lines hidden (view full) --- 29 30#if 0 31#ifndef lint 32static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; 33#endif /* not lint */ 34#endif 35 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: stable/11/usr.bin/netstat/inet.c 303267 2016-07-24 14:50:16Z tuexen $"); | 37__FBSDID("$FreeBSD: stable/11/usr.bin/netstat/inet.c 311670 2017-01-08 07:25:22Z delphij $"); |
38 39#include <sys/param.h> 40#include <sys/queue.h> 41#include <sys/domain.h> 42#include <sys/protosw.h> 43#include <sys/socket.h> 44#include <sys/socketvar.h> 45#include <sys/sysctl.h> --- 33 unchanged lines hidden (view full) --- 79#include <stdlib.h> 80#include <stdbool.h> 81#include <string.h> 82#include <unistd.h> 83#include <libxo/xo.h> 84#include "netstat.h" 85#include "nl_defs.h" 86 | 38 39#include <sys/param.h> 40#include <sys/queue.h> 41#include <sys/domain.h> 42#include <sys/protosw.h> 43#include <sys/socket.h> 44#include <sys/socketvar.h> 45#include <sys/sysctl.h> --- 33 unchanged lines hidden (view full) --- 79#include <stdlib.h> 80#include <stdbool.h> 81#include <string.h> 82#include <unistd.h> 83#include <libxo/xo.h> 84#include "netstat.h" 85#include "nl_defs.h" 86 |
87char *inetname(struct in_addr *); | |
88void inetprint(const char *, struct in_addr *, int, const char *, int, 89 const int); 90#ifdef INET6 91static int udp_done, tcp_done, sdp_done; 92#endif /* INET6 */ 93 94static int 95pcblist_sysctl(int proto, const char *name, char **bufp, int istcp __unused) --- 1306 unchanged lines hidden (view full) --- 1402 */ 1403void 1404inetprint(const char *container, struct in_addr *in, int port, 1405 const char *proto, int num_port, const int af1) 1406{ 1407 struct servent *sp = 0; 1408 char line[80], *cp; 1409 int width; | 87void inetprint(const char *, struct in_addr *, int, const char *, int, 88 const int); 89#ifdef INET6 90static int udp_done, tcp_done, sdp_done; 91#endif /* INET6 */ 92 93static int 94pcblist_sysctl(int proto, const char *name, char **bufp, int istcp __unused) --- 1306 unchanged lines hidden (view full) --- 1401 */ 1402void 1403inetprint(const char *container, struct in_addr *in, int port, 1404 const char *proto, int num_port, const int af1) 1405{ 1406 struct servent *sp = 0; 1407 char line[80], *cp; 1408 int width; |
1409 size_t alen, plen; |
|
1410 1411 if (container) 1412 xo_open_container(container); 1413 1414 if (Wflag) | 1410 1411 if (container) 1412 xo_open_container(container); 1413 1414 if (Wflag) |
1415 sprintf(line, "%s.", inetname(in)); | 1415 snprintf(line, sizeof(line), "%s.", inetname(in)); |
1416 else | 1416 else |
1417 sprintf(line, "%.*s.", (Aflag && !num_port) ? 12 : 16, inetname(in)); 1418 cp = strchr(line, '\0'); | 1417 snprintf(line, sizeof(line), "%.*s.", 1418 (Aflag && !num_port) ? 12 : 16, inetname(in)); 1419 alen = strlen(line); 1420 cp = line + alen; |
1419 if (!num_port && port) 1420 sp = getservbyport((int)port, proto); 1421 if (sp || port == 0) | 1421 if (!num_port && port) 1422 sp = getservbyport((int)port, proto); 1423 if (sp || port == 0) |
1422 sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); | 1424 snprintf(cp, sizeof(line) - alen, 1425 "%.15s ", sp ? sp->s_name : "*"); |
1423 else | 1426 else |
1424 sprintf(cp, "%d ", ntohs((u_short)port)); | 1427 snprintf(cp, sizeof(line) - alen, 1428 "%d ", ntohs((u_short)port)); |
1425 width = (Aflag && !Wflag) ? 18 : 1426 ((!Wflag || af1 == AF_INET) ? 22 : 45); 1427 if (Wflag) 1428 xo_emit("{d:target/%-*s} ", width, line); 1429 else 1430 xo_emit("{d:target/%-*.*s} ", width, width, line); 1431 | 1429 width = (Aflag && !Wflag) ? 18 : 1430 ((!Wflag || af1 == AF_INET) ? 22 : 45); 1431 if (Wflag) 1432 xo_emit("{d:target/%-*s} ", width, line); 1433 else 1434 xo_emit("{d:target/%-*.*s} ", width, width, line); 1435 |
1432 int alen = cp - line - 1, plen = strlen(cp) - 1; | 1436 plen = strlen(cp) - 1; 1437 alen--; |
1433 xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, 1434 plen, cp); 1435 1436 if (container) 1437 xo_close_container(container); 1438} 1439 1440/* --- 29 unchanged lines hidden (view full) --- 1470 } 1471 if (inp->s_addr == INADDR_ANY) 1472 strcpy(line, "*"); 1473 else if (cp) { 1474 strlcpy(line, cp, sizeof(line)); 1475 } else { 1476 inp->s_addr = ntohl(inp->s_addr); 1477#define C(x) ((u_int)((x) & 0xff)) | 1438 xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, 1439 plen, cp); 1440 1441 if (container) 1442 xo_close_container(container); 1443} 1444 1445/* --- 29 unchanged lines hidden (view full) --- 1475 } 1476 if (inp->s_addr == INADDR_ANY) 1477 strcpy(line, "*"); 1478 else if (cp) { 1479 strlcpy(line, cp, sizeof(line)); 1480 } else { 1481 inp->s_addr = ntohl(inp->s_addr); 1482#define C(x) ((u_int)((x) & 0xff)) |
1478 sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24), 1479 C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr)); | 1483 snprintf(line, sizeof(line), "%u.%u.%u.%u", 1484 C(inp->s_addr >> 24), C(inp->s_addr >> 16), 1485 C(inp->s_addr >> 8), C(inp->s_addr)); |
1480 } 1481 return (line); 1482} | 1486 } 1487 return (line); 1488} |