/* Fill dest with the text of option 'option'. */ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p) { int type, optlen; u_int16_t val_u16; int16_t val_s16; u_int32_t val_u32; int32_t val_s32; int len = option[OPT_LEN - 2]; dest += sprintf(dest, "%s=", type_p->name); type = type_p->flags & TYPE_MASK; optlen = option_lengths[type]; for(;;) { switch (type) { case OPTION_IP_PAIR: dest += sprintip(dest, "", option); *(dest++) = '/'; option += 4; optlen = 4; case OPTION_IP: /* Works regardless of host byte order. */ dest += sprintip(dest, "", option); break; case OPTION_BOOLEAN: dest += sprintf(dest, *option ? "yes " : "no "); break; case OPTION_U8: dest += sprintf(dest, "%u ", *option); break; case OPTION_U16: memcpy(&val_u16, option, 2); dest += sprintf(dest, "%u ", ntohs(val_u16)); break; case OPTION_S16: memcpy(&val_s16, option, 2); dest += sprintf(dest, "%d ", ntohs(val_s16)); break; case OPTION_U32: memcpy(&val_u32, option, 4); dest += sprintf(dest, "%lu ", (unsigned long) ntohl(val_u32)); break; case OPTION_S32: memcpy(&val_s32, option, 4); dest += sprintf(dest, "%ld ", (long) ntohl(val_s32)); break; case OPTION_STRING: memcpy(dest, option, len); dest[len] = '\0'; return; /* Short circuit this case */ } option += optlen; len -= optlen; if (len <= 0) break; } }
/* Fill dest with the text of option 'option'. */ static void fill_options(char *dest, unsigned char *option, struct dhcp_option *type_p) { int type, optlen; u_int16_t val_u16; int16_t val_s16; u_int32_t val_u32; int32_t val_s32; int len = option[OPT_LEN - 2]; dest += sprintf(dest, "%s=", type_p->name); type = type_p->flags & TYPE_MASK; /* foxconn added start by EricHuang, 12/20/2007 */ if ( strcmp(type_p->name, "rfc3442") == 0 ) { FILE *fp=0; /*foxconn added start, water, 03/08/10, @option249*/ /*fp = fopen("/tmp/udhcpc.routes", "w+");*/ fp = fopen("/tmp/udhcpc.routes", "a+"); /*foxconn added end, water, 03/08/10*/ if (fp) { fwrite(option, 1, len, fp); fclose(fp); } dest += sprintf(dest, "%d", len); /* only save the length here ... */ return; } /* foxconn added end by EricHuang, 12/20/2007 */ /* foxconn added start by EricHuang, 03/12/2008 */ if ( strcmp(type_p->name, "sroute") == 0 ) { FILE *fp=0; fp = fopen("/tmp/udhcpc.routes2", "w+"); if (fp) { fwrite(option, 1, len, fp); fclose(fp); } dest += sprintf(dest, "%d", len); /* only save the length here ... */ return; } /* foxconn added end by EricHuang, 03/12/2008 */ optlen = option_lengths[type]; for(;;) { switch (type) { case OPTION_IP_PAIR: dest += sprintip(dest, "", option); *(dest++) = '/'; option += 4; optlen = 4; case OPTION_IP: /* Works regardless of host byte order. */ dest += sprintip(dest, "", option); break; case OPTION_BOOLEAN: dest += sprintf(dest, *option ? "yes " : "no "); break; case OPTION_U8: dest += sprintf(dest, "%u ", *option); break; case OPTION_U16: memcpy(&val_u16, option, 2); dest += sprintf(dest, "%u ", ntohs(val_u16)); break; case OPTION_S16: memcpy(&val_s16, option, 2); dest += sprintf(dest, "%d ", ntohs(val_s16)); break; case OPTION_U32: memcpy(&val_u32, option, 4); dest += sprintf(dest, "%lu ", (unsigned long) ntohl(val_u32)); break; case OPTION_S32: memcpy(&val_s32, option, 4); dest += sprintf(dest, "%ld ", (long) ntohl(val_s32)); break; case OPTION_STRING: memcpy(dest, option, len); dest[len] = '\0'; return; /* Short circuit this case */ } option += optlen; len -= optlen; if (len <= 0) break; } }