This function receives a token or message.
/* * Function: recv_token * * Purpose: Reads a token from a file descriptor. * * Arguments: * * s (r) an open file descriptor * tok (w) the read token * * Returns: 0 on success, -1 on failure * * Effects: * * recv_token reads the token length (as a network long), allocates * memory to hold the data, and then reads the token data from the * file descriptor s. It blocks to read the length and data, if * necessary. On a successful return, the token should be freed with * gss_release_buffer. It returns 0 on success, and -1 if an error * occurs or if it could not read all the data. */ int recv_token(s, tok) int s; gss_buffer_t tok; { int ret, len; ret = read_all(s, (char *) &len, sizeof(int)); if (ret < 0) { perror("reading token length"); return -1; } else if (ret != 4) { if (display_file) fprintf(display_file, "reading token length: %d of %d bytes read\n", ret, 4); return -1; } tok->length = ntohl(len); tok->value = (char *) malloc(tok->length); if (tok->value == NULL) { if (display_file) fprintf(display_file, "Out of memory allocating token data\n"); return -1; } ret = read_all(s, (char *) tok->value, (OM_uint32)tok->length); if (ret < 0) { perror("reading token data"); free(tok->value); return -1; } else if (ret != tok->length) { fprintf(stderr, "sending token data: %d of %d bytes written\n", ret, tok->length); free(tok->value); return -1; } return 0; }