I'm trying to connect to MSMQ and send some messages. Unfortunately, there is "previous art" in the project on how this is done and I'm supposed to mimick it. The way this previous app is connecting is the following:
if (MSMQ in workgroup mode)
{
connect via FormatName;
}
else
{
if (connected to network)
connect via PathName;
else
connect via GUID (as FormatName)
}
Is all this really necessary? Shouldn't a proper FormatName be enough to connect to a queue?
Additionally, the "connected to network" is detected by calling NetGetDCName() which is marked as obsolete in my MSDN, adding to my confusion on why is the app connecting this way.
TL;DR: Is the above logic for connecting: wrong, obsolete or correct? Can I simplify this by simply using FormatName to connect in all cases?
That code is determining whether the domain is available by looking for the domain controller. If the domain is not available then MSMQ is assumed to be working in non-domain - or workgroup - mode.
Domain mode allows the use of public queues and pathname addressing.
Workgroup mode instead uses private queues and formatname addressing (although this is a simplification).
So the code is really determining the mode of message addressing to be used.
There is not enough information about the environment to say if you can just use formatname for all cases.
Cheers
John Breakwell
Related
Actually I'm using D-Feet (D-Feet can be used to inspect D-Bus interfaces of running programs and invoke methods on those interfaces) to connect to a BLE peripheral that advertises proximity profile.
When I try the Connect() method on the remote object /org/bluez/hci0/dev_88_6B_0F_00_C4_3A every thing is fine and the connection succeed but when I try to connect only the proximity profile using ConnectProfile("0x1802") method an error occurs saying that the host is down:
g-io-error-quark: GDBus.Error:org.bluez.Error.Failed: Host is down
(36)
Can anyone help me solving this problem (I'm blocked for 2 weeks and there still to much to deal with in the project :/)
ConnectProfile("0x1802")
ConnectProfile (and the Bluez API in general) does not deal with handles, only UUIDs. Your input argument does not look like a UUID: I suggest you find the remote service UUID that matches the handle (I'm assuming your current input argument is a handle).
I believe you can find the UUID with d-feet (after Connect() the service objects should be there) or with bluez command line tools.
I'm experimenting with Cesanta's Mongoose server/"client" networking library in C. This is in Windows 7 x64 using Pelle's C. I'm trying to make a LAN-capable text messaging app on port 90 as two dialog-as-main executables (server and client) to support 20 connections to the server. FWIW, I'm using a fast timer to call mg_mgr_poll(&mgr, 0) which retains UI responsiveness and uses very little CPU.
Cesanta gives good examples of server communication setup and that works flawlessly. I can also get a client to connect to the server, but the server's IP address must be used in mg_connect().
Since the server's hostname is public to the LAN, I was hoping to ask the LAN for this host's IP. I had this working in VB awhile ago:
Dim host As New IPHostEntry
host = Dns.GetHostEntry(hostName)
Return host.AddressList.GetValue(0)
However as the VB project got bigger, VB got stranger and much more difficult, so I migrated to good old C. (Perhaps it was falling back to a NetBIOS name query, dunno.) No, I'd rather not migrate again to C# or C++/VS.
The Cesanta documentation on DNS resolution is quite vague. Code like mg_connect(&mgr, "MyServerPC:90", ev_handler); simply crashes, despite mg_connect stating it will try and resolve hostnames.
Can Mongoose resolve a local (LAN) hostname, and how? Or is this futile, and should everything be done manually in Winsock?
i have the same issue as you.
First i think that the mg_connect should not crashes, only if you try to do something with the returned connection which is null.
Second, mongoose try to resolve the address using DNS from specific location at the registry and it's take the first address he can find.
The location is :SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces
,check here in each of the interfaces.
i think there is a bug here (i am going to open an issues for it and also try to fix it and created a pull request).
Little update:
i have opend an issue and create a pull request about this issue.
https://github.com/cesanta/mongoose/issues/832
https://github.com/cesanta/mongoose/pull/833
Mongoose check each interface for the Value of NameServer and DhcpNameServer ,and return the first one (which is not empty) it can find but if it found an empty value for NameServer it doesn't check DhcpNameServer(and therefore miss the correct address) which will cause an error and direct the name resolving to a default server(i think it's google DNS -8.8.8.8).
You can fix this by going to the registry and adding the value of your DNS address to the registry key-NameServer
this is a comment from mongoose code:
/*
* See https://github.com/cesanta/mongoose/issues/176
* The value taken from the registry can be empty, a single
* IP address, or multiple IP addresses separated by comma.
* If it's empty, check the next interface.
* If it's multiple IP addresses, take the first one.
*/
I have read loads of Microsoft documentation regarding RPC programming and still do not figure out how do we get from RPC server the IP address of the connecting client.
I am sure there is a simple way to get client IP address from server when connecting, but do not know how to do this :/
Thanks for helping, a simple pointer to a documentation would be great.
No - there is no documented way to accomplish this. Windows RPC by design abstracts the network transport (and associated metadata like network addresses) from it's clients.
If you really need something like this, you could bake it into your interface (e.g. implement a Connect() method where your client provides it's IP address that you could stash in a Context Handle). This assumes of course, that you can trust your clients to provide valid IP addresses...
It should be possible using RpcBindingServerFromClient. Quoting documentation for RpcBindingServerFromClient:
To query a client's address, an application starts by calling the RpcBindingServerFromClient function to obtain a partially bound server binding handle. The server binding handle can be used to obtain a string binding by invoking RpcBindingToStringBinding. The server can then call RpcStringBindingParse to extract the client's network address from the string binding.
UPDATE 16/05/2017: There is also undocumented function I_RpcServerInqRemoteConnAddress() that most likely return client IP address. But I didn't try it yet.
I'm writing a port scanner in C and i want to detect what service is running on an open port and its version.I've already wrote the scanner code but now i have no idea about how to detect running service.
What can i do?
If you are determined to do it in your own code, you can connect to the port, see if you get any data on it, if nothing then send a few bytes, and check again.
Then match that against expected response.
to get an idea what you are looking for, you can connect manually to the port with telnet and poke at it. In many cases (a web server is an easy example) you must send some correctly formatted data in order to get a usable response.
nmap has done all this and much more (e.g. extensive checks such as looking for byte order and timing of arp traffic)
UPDATE: several people have mentioned well known ports, but that won't help you discover standard services running on nonstandard ports, such as ssh or http servers running on custom ports.
If server sends something first, use that to identify protocol.
If not, send something according to some protocol, such as http, and see what server sends back (valid response or error). You may need to make several attempts with different protocols, and a good order is important to minimize connection count.
Some protocols may be very hard to identify, and it is easy to make custom server with unique protocol you don't know about, or even hide real server under simple fake server of other proto such as http.
If you just want to know what the port usually is, check "well known ports" and official reserved ports.
Also check nmap source code.
I need to detect the presence/absence of internet connection. More precisely, let us suppose that the application is broken up into 2 parts - A and B.
A is responsible for checking whether or not the system is connected to the internet. If it finds that there is no connection, it starts up part B. And as soon as it detects that there is a network connection, it kills B and continues its own work.
What would be the best way to do the A part of the application? Continual pings sounds hideous. There has to be a better way of doing this (preferably in C).
With sufficient privilege you can test the various network interfaces and examine their state. This would tell you if any of the interfaces was connected to a network and operating. However, this won't tell you if the connection is actually usable, i.e., connected to the internet (or your local net if that's all you need). I don't know of anyway to do that short of actually using it.
Using ICMP (ping) can be useful at a low level, but presumably what you need is a connection to an actual endpoint via TCP/IP to do real work. I would say that you should change the design of your application so that B is responsible for indicating when it is unable to continue due to the absence of resources that it relies on -- network or otherwise. A and B should communicate so that A is aware of the situation and is able to either kill B or respond to B terminating itself and thus continuing its work.
A lot of companies have measures in place to prevent outgoing ICMP requests, TCP connections to ports other than 80/443 for example, or even to prevent you from reaching the internet directly by (transparently) proxying your traffic.
Under an internet connection I would understand any way to contact the outside, be it UDP, TCP or ICMP. Depending on what your application needs to contact the internet for, I would suggest to check over the same protocol, as that is the only thing that matters to your app.
If your application uses HTTP to communicate to an external source, try to connect to a few sites you would suspect to not be blacklisted and that have a reliable uptime. Like google.com, microsoft.com, apple.com, and so on...
Edit:
I am unsure what the specifics are, so let me give you an example with a hypothetical situation.
Application A collects data on the system it is running on and forwards it to a Web Service listening on yourserverhost.yourcompany.com:80
Application B would basically take over the job of the Web Service when it is down and log everything so no data is lost.
When all is well, App A will be sending the data to your web service
Once this connection drops, you immediatly launch App B (the obvious remark here would be, why not keep App B running as a failsafe)
App A connects to App B and forwards what it had been buffering
App A continues to try to reestablish the connection to your Web Service and once it is back up will request App B to stop
If the problem you are facing is nothing like this, please provide a more concrete description of what App A and App B are supposed to be doing. I will be more than happy to help.
In your code, you have to check whether the internet connection exists by using a socket to open a connection to a website.
Firstrun: Ask user to input the network parameters, like proxy settings. Save this info.
Next runs: Use these settings to check for the Internet connection. You may simply do a DNS search.
If results are negative, ask user to check settings.
Check whether the cable is connected , if so ping your internet connection to any host as google.com.
ping google.com