473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

packet help

hi community

my first post.

i have been developing a yahoo messenger client for nintendo ds hand held console utilizing its wifi functionality.I finished laying out the user interface.
i am left with the yahoo protocol.

I want to do some test programs using sockets before actually coding it into my program.
I want to know how to create a packet in c language with the following structure



<------- 4B -------><------- 4B -------><---2B--->
+-------------------+-------------------+---------+
| Y M S G | version | pkt_len |
+---------+---------+---------+---------+---------+
| service | status | session_id |
+---------+-------------------+-------------------+
| |
: D A T A :
| 0 - 65535* |
+-------------------------------------------------+

the library which i use for ds has all the commands for sending and receiving information through sockets.So i just need to know how packets are made or represented in c
May 18 '07 #1
3 1824
Banfa
9,065 Expert Mod 8TB
You just need to put the byte values for the various Fields into an array of char (or unsigned char) this could be allocated dynamically.

Expand|Select|Wrap|Line Numbers
  1. char *pPacket;
  2.  
  3. pPacket = malloc( <TotalLengthOfPacket> );
  4.  
  5. pPacket[0] = 'Y';
  6. pPacket[1] = 'M';
  7. pPacket[2] = 'S';
  8. pPacket[3] = 'G';
  9.  
  10. ...
  11.  
  12. send(pPacket, <TotalLengthOfPacket>);
  13.  
May 18 '07 #2
thanks banfa.

the lib i am using is called palib.it has the following functions.
Supposing
i want to see a network path is available to yahoo server then i have to send the following packet


YMSG --------version 12-----------0
verify(76)-----available----------null


supposing i have to send that to the yahoo server i will first declare a char buffer to store in the packet contents.










char *pPacket;


pPacket = malloc( <TotalLengthOfPacket> );

pPacket[0] = 'Y';
pPacket[1] = 'M';
pPacket[2] = 'S';
pPacket[3] = 'G';

..........


YMSG //this one is clear

version valuue is a 4 byte value '0x09 0x00 0x00 0x0'
0
verify
available
null

so how do i store thse values into the array???
the byte values?

palib has the following handy command once i am able to finish the packet


int sock;
char *pPacket;//create buffer

PA_InitSocket(&sock,"scs.msg.yahoo.com",5050,PA_NO RMAL_TCP); //open socket on yahoo server on port 5050

char *strcpy ( char *pPacket, const char *src ); //i need help with this command too i am not sure if its correct


send(sock,pPacket,256,0); //send the buffered arrayu to yahoo server


this is how it is but as you can see i have a few doubts with strcpy usage and packet representation.Can you help me pout?
May 18 '07 #3
Banfa
9,065 Expert Mod 8TB
pPacket[0] = 'Y';
pPacket[1] = 'M';
pPacket[2] = 'S';
pPacket[3] = 'G';

..........


YMSG //this one is clear

version valuue is a 4 byte value '0x09 0x00 0x00 0x0'
Expand|Select|Wrap|Line Numbers
  1. pPacket[0] = 'Y';
  2. pPacket[1] = 'M';
  3. pPacket[2] = 'S';
  4. pPacket[3] = 'G';
  5. pPacket[4] = 0x09;
  6. pPacket[5] = 0x00;
  7. pPacket[6] = 0x00;
  8. pPacket[7] = 0x00;
  9.  
  10. ...
  11.  
But make sure you have the bytes in the right order, bytes 4 - 7 are the value 9 if the byte order is little endian(least significant byte first) but value 150994944 if the byte order is big endian (most significant byte first).
May 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Marcia Hon | last post by:
Hi, I am using read and send of the socket library. I would like to send packets that have variable length, and I would like to read these packets. I have designated the first 2 bytes to state...
12
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
2
by: flywave | last post by:
hi,who can help me ?i came into a problem that how can i get a packet which was send in the LAN.in a word ,how the sniffer works. I once used the rawsocket in win2000 or xp,and it do catch. but...
2
by: bobrics | last post by:
Hi, I would like to create a packet for a RAW socket transfer. Please let me know if this is the right approach. 1. First, I am creating a header structure where I store all the information I...
1
by: visal | last post by:
hi Please help me.i am developing a java pgm to capture network packets using jpcap.i downloded jpcap and wpcap dll files. My pgm is: import jpcap.JpcapHandler; import jpcap.Jpcap; import...
6
Sagittarius
by: Sagittarius | last post by:
I will first try to describe my problem in words. I have a simple program, written in C++, that needs to send a single bytearray via a UDP socket to a microprocessor, which returns an answer, also...
3
by: nexus024 | last post by:
I am trying to write a program that will continuously sniff eth0 for a specific UDP packet thats being sent to a specific destination IP, alter the data of the packet, and finally transmit it to the...
1
by: sangith | last post by:
Hi, I tried the packet capture module program. I did a file transfer using ftp from this host to another server. But when I ran the program, it was just hanging off and it did not print the...
1
by: AngreGanon | last post by:
Hi all~ I've written a network program in C. This program catputures ARP request packet and reply wrong ARP packet. Hi. I've written a small program to learn to write in C. But unfortunately...
0
by: ShambhuHubli | last post by:
Hi all ! In my application, I need to construct a packet(SMS format), and send it over the network... And should decrypt the packet on the receiver side.... Using Python My packet look like: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.