+ XDR xdr;
+ xdrproc_t xdrp_args;
+ xdrproc_t xdrp_ret;
+ struct wrap_int_message_header hdr;
+ struct wrap_int_message_error err;
+ size_t i;
+
+ for (;;) {
+ /* Receive the request header. */
+ xdrstdio_create (&xdr, stdin, XDR_DECODE);
+ memset (&hdr, 0, sizeof hdr);
+ if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
+ fprintf (stderr, "error receiving request header\n");
+ return;
+ }
+
+ if (hdr.magic != WRAP_INT_PROTO_MAGIC) {
+ fprintf (stderr, "error in request: unexpected magic (%x)\n",
+ hdr.magic);
+ return;
+ }
+ if (hdr.protocol != WRAP_INT_PROTOCOL) {
+ fprintf (stderr, "error in request: unexpected protocol number (%d)\n",
+ hdr.protocol);
+ return;
+ }
+ if (hdr.type != WRAP_INT_PROTO_TYPE_REQUEST) {
+ fprintf (stderr, "error in request: unexpected type (%d)\n",
+ hdr.type);
+ return;
+ }
+
+ /* Convert the proc name to the internal entry point. */
+ /* XXX We're going to use gperf here, as we do in libguestfs. */
+ for (i = 0; i < wrap_int_nr_procs; ++i) {
+ if (STREQ (wrap_int_proc_table[i].name, hdr.proc))
+ goto found;
+ }
+ fprintf (stderr, "unknown proc name in request: %s\n", hdr.proc);
+ exit (EXIT_FAILURE);
+
+ found:
+ xdrp_args = wrap_int_proc_table[i].xdr_args;
+ assert (xdrp_args);
+ xdrp_ret = wrap_int_proc_table[i].xdr_ret;
+ assert (xdrp_ret);