LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-08-2008, 10:41 PM   #1
linuxtest
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
Reading the ip address from a packet raw sockets


Hi
I'm trying to read the ip address from a packet buffer from recvfrom, I can read the mac address but when i try the ip useing printf("%s",inet_itoa(ip->saddr)); it says wrong argument.
struct iphdr *ip;

I would perfer not to use libpcap. I've tryed to use sturct sockaddr_in *in printf("%s",inet_itoa(in->sin_addr)); ,and ip address is show ,but isn't correct

If you need anymore info just say.
Thanks
 
Old 12-09-2008, 03:46 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
this website has this information:
Quote:
printf("%-15s ", inet_ntoa(ip->saddr));

Compiling with "gcc -Wall -g -ansi -pedantic" result with a warning: "
incompatible type for argument 1 of `inet_ntoa' ". I came to know the
solution is to change the call into:

printf("%-15s ", inet_ntoa(*(struct in_addr *)&ip->saddr));
i think this is what your looking for. another website said that the inet_itoa is deprecated and suggests using inet_ntop to support ipv6.
 
Old 12-10-2008, 02:43 PM   #3
linuxtest
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks nadroj
It(ntop)allows me to use ip->saddr and just needed to change *packetbuf to packetbuf.

Cheers dude.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
raw sockets in c wee-face Programming 1 02-01-2007 09:35 AM
Raw Packet Sockets in Fedora Core 6 don't transmit Son_of_Merlin Linux - Networking 6 01-02-2007 12:55 AM
Raw Sockets Srikanth0210 Programming 2 12-05-2005 03:22 AM
raw sockets and C wrongman Programming 3 05-04-2004 02:17 PM
raw sockets BashTin Programming 1 06-07-2003 06:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration