{"id":18006942,"url":"https://github.com/wbenny/ksocket","last_synced_at":"2025-04-05T12:04:02.456Z","repository":{"id":41403591,"uuid":"169938293","full_name":"wbenny/KSOCKET","owner":"wbenny","description":"KSOCKET provides a very basic example how to make a network connections in the Windows Driver by using WSK","archived":false,"fork":false,"pushed_at":"2022-09-02T09:14:19.000Z","size":28,"stargazers_count":495,"open_issues_count":7,"forks_count":130,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-29T11:06:30.601Z","etag":null,"topics":["driver","kernel","socket","windows","wsk"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wbenny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-10T03:12:39.000Z","updated_at":"2025-03-28T11:15:39.000Z","dependencies_parsed_at":"2022-07-16T15:00:46.421Z","dependency_job_id":null,"html_url":"https://github.com/wbenny/KSOCKET","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbenny%2FKSOCKET","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbenny%2FKSOCKET/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbenny%2FKSOCKET/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wbenny%2FKSOCKET/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wbenny","download_url":"https://codeload.github.com/wbenny/KSOCKET/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332560,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["driver","kernel","socket","windows","wsk"],"created_at":"2024-10-30T01:11:21.821Z","updated_at":"2025-04-05T12:04:02.406Z","avatar_url":"https://github.com/wbenny.png","language":"C","readme":"# KSOCKET\n\n**KSOCKET** provides a very basic example on how to make a network connections\nin the Windows Driver by using WSK.\n\n### Why?\n\nIn my opinion there aren't too much examples on WSK on the Internet.  This is\nquite understandable, as generally dealing with networking in the kernel-mode\nisn't a very good idea.  However, sometimes, you're just too interested _**how it can be done**_.\n\n### What does it do?\n\nIt makes a HTTP GET request to the `httpbin.org/uuid` and prints the response\nto the debugger.  Then, it creates a TCP server listening on port 9095 and waits\nfor a client.  When the client connects, it waits for a single message, prints\nit to the debugger and then responds with `Hello from WSK!` and closes both\nclient and server sockets.\n\nThe output in the debugger might look like this:\n\n![windbg](img/windbg.png)\n\n### Implementation\n\nBecause everyone is familiar with the **Berkeley socket API**, I've ported\na very small subset of it - enough to make a basic TCP/UDP client/server:\n\n```c\nint getaddrinfo(const char* node, const char* service, const struct addrinfo* hints, struct addrinfo** res);\nvoid freeaddrinfo(struct addrinfo *res);\n\nint socket_connection(int domain, int type, int protocol);\nint socket_listen(int domain, int type, int protocol);\nint socket_datagram(int domain, int type, int protocol);\nint connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen);\nint listen(int sockfd, int backlog);\nint bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);\nint accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);\nint send(int sockfd, const void* buf, size_t len, int flags);\nint sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);\nint recv(int sockfd, void* buf, size_t len, int flags);\nint recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);\nint closesocket(int sockfd);\n```\n\nYou can probably see the biggest difference between this API and the original Berkeley\nsocket API - instead of a single `socket()` function, there are `socket_connection()`,\n`socket_listen()` and `socket_datagram()` functions.  This is because in WSK, you\nhave to specify type of the socket **when** the socket object is created.  Although\nit would probably be possible with some workarounds to make just single `socket()` function,\nfor simplicity of the implementation I've decided to split it too.\n\n\u003e **NOTE:** This project is purely experimental and its goal is to show basic\n\u003e usage of the WSK. There aren't many error checks and it is not recommended\n\u003e for production use.\n\n### License\n\nThis software is open-source under the MIT license. See the LICENSE.txt file in this repository.\n\nDependencies are licensed by their own licenses.\n\nIf you find this project interesting, you can buy me a coffee\n\n```\n  BTC 3GwZMNGvLCZMi7mjL8K6iyj6qGbhkVMNMF\n  LTC MQn5YC7bZd4KSsaj8snSg4TetmdKDkeCYk\n```\n\n[wsk-msdn]: \u003chttps://docs.microsoft.com/en-us/windows-hardware/drivers/network/introduction-to-winsock-kernel\u003e\n[wsk-http]: \u003chttps://github.com/reinhardvz/afdmjhk/blob/master/WSK/Samples/wsksample/wsksample.c\u003e\n[wsk-echosrv]: \u003chttps://github.com/Microsoft/Windows-driver-samples/tree/master/network/wsk/echosrv\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwbenny%2Fksocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwbenny%2Fksocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwbenny%2Fksocket/lists"}