+int do_hbytes_compare(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value a, HBytes_Value b, int *result) {
+ int al, bl, minl, r;
+
+ al= hbytes_len(&a);
+ bl= hbytes_len(&b);
+ minl= al<bl ? al : bl;
+
+ r= memcmp(hbytes_data(&a), hbytes_data(&b), minl);
+
+ if (r<0) *result= -2;
+ else if (r>0) *result= +2;
+ else {
+ if (al<bl) *result= -1;
+ else if (al>bl) *result= +1;
+ else *result= 0;
+ }
+ return TCL_OK;
+}
+
+int do_hbytes_range(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value v, int start, int size,
+ HBytes_Value *result) {
+ const Byte *data;
+ int l;
+
+ l= hbytes_len(&v);
+ if (start<0 || size<0)
+ return staticerr(ip,"hbytes range subscript(s) -ve","HBYTES LENGTH RANGE");
+ if (l<start+size)
+ return staticerr(ip, "hbytes range subscripts too big",
+ "HBYTES LENGTH UNDERRUN");
+
+ data= hbytes_data(&v);
+ hbytes_array(result, data+start, size);
+ return TCL_OK;
+}
+
+/* hbytes representing uint16_t's */
+
+int do_hbytes_h2ushort(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value hex, long *result) {
+ const Byte *data;
+ int l;
+
+ l= hbytes_len(&hex);
+ if (l>2)
+ return staticerr(ip, "hbytes h2ushort input more than 4 hex digits",
+ "HBYTES VALUE OVERFLOW");
+
+ data= hbytes_data(&hex);
+ *result= data[l-1] | (l>1 ? data[0]<<8 : 0);
+ return TCL_OK;
+}
+
+int do_hbytes_ushort2h(ClientData cd, Tcl_Interp *ip,
+ long input, HBytes_Value *result) {
+ uint16_t us;
+
+ if (input > 0x0ffff)
+ return staticerr(ip, "hbytes ushort2h input >2^16",
+ "HBYTES VALUE OVERFLOW");
+
+ us= htons(input);
+ hbytes_array(result,(const Byte*)&us,2);
+ return TCL_OK;
+}
+
+/* toplevel functions */
+
+int do_toplevel_hbytes(ClientData cd, Tcl_Interp *ip,
+ const HBytes_SubCommand *subcmd,
+ int objc, Tcl_Obj *const *objv) {
+ return subcmd->func(0,ip,objc,objv);
+}
+
+int do_toplevel_dgram_socket(ClientData cd, Tcl_Interp *ip,
+ const DgramSocket_SubCommand *subcmd,
+ int objc, Tcl_Obj *const *objv) {
+ return subcmd->func(0,ip,objc,objv);
+}
+
+int do_toplevel_ulong(ClientData cd, Tcl_Interp *ip,
+ const ULong_SubCommand *subcmd,
+ int objc, Tcl_Obj *const *objv) {