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

Function bpf_getdltlist

freebsd/net/bpf.c:2781–2815  ·  view source on GitHub ↗

* Get a list of available data link type of the interface. */

Source from the content-addressed store, hash-verified

2779 * Get a list of available data link type of the interface.
2780 */
2781static int
2782bpf_getdltlist(struct bpf_d *d, struct bpf_dltlist *bfl)
2783{
2784 struct ifnet *ifp;
2785 struct bpf_if *bp;
2786 u_int *lst;
2787 int error, n, n1;
2788
2789 BPF_LOCK_ASSERT();
2790
2791 ifp = d->bd_bif->bif_ifp;
2792 n1 = 0;
2793 CK_LIST_FOREACH(bp, &bpf_iflist, bif_next) {
2794 if (bp->bif_ifp == ifp)
2795 n1++;
2796 }
2797 if (bfl->bfl_list == NULL) {
2798 bfl->bfl_len = n1;
2799 return (0);
2800 }
2801 if (n1 > bfl->bfl_len)
2802 return (ENOMEM);
2803
2804 lst = malloc(n1 * sizeof(u_int), M_TEMP, M_WAITOK);
2805 n = 0;
2806 CK_LIST_FOREACH(bp, &bpf_iflist, bif_next) {
2807 if (bp->bif_ifp != ifp)
2808 continue;
2809 lst[n++] = bp->bif_dlt;
2810 }
2811 error = copyout(lst, bfl->bfl_list, sizeof(u_int) * n);
2812 free(lst, M_TEMP);
2813 bfl->bfl_len = n;
2814 return (error);
2815}
2816
2817/*
2818 * Set the data link type of a BPF instance.

Callers 1

bpfioctlFunction · 0.85

Calls 3

mallocFunction · 0.85
copyoutFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected