Programming :: PING Using Raw Sockets In C?

Nov 18, 2010

Is there any way to implement a simple ping script in C (unix)? I'm programming simple OpenWRT scripts.

I have found some examples of ping in C:

[URL]

However, nothing happens, nothing is sent.

When I look at the code, in the portion where the socket is created, I can see that the socket is not binding to any interface:

Code:
if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1)
{
perror("socket");
exit(EXIT_FAILURE);
}
setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &optval, sizeof(int));

Instead, it uses "setsockopt" to set some options.

My guess is that it is trying to send packets over the eth0 interface instead over the wl0 (wireless) interface (which is the one I want to use to send pings).

Now, my question is: Is there any other way to send pings in C by binding to an interface?

View 1 Replies


ADVERTISEMENT

Programming :: C/C++ - Program Detecting New Sockets

Jul 25, 2010

I need to create a C/C++ program in Linux that succeeds in detecting how many tcp-sockets and what tcp-sockets are created by the other processes in the system in a particular time interval (e.g., the interval time this application is running in). Then, I'd need to get some information like local/remote port number and local/remote ip address of each of these sockets.

View 8 Replies View Related

Programming :: How To Use Sockets To Display GUI At Server End

Aug 27, 2010

I am struggling a little on how to best approach this problem. I have wrote a server program that runs via xinetd, that obviously spits out data at the client end. Fairly straightforward stuff?There is a point in my server code where I need to display an image/gui i.e something that runs on X11 that prompts a user to perform a task on the display connected at the the server side.So far I have written a test program that displays some text at the client end and then launches the browser at the server end. I have also set the following export. Code: export DISPLAY=:0 and then goes on to launch my web browser. Works great when ran locally on the server and when I remotely telnet in to the server and run the code.

However when I try to run the same piece of code as a xinetd service the export seems to have zero affect and the client terminal window displays errors associated with there not being a X11 server running.The code launches fine when I create a socket to serverip:6556 it just the ability to display gui programs to another display that does not seem to be working.

View 5 Replies View Related

Programming :: Send A Packet Through Sockets C++

Feb 1, 2011

Can someone help me with this problem,trying to send a packet,using tcp/ip,the packet should look like this:

Code:
field 1: SOCKS protocol version, 1 byte (0x05 for this version)
field 2: status, 1 byte:
0x00 = request granted
0x01 = general failure
0x02 = connection not allowed by ruleset
0x03 = network unreachable
0x04 = host unreachable
0x05 = connection refused by destination host
0x06 = TTL expired
0x07 = command not supported / protocol error
0x08 = address type not supported
field 3: reserved, must be 0x00
field 4: address type, 1 byte:
0x01 = IPv4 address
0x03 = Domain name
0x04 = IPv6 address
field 5: destination address of
4 bytes for IPv4 address
1 byte of name length followed by the name for Domain name
16 bytes for IPv6 address
field 6: network byte order port number, 2 bytes
and this is my code:

Code:
int domainLen = strlen(domain);
char reply[domainLen + 7];
reply[0] = 5; // version
reply[1] = 0; // succed
reply[2] = 0; // reserved
reply[3] = 3; // its a domain
reply[4] = domainLen;; // lenght of domain
for(int j = 0; j < domainLen; ++j)
{
reply[j + 5] = domain[j];
}
reply[5 + domainLen] = 80; // port
reply[20] = '�';
Send(reply, sizeof(reply));
domain is "www.google.com". Am I doing it right ? I dont know much about bits.

View 6 Replies View Related

Programming :: Parallel Data Transfer Using Sockets

Feb 25, 2011

I am doing a project where 2 clients connect to server and communicate (chat) and transfer data one after other using sockets. I have working code for this in C language. Now our main aim is to create a communication link where two clients transfer multiple streams data parallely. To be more precise i want to transfer images files and audio files parallel at same time, so is it possible to send data parallel using one socket connection?

View 3 Replies View Related

Programming :: Creating 2 Sockets In Client / Server?

