MCPcopy Create free account
hub / github.com/F-Stack/f-stack / print_nhop_entry_sysctl

Function print_nhop_entry_sysctl

tools/netstat/nhops.c:246–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244#endif
245
246static void
247print_nhop_entry_sysctl(const char *name, struct rt_msghdr *rtm, struct nhop_external *nh)
248{
249 char buffer[128];
250 char iface_name[128];
251 int protrusion;
252 char gw_addr[144];
253 struct nhop_addrs *na;
254 struct sockaddr *sa_gw, *sa_ifa;
255
256 xo_open_instance(name);
257
258 snprintf(buffer, sizeof(buffer), "{[:-%d}{:index/%%lu}{]:} ", wid_nhidx);
259 //xo_emit("{t:index/%-lu} ", wid_nhidx, nh->nh_idx);
260 xo_emit(buffer, nh->nh_idx);
261
262 if (Wflag) {
263 char *cp = nh_types[nh->nh_type];
264 xo_emit("{t:type_str/%*s} ", wid_nhtype, cp);
265 }
266 memset(iface_name, 0, sizeof(iface_name));
267 if (nh->ifindex < (uint32_t)ifmap_size) {
268 strlcpy(iface_name, ifmap[nh->ifindex].ifname,
269 sizeof(iface_name));
270 if (*iface_name == '\0')
271 strlcpy(iface_name, "---", sizeof(iface_name));
272 }
273
274 na = (struct nhop_addrs *)((char *)nh + nh->nh_len);
275 //inet_ntop(nh->nh_family, &nh->nh_src, src_addr, sizeof(src_addr));
276 //protrusion = p_addr("ifa", src_addr, wid_dst);
277 sa_gw = (struct sockaddr *)((char *)na + na->gw_sa_off);
278 sa_ifa = (struct sockaddr *)((char *)na + na->src_sa_off);
279 protrusion = p_sockaddr("ifa", sa_ifa, NULL, RTF_HOST, wid_dst);
280
281 if (nh->nh_flags & NHF_GATEWAY) {
282 const char *cp;
283 cp = fmt_sockaddr(sa_gw, NULL, RTF_HOST);
284 strlcpy(gw_addr, cp, sizeof(gw_addr));
285 } else
286 snprintf(gw_addr, sizeof(gw_addr), "%s/resolve", iface_name);
287 protrusion = print_addr("gateway", gw_addr, wid_dst - protrusion);
288
289 nhop_map_update(&global_nhop_map, nh->nh_idx, gw_addr, iface_name);
290
291 snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ",
292 wid_flags - protrusion);
293
294 //p_nhflags(nh->nh_flags, buffer);
295 print_flags_generic(rtm->rtm_flags, rt_bits, buffer, "rt_flags_pretty");
296
297 if (Wflag) {
298 xo_emit("{t:use/%*lu} ", wid_pksent, nh->nh_pksent);
299 xo_emit("{t:mtu/%*lu} ", wid_mtu, nh->nh_mtu);
300 }
301 //printf("IDX: %d IFACE: %s FAMILY: %d TYPE: %d FLAGS: %X GW \n");
302
303 if (Wflag)

Callers 1

print_nhops_sysctlFunction · 0.85

Calls 11

xo_open_instanceFunction · 0.85
snprintfFunction · 0.85
xo_emitFunction · 0.85
memsetFunction · 0.85
fmt_sockaddrFunction · 0.85
nhop_map_updateFunction · 0.85
print_flags_genericFunction · 0.85
xo_close_instanceFunction · 0.85
p_sockaddrFunction · 0.70
print_addrFunction · 0.70
strlcpyFunction · 0.50

Tested by

no test coverage detected