PRIVATE_EXTERN CFStringRef inet6_addrlist_copy_description(const inet6_addrlist_t * addr_list_p) { int i; inet6_addrinfo_t * scan; CFMutableStringRef str; str = CFStringCreateMutable(NULL, 0); STRING_APPEND(str, "{"); for (i = 0, scan = addr_list_p->list; i < addr_list_p->count; i++, scan++) { char ntopbuf[INET6_ADDRSTRLEN]; char pltime_str[32]; char vltime_str[32]; lifetime_to_str(scan->valid_lifetime, vltime_str, sizeof(vltime_str)); lifetime_to_str(scan->preferred_lifetime, pltime_str, sizeof(pltime_str)); STRING_APPEND(str, "%s%s/%d flags 0x%04x vltime=%s pltime=%s\n", i == 0 ? "\n" : "", inet_ntop(AF_INET6, &scan->addr, ntopbuf, sizeof(ntopbuf)), scan->prefix_length, scan->addr_flags, vltime_str, pltime_str); } STRING_APPEND(str, "}"); return (str); }
PRIVATE_EXTERN void print_bytes_sep_cfstr(CFMutableStringRef str, uint8_t * data_p, int n_bytes, char separator) { int i; for (i = 0; i < n_bytes; i++) { char sep[3]; if (i == 0) { sep[0] = '\0'; } else { if ((i % 8) == 0 && separator == ' ') { sep[0] = sep[1] = ' '; sep[2] = '\0'; } else { sep[0] = separator; sep[1] = '\0'; } } STRING_APPEND(str, "%s%02x", sep, data_p[i]); } return; }
static int scan_c_comment(Token *tok, Tokenizer *tokz) { STRING_DECL_P(s, "/*"); int c; int st=0; while(1){ c=GETCH(); if(c==EOF){ STRING_FREE(s); return E_TOKZ_UNEXPECTED_EOF; } STRING_APPEND(s, c); if(c=='\n'){ INC_LINE(); }else if(st==0 && c=='*'){ st=1; }else if(st==1){ if(c=='/') break; st=0; } } STRING_FINISH(s); TOK_SET_COMMENT(tok, s); return 0; }
static void DHCPLeasePrintToString(CFMutableStringRef str, DHCPLeaseRef lease_p) { STRING_APPEND(str, "IP " IP_FORMAT " Start %d Length", IP_LIST(&lease_p->our_ip), (int)lease_p->lease_start); if (lease_p->lease_length == DHCP_INFINITE_LEASE) { STRING_APPEND(str, " infinite"); } else { STRING_APPEND(str, " %d", (int)lease_p->lease_length); } if (lease_p->router_ip.s_addr != 0) { STRING_APPEND(str, " Router IP " IP_FORMAT, IP_LIST(&lease_p->router_ip)); if (lease_p->router_hwaddr_length > 0) { char link_string[MAX_LINK_ADDR_LEN * 3]; link_addr_to_string(link_string, sizeof(link_string), lease_p->router_hwaddr, lease_p->router_hwaddr_length); STRING_APPEND(str, " MAC %s", link_string); } } if (lease_p->ssid != NULL) { STRING_APPEND(str, " SSID '%@'", lease_p->ssid); } return; }
static int scan_identifier(Token *tok, Tokenizer *tokz, int c) { STRING_DECL(s); do{ STRING_APPEND(s, c); c=GETCH(); }while(isalnum(c) || c=='_' || c=='$'); UNGETCH(c); STRING_FINISH(s); TOK_SET_IDENT(tok, s); return 0; }
static void DHCPLeaseListLog(DHCPLeaseListRef list_p) { int count; int i; CFMutableStringRef str; str = CFStringCreateMutable(NULL, 0); count = dynarray_count(list_p); for (i = 0; i < count; i++) { DHCPLeaseRef lease_p = dynarray_element(list_p, i); STRING_APPEND(str, "\n%d. ", i + 1); DHCPLeasePrintToString(str, lease_p); } my_log(~LOG_DEBUG, "DHCPLeaseList has %d element(s)%@", count, str); CFRelease(str); return; }
static int scan_line_comment(Token *tok, Tokenizer *tokz) { STRING_DECL_P(s, "#"); int c; c=GETCH(); while(c!='\n' && c!=EOF){ STRING_APPEND(s, c); c=GETCH(); } UNGETCH(c); STRING_FINISH(s); TOK_SET_COMMENT(tok, s); return 0; }
void print_bytes_cfstr(CFMutableStringRef str, const uint8_t * data_p, int n_bytes) { int i; for (i = 0; i < n_bytes; i++) { char * space; if (i == 0) { space = ""; } else if ((i % 8) == 0) { space = " "; } else { space = " "; } STRING_APPEND(str, "%s%02x", space, data_p[i]); } return; }
static int scan_string(Token *tok, Tokenizer *tokz, bool escapes) { STRING_DECL(s); int c; while(1){ c=GETCH(); if(c=='"') break; if(c=='\n'){ UNGETCH(c); STRING_FREE(s); return E_TOKZ_UNEXPECTED_EOL; } if(c=='\\' && escapes){ c=scan_char_escape(tokz); if(c==-2){ STRING_FREE(s); return E_TOKZ_UNEXPECTED_EOL; } } if(c==EOF){ STRING_FREE(s); return E_TOKZ_UNEXPECTED_EOF; } STRING_APPEND(s, c); } STRING_FINISH(s); TOK_SET_STRING(tok, s); return 0; }
/* * Function: print_data_cfstr * Purpose: * Displays the buffer as a series of 8-bit hex numbers with an ASCII * representation off to the side. */ PRIVATE_EXTERN void print_data_cfstr(CFMutableStringRef str, const uint8_t * data_p, int n_bytes) { #define CHARS_PER_LINE 16 char line_buf[CHARS_PER_LINE + 1]; int line_pos; int offset; for (line_pos = 0, offset = 0; offset < n_bytes; offset++, data_p++) { if (line_pos == 0) { STRING_APPEND(str, "%04x ", offset); } line_buf[line_pos] = isprint(*data_p) ? *data_p : '.'; STRING_APPEND(str, " %02x", *data_p); line_pos++; if (line_pos == CHARS_PER_LINE) { line_buf[CHARS_PER_LINE] = '\0'; STRING_APPEND(str, " %s\n", line_buf); line_pos = 0; } else if (line_pos == (CHARS_PER_LINE / 2)) STRING_APPEND(str, " "); } if (line_pos) { /* need to finish up the line */ char * extra_space = ""; if (line_pos < (CHARS_PER_LINE / 2)) { extra_space = " "; } for (; line_pos < CHARS_PER_LINE; line_pos++) { STRING_APPEND(str, " "); line_buf[line_pos] = ' '; } line_buf[CHARS_PER_LINE] = '\0'; STRING_APPEND(str, " %s%s\n", extra_space, line_buf); } return; }
void dhcp_packet_print_cfstr(CFMutableStringRef str, struct dhcp * dp, int pkt_len) { int i; int j; int len; if (pkt_len < sizeof(struct dhcp)) { STRING_APPEND(str, "Packet is too short %d < %d\n", pkt_len, (int)sizeof(struct dhcp)); return; } STRING_APPEND(str, "op = "); if (dp->dp_op == BOOTREQUEST) { STRING_APPEND(str, "BOOTREQUEST\n"); } else if (dp->dp_op == BOOTREPLY) { STRING_APPEND(str, "BOOTREPLY\n"); } else { i = dp->dp_op; STRING_APPEND(str, "OP(%d)\n", i); } i = dp->dp_htype; STRING_APPEND(str, "htype = %d\n", i); STRING_APPEND(str, "flags = %x\n", ntohs(dp->dp_flags)); len = dp->dp_hlen; STRING_APPEND(str, "hlen = %d\n", len); i = dp->dp_hops; STRING_APPEND(str, "hops = %d\n", i); STRING_APPEND(str, "xid = %lu\n", (u_long)ntohl(dp->dp_xid)); STRING_APPEND(str, "secs = %hu\n", ntohs(dp->dp_secs)); STRING_APPEND(str, "ciaddr = %s\n", inet_ntoa(dp->dp_ciaddr)); STRING_APPEND(str, "yiaddr = %s\n", inet_ntoa(dp->dp_yiaddr)); STRING_APPEND(str, "siaddr = %s\n", inet_ntoa(dp->dp_siaddr)); STRING_APPEND(str, "giaddr = %s\n", inet_ntoa(dp->dp_giaddr)); STRING_APPEND(str, "chaddr = "); for (j = 0; j < len; j++) { i = dp->dp_chaddr[j]; STRING_APPEND(str, "%0x", i); if (j < (len - 1)) STRING_APPEND(str, ":"); } STRING_APPEND(str, "\n"); STRING_APPEND(str, "sname = %s\n", dp->dp_sname); STRING_APPEND(str, "file = %s\n", dp->dp_file); { dhcpol_t t; dhcpol_init(&t); if (dhcpol_parse_packet(&t, dp, pkt_len, NULL)) { STRING_APPEND(str, "options:\n"); dhcpol_print_cfstr(str, &t); } dhcpol_free(&t); } return; }