Jun 9, 2010

I have a problem creating my second socket in client file. the program was running well but when I try to add another socket to connect to the same server, I got a problem connecting to the first socket! it doesn't make sense. the original code was:

sockfd[i] = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd[i] < 0) error("(MAIN) - Error openning socket 1");
port_num[i] = portno;
bzero((char*) &serv_addr[i], sizeof(serv_addr[i]));

[Code].....

View 1 Replies View Related

Programming :: Read DNS Informaton Using Sockets And C Libraries

Jun 9, 2010

I am using the API libpcap in order to filter the traffic of the port 53 from my PC ro other PCs, in other words the DNS traffic.I want to get more information about the DNS traffic that is being sent to the DNS server, in other words the queries. So far I have no idea how to read the information data or payload of the UDP package in order to read the content of the traffic for example if there is any PTR, A, MX, etc Resource Record.According to the RFC 1053 there is a header that is possible to use in order to easily get this info.

View 5 Replies View Related

Programming :: Automated Monitoring Of Different Sockets For Available Data

Feb 4, 2011

NextPendingConnection () returns a new socket with respect to a new client. This new QSocket is passed to the connect () function which connects it to a SLOT 'xyz' with SIGNAL 'readyRead()'. Now in the SLOT 'xyz' how I am supposed to automate the monitoring of ALL connected sockets to see whether some data is available on them? One pathetic way would be to run all the sockets through a for loop and check each one of them for the data. Secondly, I read up on QSocketNotifier() here: [URL]. But I am not sure if that is the correct thing.

View 3 Replies View Related

Programming :: Sending Binary Data Through Sockets In C

Nov 29, 2010

I am coding a http server which has to send the file(s) such as images, .avi files, .mpeg, that the client is going to request. I have been trying of sending files through sockets.

char info [256];
bzero(info, 256);
//memset(&info,0,sizeof(info));
read(socket, info, 255);
write(socket, HTTP, 255);
FILE *fl= fopen(info,"rb");
fseek(fl, 0, SEEK_END);
long len = ftell(fl);
printf("largo: %ld", len);
unsigned char *ret = (char*) malloc(len);
fseek(fl, 0, SEEK_SET);
fread(ret, 1, len, fl);

However, it's supposed to be shown in Mozilla Firefox (as the client). But it is not doing it, so.. It's just not getting the complete file.

View 1 Replies View Related

Programming :: Possible To Pass File D Escriptor Without Sockets / Streams?

Apr 20, 2010

I have a problem passing a file descriptor from one process to another.

I have two processes A and B. Both are running in different network and
filesystem namespaces, so it is impossible to use unix domain sockets or
net sockets to pass a file descriptor from process A to process B.

The usage of STREAMS is also impossible, as you can see in
fixunix.com/unix/84093-streams-pipes-ioctl-i_sendfd.html

[quotation begin]
Linux doesn't have STREAMS, which are the System V way
of doing this task. ...
[quotation end]

Are there additional possibilities for file descriptor passing like
using named pipes or something like that or does anybody know
a good workaround for this problem ?

View 9 Replies View Related

Programming :: Closing Multiple Client Sockets In Server ?

Nov 30, 2010

I have written a server application which has select for both incoming new client connection requests and incoming data from client. I am able to process incoming connection requests and client data.

For example, server has 8 clients connected to it. If client 3 disconnects from server, how will server come to know this client has disconnected and to close its client socket fd gracefully? Does server's select get data on that client socket fd as 'close' data or any error code in recv() function that notifies server to close this client socket fd? Also if client disconnects abruptly without sending close request to server, how should server handle this? Does server get "EPIPE" error?

View 1 Replies View Related

Programming :: Send A Request To A Http Server Without Using Sockets.

Jul 8, 2011

Hi, is it possible to send a request to a http server without using sockets?

View 7 Replies View Related

Programming :: Sockets - P2 - P3 Http Connection Taking More Time Than The Expected?

Mar 31, 2011

