Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/networking/libiproute/utils.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/networking/libiproute/utils.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * utils.c … … 12 13 13 14 #include "libbb.h" 14 15 #include <string.h>16 #include <unistd.h>17 18 15 #include "utils.h" 19 16 #include "inet_common.h" … … 32 29 return 0; 33 30 } 34 31 //XXX: FIXME: use some libbb function instead 35 32 int get_unsigned(unsigned *val, char *arg, int base) 36 33 { … … 47 44 } 48 45 49 int get_u32( __u32* val, char *arg, int base)46 int get_u32(uint32_t * val, char *arg, int base) 50 47 { 51 48 unsigned long res; … … 61 58 } 62 59 63 int get_u16( __u16* val, char *arg, int base)60 int get_u16(uint16_t * val, char *arg, int base) 64 61 { 65 62 unsigned long res; … … 75 72 } 76 73 77 int get_u8( __u8* val, char *arg, int base)74 int get_u8(uint8_t * val, char *arg, int base) 78 75 { 79 76 unsigned long res; … … 89 86 } 90 87 91 int get_s16( __s16* val, char *arg, int base)88 int get_s16(int16_t * val, char *arg, int base) 92 89 { 93 90 long res; … … 103 100 } 104 101 105 int get_s8( __s8* val, char *arg, int base)102 int get_s8(int8_t * val, char *arg, int base) 106 103 { 107 104 long res; … … 125 122 memset(addr, 0, sizeof(*addr)); 126 123 127 if (strcmp(name, bb_ INET_default) == 0 ||124 if (strcmp(name, bb_str_default) == 0 || 128 125 strcmp(name, "all") == 0 || strcmp(name, "any") == 0) { 129 126 addr->family = family; … … 169 166 memset(dst, 0, sizeof(*dst)); 170 167 171 if (strcmp(arg, bb_ INET_default) == 0 || strcmp(arg, "any") == 0) {168 if (strcmp(arg, bb_str_default) == 0 || strcmp(arg, "any") == 0) { 172 169 dst->family = family; 173 170 dst->bytelen = 0; … … 178 175 slash = strchr(arg, '/'); 179 176 if (slash) 180 *slash = 0;177 *slash = '\0'; 181 178 err = get_addr_1(dst, arg, family); 182 179 if (err == 0) { … … 197 194 } 198 195 } 199 196 done: 200 197 if (slash) 201 198 *slash = '/'; … … 206 203 { 207 204 if (family == AF_PACKET) { 208 bb_error_msg_and_die("\"%s\" may be inet address, but it is not allowed in this context .", arg);205 bb_error_msg_and_die("\"%s\" may be inet address, but it is not allowed in this context", arg); 209 206 } 210 207 if (get_addr_1(dst, arg, family)) { 211 bb_error_msg_and_die("an inet address is expected rather than \"%s\" .", arg);208 bb_error_msg_and_die("an inet address is expected rather than \"%s\"", arg); 212 209 } 213 210 return 0; … … 217 214 { 218 215 if (family == AF_PACKET) { 219 bb_error_msg_and_die("\"%s\" may be inet address, but it is not allowed in this context .", arg);216 bb_error_msg_and_die("\"%s\" may be inet address, but it is not allowed in this context", arg); 220 217 } 221 218 if (get_prefix_1(dst, arg, family)) { 222 bb_error_msg_and_die("an inet address is expected rather than \"%s\" .", arg);223 } 224 return 0; 225 } 226 227 __u32get_addr32(char *name)219 bb_error_msg_and_die("an inet address is expected rather than \"%s\"", arg); 220 } 221 return 0; 222 } 223 224 uint32_t get_addr32(char *name) 228 225 { 229 226 inet_prefix addr; … … 237 234 void incomplete_command(void) 238 235 { 239 bb_error_msg("Command line is not complete. Try option \"help\""); 240 exit(-1); 241 } 242 243 void invarg(const char * const arg, const char * const opt) 244 { 245 bb_error_msg(bb_msg_invalid_arg, arg, opt); 246 exit(-1); 247 } 248 249 void duparg(char *key, char *arg) 250 { 251 bb_error_msg("duplicate \"%s\": \"%s\" is the second value.", key, arg); 252 exit(-1); 253 } 254 255 void duparg2(char *key, char *arg) 256 { 257 bb_error_msg("either \"%s\" is duplicate, or \"%s\" is a garbage.", key, arg); 258 exit(-1); 259 } 260 261 int matches(char *cmd, char *pattern) 262 { 263 int len = strlen(cmd); 264 265 if (len > strlen(pattern)) { 266 return -1; 267 } 268 return memcmp(pattern, cmd, len); 236 bb_error_msg_and_die("command line is not complete, try option \"help\""); 237 } 238 239 void invarg(const char *arg, const char *opt) 240 { 241 bb_error_msg_and_die(bb_msg_invalid_arg, arg, opt); 242 } 243 244 void duparg(const char *key, const char *arg) 245 { 246 bb_error_msg_and_die("duplicate \"%s\": \"%s\" is the second value", key, arg); 247 } 248 249 void duparg2(const char *key, const char *arg) 250 { 251 bb_error_msg_and_die("either \"%s\" is duplicate, or \"%s\" is garbage", key, arg); 269 252 } 270 253 271 254 int inet_addr_match(inet_prefix * a, inet_prefix * b, int bits) 272 255 { 273 __u32*a1 = a->data;274 __u32*a2 = b->data;256 uint32_t *a1 = a->data; 257 uint32_t *a2 = b->data; 275 258 int words = bits >> 0x05; 276 259 … … 282 265 283 266 if (bits) { 284 __u32w1, w2;285 __u32mask;267 uint32_t w1, w2; 268 uint32_t mask; 286 269 287 270 w1 = a1[words]; … … 295 278 296 279 return 0; 297 }298 299 int __iproute2_hz_internal;300 301 int __get_hz(void)302 {303 int hz = 0;304 FILE *fp = fopen("/proc/net/psched", "r");305 306 if (fp) {307 unsigned nom, denom;308 309 if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2)310 if (nom == 1000000)311 hz = denom;312 fclose(fp);313 }314 if (hz)315 return hz;316 return sysconf(_SC_CLK_TCK);317 280 } 318 281 … … 347 310 } 348 311 } 349 if (len > 0 && (h_ent = gethostbyaddr(addr, len, af)) != NULL) { 350 snprintf(buf, buflen - 1, "%s", h_ent->h_name); 351 return buf; 312 if (len > 0) { 313 h_ent = gethostbyaddr(addr, len, af); 314 if (h_ent != NULL) { 315 safe_strncpy(buf, h_ent->h_name, buflen); 316 return buf; 317 } 352 318 } 353 319 }
Note:
See TracChangeset
for help on using the changeset viewer.