Programming :: Build Ip Packet With C,socket Programming?

Jan 30, 2011

How can we build a packet using C?we have a structure called sockaddr_in which is use to for IPv4,so that we can define address,port and etc in this way:

Code:
struct sockaddr_in sock;
sock.sin_family=AF_INET;

[code]...

View 5 Replies


ADVERTISEMENT

Programming :: Socket Programming - Detect Whether A Client Socket Is Closed / Active?

Mar 8, 2011

iam just trying to connect to server which accepts one client and server will read(blocking operation) infinitely, but After closing the client socket the server "read operation" is returning zero and "errno variable(in errno.h)" value is also zero. how can i detect whether a client socket is closed/active..?

client.c
Serv_Addr.sin_family = AF_INET;
Serv_Addr.sin_addr.s_addr = inet_addr("127.0.0.1");
Serv_Addr.sin_port = htons(26553);
if( 0 > connect (Serv_Fds,&Serv_Addr,sizeof(Serv_Addr)) )
{
perror("connect");
return 0;
[Code]....

View 3 Replies View Related

Programming :: Timer In Socket Programming - Wait For X Sec After Read() And Then Disconnect The Client Connection

Mar 8, 2011

I have a server listening on incoming client connections. Once the client establishes SSL connection with the server, the server waits on read() from the client. Only Client can disconnect the connection. I want to have a timer in the server program to wait for x secs after read() and then disconnect the Client connection.

View 3 Replies View Related

Programming :: Socket And Timer Programming - Server Doesn't Execute Any Msg Which Client Sent

May 16, 2011

i have a server program which accept multiple client connection and am using polling. like every 2 secs it will look to client whether any data is received after it binded. i have used setitimer but there is runtime error i got.. the server accept all client connection but doesn't execute any msg which client sent.

#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netdb.h>
#include<unistd.h>
#include<pthread.h>
#include<string.h>
[Code]....

View 1 Replies View Related

Programming :: Socket Programming While Displaying Received Message In File

May 11, 2011

i have problem in socket programming, while displaying received message in file,i got a problem... i cant able to write it in the file.... this is the code....

Code:
/* tcpserver.c */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
[Code]....

now my problem is run time error i can able to create file but i cant able to write file....log.txt contain nothing.... as here i have give sample code... dont say not initialising function and all.... i have initialised , please only see func1() - my problem is only not able to write msg which i got received from the client..

View 2 Replies View Related

Programming :: Use Socket Programming In Order To Implement Chatting Feature?

Aug 25, 2010

how to use socket programming in order to implement chatting feature

View 5 Replies View Related

General :: Socket Programming - Feed Some Words One By One To The Socket

Jul 6, 2010

i'm writing a simple program of client socket program. Here below is the code sample which i'm writing...

Code:
//tcp_client.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include<string.h>
#include<stdlib.h>
[Code].....

the above code works fine.if we copmile and run ./a.exe 192.xx.xx.xxx 1111 and press enter it works fine..everytime it asks "Please enter the message: " and if give that will be displayed in server. but my problem is i dont want to print everytime "Please enter the message: " i just want to feed some words one by one to the socket.

View 4 Replies View Related

Programming :: Setsockopt : Socket Operation On Non-socket Getting Error?

Mar 30, 2009

im getting that error in my code for some reason. I compiled my code, and when i try to run this server it throws me an error on my call to setsocketopt(). The only way it can reach that part of my loop is if it succeeds when it calls sock() so I dont understand why the error says its an operation on a non-socket. Im just trying to set up a server to pass messages from a client to it a viceversa. Here is the code:

Code:
int main()
{
int socket_fd, new_socket_fd, k;
struct addrinfo hints, *server_info, *p;
struct sockaddr_storage peer_address;
code....

View 7 Replies View Related

Programming :: Socket Programming: Insertion Of 0x00 Into The Stream?

Dec 5, 2010

When sending data over the socket, the sending socket includes 0x00 after each sent byte. I wonder how this can be avoided -- I just want to transfer the data in the tx_buffer as it is.

# ./serv &
[1] 6895
# ./EUG 127.0.0.1
EUG: Data to be transmitted: 0x35 0x32 0x30 0xff 0x03 0x31
EUG: Data - #Bytes transmitted: 6
./serv: Here is the message: '5'

[Code]...

View 3 Replies View Related

Programming :: Socket Programming Using Php - Swap A Client Ip And Port?

Mar 28, 2011

Is it possible to swap a client ip and port ? This is what I am trying to do. Let say you have Comp1 and Comp2 And you have Server between them. My goal is to get Comp1 and Comp2 know each others IP So Comp1 connects to server And server stores comp1's IP In a text file or other place And Comp2 connect to server And server also stores his info And then both comp1 and comp2 dowload the tex file And use the info on it.

View 9 Replies View Related

Programming :: Raw Socket Programming ( Head Is Going To Explode )?

Nov 11, 2010

This is my main question:Quote: In raw socket sniffing: how do I copy data from a structure into a char[] or pointer? My problem: I started doing some raw socket programming in OpenWRT (I'm a newbie) for research. It's been a long time since the last time I programmed in C, so here's my newbie question/problem.

I'm receiving packets and using an .h file with the structures to get the information of each 802.11 packet in monitor mode (attached to this post).My (simple) goal is to get the Tx MAC Address. No luck. This is my "read the prism header" function:

Code:
ParsePrismHeader(unsigned char *packet,int len)
{
wlan_header *wlan;ieee_802_11_header *i802;u_int16_t eth_type;
unsigned char *mac;unsigned char *mac2;
wlan = (wlan_header *)packet;
i802 = (ieee_802_11_header *)(packet + wlan->msglen);

[Code]...

View 3 Replies View Related

Programming :: Send File Through Raw Socket Using C Programming

Jul 23, 2010

I am currently doing a research on video transmission over wireless LAN. I tend to transmit my offline file (xx.svc) from server to client.It may sound stupid (since I have a very little knowledge about c programming and raw socket), but my biggest challenges is that when I want to write the file to the buffer, how actually to define/include the file at the programming coding? where I need to locate the file? Is it at the same folder with my c programming, or somewhere in the linuxinclude folder?

Can anyone just give a simple example on how to include a file and write it into a buffer before send it through raw socket.

View 14 Replies View Related

Programming :: Socket Programming - Connect To An IRC Server In A C

Mar 16, 2010

I am looking to be able to connect to an IRC server in a C program. I have followed some instructions from an old book I have however it doesn't seem to be working. I've tried connecting to localhost on my ssh port and it still doesn't want to work. This is what I have so far as a piece of skeleton test code:

Code:
#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<unistd.h>
#include<netinet/in.h>
#include<arpa/inet.h>
[Code]....

View 1 Replies View Related

Programming :: Socket Programming In Module Perl

Jul 21, 2010

Where is the perl module for programming with sockets?

View 4 Replies View Related

Programming :: Socket Programming Select Interface

Jan 15, 2010

I have currently had the need to go back to basic socket programming, and implemented a simple udp packet sender. But I realized I needed to be able to select which network interface to send the packets from.

The reason is so that one of the interfaces has vlan tagging, and I need my UDP packets to be accordingly vlan tagged. For example, one of the interfaces is eth1.200.

View 2 Replies View Related

Programming :: Socket Programming Send File

Jun 22, 2009

this is my client and server. I can receive text file. but I can't send other type of file like PDF,Docx,Odt

View 11 Replies View Related

Programming :: Build A Simple Program For C Programming Class?

Feb 12, 2011

im trying to build a simple program for my C programming class, this is the source code

#include <stdio.h>
int main()
{
int length, width, length, height, area, perimeter;
perimeter = width + length + height;
area = width * length + heigth;

[Code]...

i dont see any error (you might)but every time i run it it runs but after it asks me to input for the width i do it but it doesn't take me to the length, it just stays blank until i input another value in the same place for the width, it asks me for 4 inputs in total i don;t know why, and after i run it different times it gives me different values for the perimeter and are. how can I fix this?

View 5 Replies View Related

Programming :: Create Own Packet In NS2?

Apr 14, 2011

I want to create my own packet for aodv so how can i do? from where i should start?

View 2 Replies View Related

Programming :: How To Tunnel Packet

Apr 19, 2011

I want to develop program to put (tunnel) sniffed packets into another packet, i already have sniffer code to capture packet, can some one give me use full site or simple code to do that.

View 3 Replies View Related

Programming :: How To Access Packet Timestamp

Jan 8, 2011

I want to access the timestamp field of the packet being sent or received. I am not getting clear idea as to which ioctl I should use, and how it should be used in the program. Anyone explain rough flow of the program for accessing the timestamp.

View 5 Replies View Related

Programming :: Perl Disassembling DNS Packet?

May 11, 2010

I'm a newbie trying to modify a DNS-formatted UDP packet. I am piping DNS replies through a firewall queue where I get the packet with $udp_obj->data provided by NetPacket::UDP. Is there a command line application that will break down the udp packet for me so I can extract an answer? Cpan doesn't have a module to do this. One can *create* udp packets programmatically or get them off of libpcap, but I don't need either.

View 7 Replies View Related

Programming :: Save A Packet In The Memory

Feb 7, 2011

i'm sniffing network packets with pcap in ubuntu, i need to save these packets somewhere in the memory and after a while read ans send them. how can i do this?

View 1 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 :: Store A Packet In Buffer?

May 19, 2010

writing a code in C program for debugging error and sendingror messagein routingprotocols. please answer with code

View 2 Replies View Related

Programming :: Send A UDP Msg Across A Socket?

Jan 24, 2011

Has anyone had an issue with gdb not being able to send a UDP msg across a socket?

I have ComponentA sending a msg to ComponentB utilizing gdb. ComponentB gets the msg. ComponentB sends a msg to ComponentC. ComponentC does stuff to the msg and sends a msg back to ComponentB using gdb.
ComponentB never seems to receive the 2nd message.

If I don't use gdb the messages Tx and Rx without an issue.

I'm flying blind without gdb to figure out a different bug.

View 3 Replies View Related

Programming :: Name A Socket By Bind?

Oct 20, 2010

How does bind system call names a socket.Code:bind(server_sockfd, (struct sockaddr *)&server_address, server_len);I see use of bind in majority of programms as above.But any of the arguments is not the name of socket.

View 1 Replies View Related

Programming :: Capture Packet From DMA Ring Buffer?

Jul 21, 2010

I wanna capture network packets from DMA ring buffer, just like netfilter. i wanna capture it from DMA, because i wanna get MAC address of I/O packets, so netfilter not included MAC address of out going packets because its on IP level and Ebtables is like that too. how i can capture network packets from DMA ring buffer.

View 9 Replies View Related

Programming :: Raw Socket Not Sending Packets?

Mar 26, 2010

(Let me first of all state that I am a newbie to any form of programming.) I have been trying to create an IP header + TCP header and send this to another machine on my network.using C)I used the normal stuff: two structures for the headers, a sockaddr_in structure, call to function socket with SOCK_RAW, setsockopt with HDRINCL and call to sendto.All functions seem to return fine (values other then -1) the function that I have used to calculate the checksum for the IPheader matches the value that I manually calculated. I just don?t see the anything coming out of the interface on whireshark.I assumed that it had something do with my piece of code so I used two examples (including mixter void ru rawip html A brief programming tutorial in C for raw sockets[/url]). They show exactly the same thing functions return fine but no packets being send.I use Ubuntu 9.04 2.6.28-14-genericThe machine has two interfaces one with an ip address the other interface is in promiscuous mode. (both interfaces connected to a switch with port mirroring) I can see all normal traffic in/out.

View 2 Replies View Related

Programming :: Socket And Segmentation Fault

Jul 16, 2010

I am programming an application with an ARM device with an embedded version of Linux. My application talks to a java application via socket. If there is any connection problems, it attempts the connection again. My problem is that after exactly 146 times, there is a Segmentation Fault. Apparently this happens in opening the socket, which is not successful after this amount of attempts.

Following, some code that I'm using:

The function for openning the socket and perform a connection:

Code:

View 2 Replies View Related

Programming :: Read Data From A Socket?

Aug 24, 2010

I need to read data from a socket but it should be always listening because data arrives continuously .. I thought something like this would do it but it doesn't work .... I already set the socket options before

Code: char databuf[1024];
int datalen = sizeof(databuf);
if(read(sd, databuf, datalen) < 0)
{

[Code]....

View 9 Replies View Related







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