How to read the RemoteAddress of client in WDK (windows driver) socket (wsk.h)?
I want to read the remote address of the client in a windows driver socket.
I imported Wsk.h, created my socket, accept the connection via WskAccept. I want to debug log the remote address ([out, optional] PSOCKADDR RemoteAddress) in a human-readable ipv4 address.
In winsock2 there is InetNtop and WSAAddressToStringA. What can I use in Wsk.h as an alternative to these?
do you know?
how many words do you know
See also questions close to this topic
-
How do I manipulate the contents of a stat() struct?
I have a stat struct, and I'm looking for a way to get data out of it to be manipulated. The program will successfully run and print the desired st_mtime value, but including either of the "seg-fault" lines below causes a segmentation fault in runtime.
struct stat buf; time_t time_m; time_t sys_time = time(0); if(stat(sub_dirp->d_name,&buf)==0) { //time_m = buf.st_mtime; //seg-fault //double since_last = (difftime(sys_time, buf.st_mtime)/60); //seg-fault printf("%d ", (int)buf.st_mtime); //This works. }
Both lines are attempting to manipulate the
buf.st_mtime
value in some way.I've had a hard time finding any examples of the usage of stat() that do anything other than print its contents, which makes me wonder if it's even possible.
So my question is, if it is possible, what am I missing?
P.S. I do wish to keep
st_mtime
in the Unix timestamp format to make it easier to manipulate.Edit: After realizing that
st_mtime
is itself its own struct (timespec), how can I access thest_mtime.tv_sec
member?The compiler doesn't like
buf.st_mtime.tv_sec
one bit. -
What's purpose of __linecapp in getline, when it'll auto resize?
It's all about second parameter of getline in stdio.h,
I'll name it 'n' or '__linecapp' below.
According to the document:
If the buffer is not large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary.
It'll automatically update line capacity, then why should we input __linecapp?
P.S Someone ask before, but discussion didn't explain when we need it, or how to make it useful.
-
Linked List Deletion function causing program to crash *wrong pointers?*
In my program when a username is following another one and also has posted a "tweet" which is a string in an attempt to delete the followed username it breaks the program. I believe this is the code snippet in question. If anyone could help me identify the issue I would be thankful as I am learning the usage of linked lists for scale able projects. Thanks
void deleteAccount(accountNodePtr *startPtr, accountNodePtr *curAcPtr, tweetsNodePtr *startTwtPtr){ accountNodePtr acLoopPtr; accountNodePtr tempCur = *curAcPtr; followNodePtr followingPtr = tempCur->followingPtr; followNodePtr tempPtr; followNodePtr tempPtr2; tweetsNodePtr iterTwtPtr; iterTwtPtr = *startTwtPtr; *below here in question* tempCur = *curAcPtr; while (tempCur->followersPtr!=NULL){ acLoopPtr = *startPtr; while (strcmp(acLoopPtr->username, tempCur->followersPtr->username)!=0){ acLoopPtr=acLoopPtr->nextPtr; } if (strcmp(acLoopPtr->followingPtr->username, tempCur->username)==0){ tempPtr=acLoopPtr->followingPtr->nextPtr; free(acLoopPtr->followingPtr); acLoopPtr->followingPtr=tempPtr; }else{ tempPtr=acLoopPtr->followingPtr; while(strcmp(tempPtr->nextPtr->username, tempCur->username)!=0){ tempPtr=tempPtr->nextPtr; } tempPtr2=tempPtr->nextPtr->nextPtr; free(tempPtr->nextPtr); tempPtr->nextPtr=tempPtr2; } tempPtr = tempCur->followersPtr->nextPtr; free(tempCur->followersPtr); tempCur->followersPtr=tempPtr; }
This is the structure
typedef struct followsNode { char username[MAX_USERNAME]; struct followsNode *nextPtr; } followNode; typedef struct accountsNode { char username[MAX_USERNAME]; struct followsNode *followersPtr; struct followsNode *followingPtr; struct accountsNode *nextPtr; } accountNode; typedef followNode *followNodePtr; typedef accountNode *accountNodePtr;
-
Socket.IO cannot establish a connection
I use socket.io-client for Javascript server on JAVA and when I enter address 'ws://10.201.223.67:9902/' the request is not by 'ws' but by 'http'.
Although I understand it should just come back 0
It keeps trying to connect.To connect using my own written hook
export function useSocketIO(url: string) { const ioRef = useRef<Socket>(); const [connected, setConnected] = useState(false); useEffect(() => { ioRef.current = io(url, { transportOptions: { polling: { extraHeaders: { Authorization: `Bearer ${APIAuth.accessToken}`, }, }, }, }); ioRef.current.on('connect', () => { console.log('WS Connected to', url); setConnected(() => true); }); ioRef.current.on('disconnect', () => { console.log('WS disconnected'); setConnected(() => false); }); return () => { console.log('WS destroyed'); ioRef.current?.close(); }; }, [url]); return { io: ioRef.current, connected, }; }
-
Steps involved in making a TCP connection
I am 18 and about to go to college for CS, I know nothing about socket programming in C.
I read the man pages on sockets, can you tell me if I got the steps right?
Server Steps:
create a socket with
socket()
create an address with a struct [presumably using some kind of
sockaddr
struct variant]bind the socket to the address with
bind()
listen for a connection with
listen()
accept the connection, and move the connection to another socket using
accept()
to free up the original "listening" socketuse
read()
andwrite()
to communicate over the new socket
Client Steps:
create a socket with
socket()
specify the address of the server we want to connect to [presumably using some
sockaddr
struct variant]connect the socket to the address using
connect()
use
read()
andwrite()
to communicate over the socket
-
Find the coordinates returned by the server after send commands GPS Tracker (TK303 etc)
I sent commands to the server according to the following links and data was returned that I do not know how to find the coordinates.
Link 1: GPS103 Tracker Listening Application in C#
Link 2: sending commands to tk103 gps tracker
Returned data:
imei:XXXXXXXXXXXXXXX,tracker,220506170600,,F,230600.00,A,3541.45559,N,05122.93316,E,,;
I also did not find the exact source for sending the commands to the server. Example I found: How to send commands via GPRS to GPS Tracker (TK103, GT02, GT06, TK102 etc)
-
I want to write a kernel driver program where when a file is created I need to be notified
I used the reference of this project where it creates a handler for IRP_MJ_CREATE. which displays all the files which are created or opened the system. The documentation of IRP_MJ_CREATE is this:
The I/O Manager sends an IRP_MJ_CREATE request when a new file or directory is being created, or when an existing file, device, directory, or volume is being opened.
Normally this IRP is sent on behalf of a user-mode application that has called a Microsoft Win32 function such as CreateFile or on behalf of a kernel-mode component that has called a function such as IoCreateFile, IoCreateFileSpecifyDeviceObjectHint, ZwCreateFile, or ZwOpenFile.
If the create request is completed successfully, the application or kernel-mode component receives a handle to the file object.
This program below prints all the files or volumes which are opened, created.
main.c
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; ++i) { DriverObject->MajorFunction[i] = FsFilterDispatchPassThrough; } //creating handle for IRP_MJ_CREATE. DriverObject->MajorFunction[IRP_MJ_CREATE] = FsFilterDispatchCreate;
// IRP_MJ_CREATE IRP Handler NTSTATUS FsFilterDispatchCreate( __in PDEVICE_OBJECT DeviceObject, __in PIRP Irp ) { PFILE_OBJECT pFileObject = IoGetCurrentIrpStackLocation(Irp)->FileObject; DbgPrint("%wZ\n", &pFileObject->FileName); return FsFilterDispatchPassThrough(DeviceObject, Irp); }
I just need the driver to print only when a file or directory is created.
-
Connected monitor to laptop via HDMI stopped working
After the update, the monitor connected to the laptop via HDMI stopped working. I needed to update the software, I updated according to this guide - https://www.vultr.com/docs/update-ubuntu-server-best-practices/ After the update the next day, when I turned on the laptop, the monitor was detected, but there was a black screen, when the Join Displays option was selected and after pressing the Apply button, the settings were still reset to the Single Display option. (screenshot - http://joxi.net/ZrJKoLFQxq7Vmj)
My System
- OS: Ubuntu 20.04 focal
- Kernel: x86_64 Linux 5.13.0-40-generic
- DE: GNOME 3.36.5
- CPU: AMD Ryzen 7 5800H
- GPU: AMD/ATI
- GPU2: RTX3060
- Laptop Lenovo Legion 5-15ACH6H
A similar problem was when I installed the latest NVIDIA driver in the driver settings after installing the OS. After that, the monitor turned off and didn’t work anymore, the problem was fixed only by reinstalling the OS (I don’t really understand the intricacies of Ubuntu). I just reinstalled the OS and did not touch the drivers, the driver was selected by default after installation and everything worked fine until the system update, which is described above.
Windows is installed on this laptop and now both monitors work correctly as before.
-
Driver Error while installing visual studio code Version 1.66
Actually, I am trying to install the vs code in my system to the latest version of it. But I can't able installing it. It shows errors like "The driver or UNC share you selected doesn't exist or it is not accessible. Please select other" I get this error message while installing the vs code version (Version 1.66).
Anybody helps me out with this. I struggling to install it. But I can't
-
Automating RealTerm with Python
I am currently in the process of creating a script to automate RealTerm. I need to send a binary file and have the Winsock setting set to "Raw". RealTerms documentation indicates that I need an integer 0 or 1 for this setting but I am receiving a "object has no attribute" "Winsock".
RT.Winsock = 0
is what I currently have it set at. This this is the error message I get.'<win32com.gen_py.Realterm Library.IRealtermIntf instance at 0x1826368502752>' object has no attribute 'Winsock'
Could this be a bug in the program?I have also tried
RT.Winsock = ("0")
and that returned the same error but that sets it as a string and not integer.Any thoughts on how it should be set or what I'm doing wrong? Here is my full error below.
Exception has occurred: AttributeError '<win32com.gen_py.Realterm Library.IRealtermIntf instance at 0x2390257155040>' object has no attribute 'Winsock'
During handling of the above exception, another exception occurred:
File "C:\NetworkUpdater\NUP\NUPv1.0.py", line 13, in module RT.Winsock = 0
Edit: Added code below
RT = DispatchEx("Realterm.RealtermIntf") RT.Visible = True RT.Caption = "Realterm Controlled from Python" RT.SelectTabSheet("Port") RT.Winsock = 0
-
How can I receive a message on client by socket?
I'm working on a C++ project that use sockets to transfer the message, I've done the sending part which looks like this(IDK if it's correct, if no please let me know what should I do)
void CFinalProjectKeithDlg::OnBnClickedSend() { CString ChatMessage; SetDlgItemText(IDC_EDIT_CHAT, ChatMessage); //const char* pkt = "Message to be sent"; const char* srcIP = "127.0.0.1"; const char* destIP = "127.0.0.1"; sockaddr_in dest; sockaddr_in local; WSAData data; WSAStartup(MAKEWORD(2, 2), &data); local.sin_family = AF_INET; inet_pton(AF_INET, srcIP, &local.sin_addr.s_addr); local.sin_port = htons(0); dest.sin_family = AF_INET; inet_pton(AF_INET, destIP, &dest.sin_addr.s_addr); dest.sin_port = htons(3514); SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); bind(s, (sockaddr*)&local, sizeof(local)); sendto(s, ChatMessage, strlen(ChatMessage), 0, (sockaddr*)&dest, sizeof(dest)); closesocket(s); WSACleanup(); }
Now I'll need to code a receiving part that receives the message. IDK where to start, this is my first real programming project. I really don't know how to start.
-
Using netcfg to remove an NDIS LWF doesn't remove it from the driver store?
When i try to remove my NDIS LWF using
netcfg -u
, i notice that it doesn't remove it from the driver store (can be seen withpnputil /enum-drivers
).This is causing problem because on some Windows 10 machines, if we uninstall the previous version of our NDIS LWF and install the new one using
netcfg
, for some unknown reason the old inf is still used to install it! And i assume its because the inf still has the same componentID? We are updating the INF file in order to attach to some virtual adapters that we previously couldn't attach. Note that this doesn't happen in Windows 7, and we can install the new one without any problem.So my questions are:
Why is Windows still using the previous INF from driver store when we try to install the new updated driver that has a different INF?
What is the proper way to fully remove the previous NDIS LWF, including from driver store? If we need to use
pnputil
to fully remove it from driver store, then what is the proper way of finding the OEM number, considering thatpnputil -d
requires an OEM number?
-
Windows driver kit for VS2019 and Windows 10 Enterprise 21H2
What version of WDK do I need for VS2019 community and Windows 10 Enterprise 21H2? I have tried many versions of WDK but for some reason the driver package templates do not show up in VS2019. I uninstalled VS2019 and starting fresh with the idea that multiple versions of WDK can be a problem.