Iam using socket programming in one of my problem. The scenario is like this.

=>one module is working as a socket server(process p1) is able to handle client sockets on that port.
=>one module is working as socket client (process p2) is connected to server socket and Tx/Rx data on this socket. This module has some more threads, based on received data from server socket it will connect to http on other thread and get information...
=>one more module is working as socket client (process p3) is also connected to server socket and doing some other transactions.

Here my problem is when in presence of p2, p3 http connection taking more time than the expected. If we wont start p3(means only one server-client socket) then http connection is fast enough.

View 1 Replies View Related

Programming :: While Receiving Can Use Functions Like Strchr() To Differentiate These Fields For Sockets?

Apr 15, 2009

constructing a protocol where in it involves sending and receiving different files, so sending data over consists of file name, size of the file and content of the file, so while receiving can i use functions like strchr() to differentiate these fields for sockets? so to allocate memory for file to save i need to have its size.

View 3 Replies View Related

Networking :: Cannot Ping With Command - Ping IP - Address But Can Ping With - Ping IP -I Eth0

Jul 15, 2011

I am using an virtual machine. where I need to ping from one machine to another. earlier I was able to ping. But after going to google.com once, I cannot ping back to this machine.

But if I gave ping -I eth1 <IP> then I can ping.

I cannot install any package, so tell me solution which includes not installing any package.

View 2 Replies View Related

Programming :: Add Local Sockets In Multi-threaded Application In Order To Exchange Data Between Threads?

Jul 24, 2010

I'm trying to add local sockets in my multi-threaded application in order to exchange data between threads. The only problem I got is that most of the information available on the net is related to internet oriented socket programming whileI want to perform local connections. got a thread that does the sniffing via libpcap. And I would like that thread to send each captured packet to a second thread that will analyse the packetof the thread implementations is written in separate .h file.Or maybe there is a more effective method of exchanging data between threads

View 14 Replies View Related

Programming :: Connect Multiple Sockets From A Single Client To A Single Server And Keep Them Open?

Oct 13, 2010

I have question about the UNIX sockets. my goal is to connect multiple sockets from a single client to a single server and keep them open...I'm not sure if that is possible to create or not. Do you have any suggestion or an example of code?

View 1 Replies View Related

Programming :: Netlink Sockets In Kernel And Ethernet Driver - Kernel Crash

Aug 31, 2010

I write the network driver. Transmission of packets in user space I do through netlink socket`s. In user space there is a handling of packets and their transmission on other device (however, it isn't important).

Problem in that any time, packets through the driver in system, and is reverse, are transferred normally. But then there comes the moment when the kernel crash. If to look in syslog it seems to me that comes deadlock. Also I think that it is related with netlink socket`s.

I can't find the information on that anywhere how correctly to use netlink socket`s in kernel space. Can at you will any a reason into the account of synchronization of sockets and the driver in kernel space?

I can give the driver code if it is necessary.

View 2 Replies View Related

Programming :: Ping Hosts From Database?

Apr 26, 2011

I have a php scriptI want it to ping list of ips from a databse(using fping) and based on the status of the values to put them in a field(status) into the database(0 if down,1 if up)i executed tghe script and it gives me this error:Thread 1 - 17:51:01 26-04-2011 4.2.2.2 alive Couldn't execute query.I cant see what 's wrongthis is the source of the php script:

<?php
require_once("conf.php");
$connection1 = mysql_connect($h, $u, $p) or die("Couldn't connect.");

[code]....

View 1 Replies View Related

Programming :: Ping A List Of Devices?

Jul 27, 2010

I would like to ping all my virtual hosts in virtual machine server with a oneliner. For example like this:

Code:

for i in $(seq 1 20); do if [[ $(ping host$i.virtualhostserver.com -c 2 2>/dev/null | grep "2 received") == "2 packets transmitted" ]]; then echo $i; fi; done

The problem is, that I'm afraid my if-sentence is somewhat wrong because it never gets a match even if I know, that host is up.

