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

Function nhop_map_update

tools/netstat/nhops.c:208–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208void
209nhop_map_update(struct nhop_map *map, uint32_t idx, char *gw, char *ifname)
210{
211 if (idx >= map->size) {
212 uint32_t new_size;
213 size_t sz;
214 if (map->size == 0)
215 new_size = 32;
216 else
217 new_size = map->size * 2;
218 if (new_size <= idx)
219 new_size = roundup(idx + 1, 32);
220
221 sz = new_size * (sizeof(struct nhop_entry));
222 if ((map->ptr = realloc(map->ptr, sz)) == NULL)
223 errx(2, "realloc(%zu) failed", sz);
224
225 memset(&map->ptr[map->size], 0, (new_size - map->size) * sizeof(struct nhop_entry));
226 map->size = new_size;
227 }
228
229 strlcpy(map->ptr[idx].ifname, ifname, sizeof(map->ptr[idx].ifname));
230 strlcpy(map->ptr[idx].gw, gw, sizeof(map->ptr[idx].gw));
231}
232
233#ifndef FSTACK
234static struct nhop_entry *

Callers 2

update_global_mapFunction · 0.85
print_nhop_entry_sysctlFunction · 0.85

Calls 3

memsetFunction · 0.85
reallocFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected