static void parse_note(const char *arg, struct ofpbuf *ofpacts) { struct ofpact_note *note; note = ofpact_put_NOTE(ofpacts); while (*arg != '\0') { uint8_t byte; bool ok; if (*arg == '.') { arg++; } if (*arg == '\0') { break; } byte = hexits_value(arg, 2, &ok); if (!ok) { ovs_fatal(0, "bad hex digit in `note' argument"); } ofpbuf_put(ofpacts, &byte, 1); note = ofpacts->l2; note->length++; arg += 2; } ofpact_update_len(ofpacts, ¬e->ofpact); }
/* Parses as many pairs of hex digits as possible (possibly separated by * spaces) from the beginning of 's', appending bytes for their values to 'b'. * Returns the first character of 's' that is not the first of a pair of hex * digits. If 'n' is nonnull, stores the number of bytes added to 'b' in * '*n'. */ char * ofpbuf_put_hex(struct ofpbuf *b, const char *s, size_t *n) { size_t initial_size = b->size; for (;;) { uint8_t byte; bool ok; s += strspn(s, " \t\r\n"); byte = hexits_value(s, 2, &ok); if (!ok) { if (n) { *n = b->size - initial_size; } return CONST_CAST(char *, s); } ofpbuf_put(b, &byte, 1); s += 2; } }
/* Parses as many pairs of hex digits as possible (possibly separated by * spaces) from the beginning of 's', appending bytes for their values to 'b'. * Returns the first character of 's' that is not the first of a pair of hex * digits. If 'n' is nonnull, stores the number of bytes added to 'b' in * '*n'. */ char * dp_packet_put_hex(struct dp_packet *b, const char *s, size_t *n) { size_t initial_size = dp_packet_size(b); for (;;) { uint8_t byte; bool ok; s += strspn(s, " \t\r\n"); byte = hexits_value(s, 2, &ok); if (!ok) { if (n) { *n = dp_packet_size(b) - initial_size; } return CONST_CAST(char *, s); } dp_packet_put(b, &byte, 1); s += 2; } }
static void parse_note(struct ofpbuf *b, const char *arg) { size_t start_ofs = b->size; struct nx_action_note *nan; int remainder; size_t len; nan = ofputil_put_NXAST_NOTE(b); b->size -= sizeof nan->note; while (*arg != '\0') { uint8_t byte; bool ok; if (*arg == '.') { arg++; } if (*arg == '\0') { break; } byte = hexits_value(arg, 2, &ok); if (!ok) { ovs_fatal(0, "bad hex digit in `note' argument"); } ofpbuf_put(b, &byte, 1); arg += 2; } len = b->size - start_ofs; remainder = len % OFP_ACTION_ALIGN; if (remainder) { ofpbuf_put_zeros(b, OFP_ACTION_ALIGN - remainder); } nan = (struct nx_action_note *)((char *)b->data + start_ofs); nan->len = htons(b->size - start_ofs); }
/* Same as uuid_from_string() but s[UUID_LEN] is not required to be a null byte * to succeed; that is, 's' need only begin with UUID syntax, not consist * entirely of it. */ bool uuid_from_string_prefix(struct uuid *uuid, const char *s) { /* 0 1 2 3 */ /* 012345678901234567890123456789012345 */ /* ------------------------------------ */ /* 00000000-1111-1111-2222-222233333333 */ bool ok; uuid->parts[0] = hexits_value(s, 8, &ok); if (!ok || s[8] != '-') { goto error; } uuid->parts[1] = hexits_value(s + 9, 4, &ok) << 16; if (!ok || s[13] != '-') { goto error; } uuid->parts[1] += hexits_value(s + 14, 4, &ok); if (!ok || s[18] != '-') { goto error; } uuid->parts[2] = hexits_value(s + 19, 4, &ok) << 16; if (!ok || s[23] != '-') { goto error; } uuid->parts[2] += hexits_value(s + 24, 4, &ok); if (!ok) { goto error; } uuid->parts[3] = hexits_value(s + 28, 8, &ok); if (!ok) { goto error; } return true; error: uuid_zero(uuid); return false; }