How can i check internet connection in c++ or c, i'm using mac & cant find a good way. If
possible i want to check internet connection constantly' so i can save the users data.
Please provide me with examples, information and ideas.
THanks!
Call system("ping www.google.com").
If the process dies or becomes slow, then your internet connection is doing badly.
You can try implementing a lightweight ICMP to ping a remote host periodically.
Maybe this question can shed some light: Mac network ping source code compile error
Related
I'm developing an application that shows available wifi network and allow to connect/disconnection on windows compact 7(x86).
I need to use the Connection Manager APIs because it includes Connection Manager in the OS design.
I can add a connection config with CmAddConnectionConfig and connect with CmAcquireConnection successfully. But I did not find a function which can disconnect the target connection. I've tried the function CmReleaseConnection, but it always returns CMRE_INVALID_CONNECTION.
There is limited information about Connection Manager in Internet and I found somebody met the same problem.
I'm working on it for about three days. It would be appreciated if you can help me to solve it or give me some suggestions.
As CmReleaseConnection cannot work as expected, I will use CmDeleteConnectionConfig for deleting and then create another network profile without doing the connection. I found this solution from MSDN.
I'm a bit confused about the working principles of FireSheep. The official website describes session hijacking as almost a piece of cake. My question is, how does the cookie information routed towards the attacker's system without using some middle man technique? If I'm the attacker, the website won't send legitimate user's cookie directly to me, even if my (attacker's) NIC is configured in promiscuous mode, right? What am I missing here? Sorry, I don't have much experience in network security. Please tolerate if the question seems silly! I've already tried a lot of Google search, but couldn't find satisfactory answers! Thanks in advance!
Trying to answer from memory...
Firesheep uses libpcap and listens to packets in promiscuous mode. So it will be able to see any data on open wifi networks (read: unencrypted).
Remember that the "wifi cable" is the "air", and everybody with the right antenna can listen to that medium.
Since FireSheep attacks unencrypted HTTP traffic (without https), it is able to extract information, such as cookies, from that. It is just a matter of parsing the valuable information out of the raw frames it sniffs from the air.
It would be possible for FireSheep to decrypt and process data from pre-shared secret connections (WEP/WPA/WPA2), same as WireShark supports, although I don't think that this is implemented.
I'd like to figure out what IP address a DCOM client is connecting from. I have an OPC server, and from the context of the COM/DCOM code, there is no way to get the client IP that I can find. This article appears to confirm that (http://blogs.msdn.com/b/sanpil/archive/2004/03/01/82302.aspx).
I tried using a C++ library that netstat uses (iphlpapi.lib, GetExtendedTcpTable) to get open connections with no luck. It looks like COM/DCOM defaults to UDP.
The only other thing I can think of is using WireShark pcap to try and capture inbound traffic on port 135?
Does anyone have any clever ideas?
It's said "Using DCOM through firewalls becomes problematic because it dynamically allocates one port per process (configurable through the registry) and requires UPD and TCP ports 135-139 to be open. ".
I've got a problem in socket programming. I'm currently writing a simple server/client application which asks connecting clients to answer a survey (I'm following the exercises in the book: TCP/IP Sockets in C: Practical guide for Programmers). It works fine in my local network (using localhost to connect), but I can't make it work over the internet.
Since I changed some of the code found in the book, I tried to compile the original source code from the book but it still doesn't work. I assume this is not a code problem but a network problem.
I did some research and so I turned off my firewall, I forwarded the port I'm using (12543) in my router but it still doesn't work... I've got a remote windows server running Windows 7 for testing: when I run my server on it and try to connect from my computer it fails, when I try to run my server from my computer and try to connect from the remote windows server: it fails again. Even when I run my server on my computer and try to connect with the client from the same computer using my private IPv4 address 192.168.x.x or my public one, it fails ! Oh, and there is no firewall running on the windows server.
I really don't know what to do now... I can ping my windows server from my computer, I can ping my computer from my windows server, but it's impossible to connect to my application.
The source code can be found here: http://cs.ecs.baylor.edu/~donahoo/practical/CSockets2/textcode.html (SurveyServer2.cpp, SurveyClient2.cpp, SurveyCommon.h), but I don't think it's a code problem.
Please tell me if it's not clear enough. And excuse me if I did some grammatical errors, I'm french!
Any help would be appreciated, thanks!
EDIT : Ok, I know what's going on: it's a compatibility issue between IPv4 and IPv6! It's not properly working yet, but I now know what to fix. Thanks everybody :)
SECOND EDIT : Well, I think I finally understood. I was binding my server to a IPv6 address, but the host my server is running on only have a public IPv4 address. When I tried to connect, the DNS resolution only returned a IPv4 address so I was unable to connect to my server. I told to getaddrinfo to return only IPv4 addresses, so now it binds on a IPv4 address and it works fine.
There is surely a way to add a IPv6 address to my host but I don't think I will need it, it works okay right now, I hope this doesn't cause any trouble.
The code makes usage of getaddrinfo and need a hostname not a IP address.
It does sound like you have a connectivity issue or a DNS issue.
Ensure the name resolution is working:
Enter 'ping server_NAME' on the command line of the client machine.
If it can't find an IP address for the server name that could be your issue.
Ensure connectivity:
On the server command line:
enter 'netstat -an -p TCP'. This will show a list of all programs listening and their port numbers. You should see your server listening on port 12543.
On the machine where you are running your client program:
Use telnet to see if you can get through to the server. You can set the port number telnet uses with a command line option. Usually something like 'telnet -p 12543 server-ip'. If it says 'connection refused' then there's a connectivity issue (a firewall/etc). If it opens a connection you will get no error message and you will be able to type text to be sent to the server. You really only care if telnet was able to establish a tcp connection here.
If Telnet does connect then your issue is communication between the programs and not a network issue.
Windows knows when you have removed the network cable from your NIC. Is there a programmatic way to determine this via API in C++?
Note: I am not using .NET and this is for a closed LAN (not connected to Internet ever)
Raymond Chen blogged about something similar recently. Here is the relevant documentation. I think the MIB_IPADDR_DISCONNECTED flag is what you are looking for.
Use the Network List Manager api with the INetwork api.
You can register your app to receive callbacks when networks become connected/not connected.
Or you can get the list of networks and then check each of them to see if the machine is network connected or not
Remember that a windows machine will often have multiple networks set up (Ethernet, wifi, etc)
Remember that just because a network is connected, you may not have access to the internet. Eg you could have DNS or routing problems. Or you could be on a working network that is not connected to the internet.
Due to the above, many diagnostic tools also connect to a "known-good" internet server if they want to really know if they're connected or not. Something like google.com -- they spend a lot of money to make sure that their site is up all the time.
Finally, you can also have a semi-connected situation where packets are getting through but not enough to really enable communications to flow. To test this, don't just ping an internet site since that'd only be a pair of packets. Instead, open a TCP connection or something more than a ping.