View 5 Replies View Related

Programming :: Ping Command Not Working In Tcl/tk?

Feb 16, 2010

I can't get exec ping to work on my system. wish is located in /usr/bin/wish8.4

Code:
#!/usr/bin/wish8.4
text .txt
set in [open "/root/hosts.txt" r]
while {[gets $in line] != -1} {

[Code]....

View 2 Replies View Related

Programming :: Ping With Shell Script?

Sep 15, 2010

Now I am using ping command following

ping -I eth1 192.168.1.17

I want to add to shell script but I want type myself -I and eth1 when running the bash file.

View 9 Replies View Related

Programming :: PHP - Ping Test In Shell / CMD Window

Mar 4, 2010

I'm trying to do the following. from a php webpage click on a link, that opens a shell/cmd and runs an open ping to the device. so it must actually open a shell (for linux) or cmd (for windows) and run a ping to the specified ip. Currently i'm running an exec command, but for this i need to wait for the result to be fetched and print it out. I want to monitor it in realtime, by just clickingon the button. How to get this working?

View 1 Replies View Related

Programming :: Script With Will Ping A Network To Find Out Unused IP?

Jun 29, 2010

Is it possible to create threads in BASH? I need a script with will ping a network to find out unused IP. in a for or while loop the pinging process is taking a very long time. I was wondering if it is possible to send multiple ping on the same time so this will speed up the scanning process.

View 5 Replies View Related

Programming :: Ping IP Addresses Using Bash (Online Or Unavailable)

Jun 14, 2011

I am new to linux and am trying to write a script that will ping IP addresses and say either online or unavailable.

View 3 Replies View Related

Programming :: Get Errors When Marc Greis 7 Th Chapter Ping Program Was Tried?

Dec 16, 2010

Please let me know how i will overcome this.I have tried from the past 5 days.

[root@localhost ~]# cc p.cc
In file included from p.cc:1:
/root/ping.h:2:32: warning: multi-character character constant
In file included from p.cc:1:
/root/ping.h:4: error: stray in program
/root/ping.h:2: error: invalid function declaration

[Code]...

View 2 Replies View Related

Programming :: NS2 Marc Greis Chapter 7 Ping Protocol Code

Dec 16, 2010

Split programming in ns2 marc greis chapter 7 ping protocol code. I tried compiling the above program and got the errors as in error.txt I have attached. Ping.cc and ping.h also are attached. I have supplied all the required header files along with appropriate paths and yet this problem.

ATTACH]5537[/ATTACH]
pingcc.txt
pingh.txt

View 3 Replies View Related

OpenSUSE Network :: Nmblookup Resolves But Cannot Ping Netbios Names Or Ping FQDN

Feb 23, 2011

This applies to my 2 opensuse PC's, my Windows PC is fine.I can ping a hostname, say "PC1" but I can not ping PC1.domain.local (even the host PC can not ping it's own FQDN). When I ping just the hostname the ping stats even list the FQDN.Onto the next issue, since all my PC's, have the domain prefix domain.local, my Synology can not. I can ping it's IP and that is it. I can resolve it's name with nmblookup just fine tho and that is what is killing me. How is this not resolving.Even weirder, I can browse to "Synology" in Network Servers under places on the slab.

View 3 Replies View Related

General :: Ping - Gives Unknown Host Error - Ping To LAN Address Works Fine

May 13, 2011

Even ping google's ip address doesn't work. unknown host error using backtrack4 able to browse net with these settings.

My network settings:

What's the problem with these settings...

View 10 Replies View Related

Networking :: Debian 5 - After SysCp Installation And Configure Ping Valure - Ping - Unknown Host

Jul 9, 2010

Ive got a problem on my server ....installed Debian 5 , Webmin and than syscp settung up syscp ready ....

I try to ping "localhost" ansver ping: unknown host
I try to ping "localhost." there is a host with IP 127.0.0.1

I need it to change it in "localhost"

Is that the bind9 maybe?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved