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

Function load_extra_delays

tools/ipfw/dummynet.c:866–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

864#define ED_EFMT(s) EX_DATAERR,"error in %s at line %d: "#s,filename,lineno
865
866static void
867load_extra_delays(const char *filename, struct dn_profile *p,
868 struct dn_link *link)
869{
870 char line[ED_MAX_LINE_LEN];
871 FILE *f;
872 int lineno = 0;
873 int i;
874
875 int samples = -1;
876 double loss = -1.0;
877 char profile_name[ED_MAX_NAME_LEN];
878 int delay_first = -1;
879 int do_points = 0;
880 struct point points[ED_MAX_SAMPLES_NO];
881 int points_no = 0;
882
883 /* XXX link never NULL? */
884 p->link_nr = link->link_nr;
885
886 profile_name[0] = '\0';
887 f = fopen(filename, "r");
888 if (f == NULL)
889 err(EX_UNAVAILABLE, "fopen: %s", filename);
890
891 while (fgets(line, ED_MAX_LINE_LEN, f)) { /* read commands */
892 char *s, *cur = line, *name = NULL, *arg = NULL;
893
894 ++lineno;
895
896 /* parse the line */
897 while (cur) {
898 s = strsep(&cur, ED_SEPARATORS);
899 if (s == NULL || *s == '#')
900 break;
901 if (*s == '\0')
902 continue;
903 if (arg)
904 errx(ED_EFMT("too many arguments"));
905 if (name == NULL)
906 name = s;
907 else
908 arg = s;
909 }
910 if (name == NULL) /* empty line */
911 continue;
912 if (arg == NULL)
913 errx(ED_EFMT("missing arg for %s"), name);
914
915 if (!strcasecmp(name, ED_TOK_SAMPLES)) {
916 if (samples > 0)
917 errx(ED_EFMT("duplicate ``samples'' line"));
918 if (atoi(arg) <=0)
919 errx(ED_EFMT("invalid number of samples"));
920 samples = atoi(arg);
921 if (samples>ED_MAX_SAMPLES_NO)
922 errx(ED_EFMT("too many samples, maximum is %d"),
923 ED_MAX_SAMPLES_NO);

Callers 1

ipfw_config_pipeFunction · 0.85

Calls 6

strsepFunction · 0.85
strcasecmpFunction · 0.85
read_bandwidthFunction · 0.85
is_valid_numberFunction · 0.85
qsortFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected