Created
October 14, 2024 16:17
-
-
Save Hakkadaikon/708c554185caae49a86b4c44a701353e to your computer and use it in GitHub Desktop.
SSTP Sample in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ukagaka SSTP send sample | |
#define _WIN32_WINNT 0x0601 // Windows 7 later | |
#include <winsock2.h> | |
#include <ws2tcpip.h> | |
#include <wincrypt.h> | |
#include <stdio.h> | |
#pragma comment(lib, "ws2_32.lib") | |
int main(void) | |
{ | |
WSADATA wsaData; | |
WSAStartup(MAKEWORD(2, 2), &wsaData); | |
struct addrinfo hints; | |
struct addrinfo* result; | |
memset(&hints, 0x00, sizeof(hints)); | |
hints.ai_family = AF_INET; | |
hints.ai_socktype = SOCK_STREAM; | |
getaddrinfo( | |
"127.0.0.1", // IP Address | |
"9801", // Port number | |
&hints, | |
&result); | |
auto sock = socket( | |
result->ai_family, | |
result->ai_socktype, | |
result->ai_protocol | |
); | |
connect(sock, result->ai_addr, (int)result->ai_addrlen); | |
char requestBuffer[256]; | |
int requestBufferSize = sizeof(requestBuffer) / sizeof(requestBuffer[0]); | |
sprintf_s( | |
requestBuffer, | |
requestBufferSize, | |
"NOTIFY SSTP/1.5\r\n" \ | |
"Sender: Test\r\n" \ | |
"Event: OnRelease\r\n" \ | |
"Script: Test message by hakkadaikon.\r\n" \ | |
"Option: nodescript, notranslate\r\n" \ | |
"Charset: UTF-8\r\n" | |
"\r\n" | |
); | |
puts("------ SSTP request ---------"); | |
printf("%s", requestBuffer); | |
puts("-----------------------------"); | |
send(sock, requestBuffer, requestBufferSize, 0); | |
char buffer[4096]; | |
memset(buffer, 0x00, sizeof(buffer)); | |
// Receive SSTP response | |
int len = recv(sock, buffer, sizeof(buffer), 0); | |
if (len <= 0) { | |
fprintf(stderr, "SSTP send failed \n"); | |
closesocket(sock); | |
freeaddrinfo(result); | |
} | |
puts("------ SSTP response --------"); | |
printf("%s", buffer); | |
puts("-----------------------------"); | |
// Clean up | |
closesocket(sock); | |
freeaddrinfo(result); | |
WSACleanup(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment