BOOL license_send(rdpLicense* license, wStream* s, BYTE type) { int length; BYTE flags; UINT16 wMsgSize; rdpRdp* rdp = license->rdp; DEBUG_LICENSE("Sending %s Packet", LICENSE_MESSAGE_STRINGS[type & 0x1F]); length = Stream_GetPosition(s); wMsgSize = length - license->PacketHeaderLength; Stream_SetPosition(s, license->PacketHeaderLength); flags = PREAMBLE_VERSION_3_0; /** * Using EXTENDED_ERROR_MSG_SUPPORTED here would cause mstsc to crash when * running in server mode! This flag seems to be incorrectly documented. */ if (!rdp->settings->ServerMode) flags |= EXTENDED_ERROR_MSG_SUPPORTED; license_write_preamble(s, type, flags, wMsgSize); #ifdef WITH_DEBUG_LICENSE WLog_DBG(TAG, "Sending %s Packet, length %d", LICENSE_MESSAGE_STRINGS[type & 0x1F], wMsgSize); winpr_HexDump(TAG, WLOG_DEBUG, Stream_Pointer(s) - LICENSE_PREAMBLE_LENGTH, wMsgSize); #endif Stream_SetPosition(s, length); rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID); rdp->sec_flags = 0; return TRUE; }
boolean freerdp_channel_send(rdpRdp* rdp, uint16 channel_id, uint8* data, int size) { STREAM* s; uint32 flags; int i, left; int chunk_size; rdpChannel* channel = NULL; for (i = 0; i < rdp->settings->num_channels; i++) { if (rdp->settings->channels[i].channel_id == channel_id) { channel = &rdp->settings->channels[i]; break; } } if (channel == NULL) { printf("freerdp_channel_send: unknown channel_id %d\n", channel_id); return false; } flags = CHANNEL_FLAG_FIRST; left = size; while (left > 0) { s = rdp_send_stream_init(rdp); if (left > (int) rdp->settings->vc_chunk_size) { chunk_size = rdp->settings->vc_chunk_size; } else { chunk_size = left; flags |= CHANNEL_FLAG_LAST; } if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL)) { flags |= CHANNEL_FLAG_SHOW_PROTOCOL; } stream_write_uint32(s, size); stream_write_uint32(s, flags); stream_check_size(s, chunk_size); stream_write(s, data, chunk_size); rdp_send(rdp, s, channel_id); data += chunk_size; left -= chunk_size; flags = 0; } return true; }
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size) { STREAM* s; UINT32 flags; int i, left; int chunk_size; rdpChannel* channel = NULL; for (i = 0; i < rdp->settings->ChannelCount; i++) { if (rdp->settings->ChannelDefArray[i].ChannelId == channel_id) { channel = &rdp->settings->ChannelDefArray[i]; break; } } if (channel == NULL) { printf("freerdp_channel_send: unknown channel_id %d\n", channel_id); return FALSE; } flags = CHANNEL_FLAG_FIRST; left = size; while (left > 0) { s = rdp_send_stream_init(rdp); if (left > (int) rdp->settings->VirtualChannelChunkSize) { chunk_size = rdp->settings->VirtualChannelChunkSize; } else { chunk_size = left; flags |= CHANNEL_FLAG_LAST; } if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL)) { flags |= CHANNEL_FLAG_SHOW_PROTOCOL; } stream_write_UINT32(s, size); stream_write_UINT32(s, flags); stream_check_size(s, chunk_size); stream_write(s, data, chunk_size); rdp_send(rdp, s, channel_id); data += chunk_size; left -= chunk_size; flags = 0; } return TRUE; }
boolean vchan_send(rdpVchan* vchan, uint16 channel_id, uint8* data, int size) { STREAM* s; uint32 flags; rdpChan* channel = NULL; int i; int chunk_size; int left; for (i = 0; i < vchan->instance->settings->num_channels; i++) { if (vchan->instance->settings->channels[i].chan_id == channel_id) { channel = &vchan->instance->settings->channels[i]; break; } } if (channel == NULL) { printf("vchan_send: unknown channel_id %d\n", channel_id); return False; } flags = CHANNEL_FLAG_FIRST; left = size; while (left > 0) { s = rdp_send_stream_init(vchan->instance->rdp); if (left > (int) vchan->instance->settings->vc_chunk_size) { chunk_size = vchan->instance->settings->vc_chunk_size; } else { chunk_size = left; flags |= CHANNEL_FLAG_LAST; } if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL)) { flags |= CHANNEL_FLAG_SHOW_PROTOCOL; } stream_write_uint32(s, size); stream_write_uint32(s, flags); stream_check_size(s, chunk_size); stream_write(s, data, chunk_size); rdp_send(vchan->instance->rdp, s, channel_id); data += chunk_size; left -= chunk_size; flags = 0; } return True; }
static int freerdp_peer_virtual_channel_write(freerdp_peer* client, HANDLE hChannel, BYTE* buffer, UINT32 length) { wStream* s; UINT32 flags; UINT32 chunkSize; UINT32 maxChunkSize; UINT32 totalLength; rdpPeerChannel* peerChannel; rdpMcsChannel* mcsChannel; rdpRdp* rdp = client->context->rdp; if (!hChannel) return -1; peerChannel = (rdpPeerChannel*) hChannel; mcsChannel = peerChannel->mcsChannel; if (peerChannel->channelFlags & WTS_CHANNEL_OPTION_DYNAMIC) return -1; /* not yet supported */ maxChunkSize = rdp->settings->VirtualChannelChunkSize; totalLength = length; flags = CHANNEL_FLAG_FIRST; while (length > 0) { s = rdp_send_stream_init(rdp); if (length > maxChunkSize) { chunkSize = rdp->settings->VirtualChannelChunkSize; } else { chunkSize = length; flags |= CHANNEL_FLAG_LAST; } if (mcsChannel->options & CHANNEL_OPTION_SHOW_PROTOCOL) flags |= CHANNEL_FLAG_SHOW_PROTOCOL; Stream_Write_UINT32(s, totalLength); Stream_Write_UINT32(s, flags); Stream_EnsureRemainingCapacity(s, chunkSize); Stream_Write(s, buffer, chunkSize); rdp_send(rdp, s, peerChannel->channelId); buffer += chunkSize; length -= chunkSize; flags = 0; } return 1; }
boolean rdp_send_client_info(rdpRdp* rdp) { STREAM* s; //rdp->settings->crypt_flags |= SEC_INFO_PKT; rdp->sec_flags |= SEC_INFO_PKT; s = rdp_send_stream_init(rdp); rdp_write_info_packet(s, rdp->settings); return rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID); }
void rdp_send_client_info(rdpRdp* rdp) { STREAM* s; s = rdp_send_stream_init(rdp); rdp_write_security_header(s, SEC_INFO_PKT); rdp_write_info_packet(s, rdp->settings); rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID); }
int main(int argc, char** argv) { int sockfd; struct sockaddr_in sendaddr; struct sockaddr_in recvaddr; int optval = 1; if( argc != 6) { printf("Incorrect number of parameters!\nUsage: ./rwsc client_ip client_port server_ip server_port URL\n"); return -1; } if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { perror("socket"); return -1; } setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); sendaddr.sin_family = AF_INET; sendaddr.sin_port = htons(atoi(argv[2])); sendaddr.sin_addr.s_addr = inet_addr(argv[1]); if(bind(sockfd, (struct sockaddr*)&sendaddr, sizeof(sendaddr)) == -1) { perror("bind"); return -1; } recvaddr.sin_family = AF_INET; recvaddr.sin_port = htons(atoi(argv[4])); recvaddr.sin_addr.s_addr = inet_addr(argv[3]); //struct to hold the receiver's address //delete later rdp_connect(sockfd, argv[3], argv[4]); char* storage = malloc(sizeof(char)*990); char* request = "GET / HTTP/1.0\r\n\r\n"; rdp_send(sockfd, request, strlen(request), &recvaddr); rdp_recv(sockfd, storage, strlen(storage), &recvaddr); printf("%s\n", storage); rdp_recv(sockfd, storage, strlen(storage), &recvaddr); printf("%s\n", storage); rdp_recv(sockfd, storage, strlen(storage), &recvaddr); printf("%s\n", storage); rdp_recv(sockfd, storage, strlen(storage), &recvaddr); printf("%s\n", storage); close(sockfd); return 0; }
BOOL rdp_send_client_info(rdpRdp* rdp) { wStream* s; BOOL status; rdp->sec_flags |= SEC_INFO_PKT; s = Stream_New(NULL, 2048); rdp_init_stream(rdp, s); rdp_write_info_packet(s, rdp->settings); status = rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID); Stream_Free(s, TRUE); return status; }
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size) { DWORD i; int left; wStream* s; UINT32 flags; int chunkSize; rdpMcs* mcs = rdp->mcs; rdpMcsChannel* channel = NULL; for (i = 0; i < mcs->channelCount; i++) { if (mcs->channels[i].ChannelId == channelId) { channel = &mcs->channels[i]; break; } } if (!channel) { DEBUG_WARN( "freerdp_channel_send: unknown channelId %d\n", channelId); return FALSE; } flags = CHANNEL_FLAG_FIRST; left = size; while (left > 0) { s = rdp_send_stream_init(rdp); if (left > (int) rdp->settings->VirtualChannelChunkSize) { chunkSize = rdp->settings->VirtualChannelChunkSize; } else { chunkSize = left; flags |= CHANNEL_FLAG_LAST; } if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL)) { flags |= CHANNEL_FLAG_SHOW_PROTOCOL; } Stream_Write_UINT32(s, size); Stream_Write_UINT32(s, flags); Stream_EnsureCapacity(s, chunkSize); Stream_Write(s, data, chunkSize); rdp_send(rdp, s, channelId); data += chunkSize; left -= chunkSize; flags = 0; } return TRUE; }
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size) { DWORD i; int left; wStream* s; UINT32 flags; int chunkSize; rdpMcs* mcs = rdp->mcs; rdpMcsChannel* channel = NULL; for (i = 0; i < mcs->channelCount; i++) { if (mcs->channels[i].ChannelId == channelId) { channel = &mcs->channels[i]; break; } } if (!channel) { WLog_ERR(TAG, "freerdp_channel_send: unknown channelId %"PRIu16"", channelId); return FALSE; } flags = CHANNEL_FLAG_FIRST; left = size; while (left > 0) { s = rdp_send_stream_init(rdp); if (!s) return FALSE; if (left > (int) rdp->settings->VirtualChannelChunkSize) { chunkSize = rdp->settings->VirtualChannelChunkSize; } else { chunkSize = left; flags |= CHANNEL_FLAG_LAST; } if ((channel->options & CHANNEL_OPTION_SHOW_PROTOCOL)) { flags |= CHANNEL_FLAG_SHOW_PROTOCOL; } Stream_Write_UINT32(s, size); Stream_Write_UINT32(s, flags); if (!Stream_EnsureCapacity(s, chunkSize)) { Stream_Release(s); return FALSE; } Stream_Write(s, data, chunkSize); /* WLog_DBG(TAG, "%s: sending data (flags=0x%x size=%d)", __FUNCTION__, flags, size); */ if (!rdp_send(rdp, s, channelId)) { Stream_Release(s); return FALSE; } data += chunkSize; left -= chunkSize; flags = 0; } return TRUE; }