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

Function ipfw_get_config

tools/ipfw/ipfw2.c:2912–2960  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2910 */
2911
2912static int
2913ipfw_get_config(struct cmdline_opts *co, struct format_opts *fo,
2914 ipfw_cfg_lheader **pcfg, size_t *psize)
2915{
2916 ipfw_cfg_lheader *cfg;
2917 size_t sz;
2918 int i;
2919
2920
2921 if (co->test_only != 0) {
2922 fprintf(stderr, "Testing only, list disabled\n");
2923 return (0);
2924 }
2925
2926 /* Start with some data size */
2927 sz = 4096;
2928 cfg = NULL;
2929
2930 for (i = 0; i < 16; i++) {
2931 if (cfg != NULL)
2932 free(cfg);
2933 if ((cfg = calloc(1, sz)) == NULL)
2934 return (ENOMEM);
2935
2936 cfg->flags = fo->flags;
2937 cfg->start_rule = fo->first;
2938 cfg->end_rule = fo->last;
2939
2940 if (do_get3(IP_FW_XGET, &cfg->opheader, &sz) != 0) {
2941 if (errno != ENOMEM) {
2942 free(cfg);
2943 return (errno);
2944 }
2945
2946 /* Buffer size is not enough. Try to increase */
2947 sz = sz * 2;
2948 if (sz < cfg->size)
2949 sz = cfg->size;
2950 continue;
2951 }
2952
2953 *pcfg = cfg;
2954 *psize = sz;
2955 return (0);
2956 }
2957
2958 free(cfg);
2959 return (ENOMEM);
2960}
2961
2962static int
2963lookup_host (char *host, struct in_addr *ipaddr)

Callers 2

ipfw_sets_handlerFunction · 0.85
ipfw_listFunction · 0.85

Calls 3

callocFunction · 0.85
do_get3Function · 0.85
freeFunction · 0.50

Tested by

no test coverage detected