LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 07-05-2015, 11:37 PM   #1
aniruddha.jagdale
LQ Newbie
 
Registered: Apr 2013
Posts: 19

Rep: Reputation: Disabled
error: ‘struct arphdr’ has no member named ‘ar_sha’


I'm creating my own ARP header with below shown code, however this code ain't working, I get error message as struct arphdr has no member named ar_sha, ar_spa, ar_tha, ar_tpa. I've checked net/if_arp.h, these members are part of struct arphdr. Why i'm unable to use them?? Please assist.

Code:
#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<linux/if_arp.h>
#include<netinet/in.h>
#include<netinet/ether.h>
#include<netinet/arp.h>
#include<net/ethernet.h>
#include<net/if_arp.h>


int main()
{
  int rawsock;
  u_char *pckt;
  int const any=1;
  struct arphdr arp;
  struct sockaddr_in pk;

  arp.ar_hrd=htons(ARPHRD_ETHER);
  arp.ar_pro=htons(ETHERTYPE_IP);
  arp.ar_hln=6;
  arp.ar_pln=4;
  arp.ar_op=htons(ARPOP_REQUEST);
  arp.ar_sha=ether_aton("ss:ss:ss:ss:ss:ss");
  arp.ar_spa=inet_addr("192:168:32:128");
  arp.ar_tha=ether_aton("ff:ff:ff:ff:ff:ff");
  arp.arp_tpa=inet_addr("192.168.32.1"); 

  pckt=(u_char*)malloc(sizeof(arp));

  memcpy(pckt,&arp,sizeof(arp));
 
  pk.sin_family=AF_INET;
  pk.sin_addr.s_addr=arp.arp_spa;

  rawsock=socket(AF_INET,SOCK_RAW,IPPROTO_RAW);

  if(rawsock<0)
    perror("socket() failed:");

  if(setsockopt(rawsock,IPPROTO_IP,IP_HDRINCL,&any,sizeof(any))<0)
    perror("setsockopt() failed:");

  if(sendto(rawsock,pckt,sizeof(arp),0,(struct sockaddr *)&pk,sizeof(pk))<0)
    perror("sendto() failed:");

  return 0;
}
Code:
Output:
error: arphdr has no member named sha
error: arphdr has no member named spa
error: arphdr has no member named tha
error: arphdr has no member named tpa

Last edited by aniruddha.jagdale; 07-05-2015 at 11:50 PM.
 
Old 07-06-2015, 12:38 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
struct arphdr does not have this members
ar_sha, ar_spa, ar_tha, arp_tpa
these are members of struct ether_arp (if_ether.h)
 
Old 07-06-2015, 12:43 AM   #3
aniruddha.jagdale
LQ Newbie
 
Registered: Apr 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
net/if_arp.h says that ar_sha, ar_spa, ar_tha, arp_tpa are members of struct arphdr

1. http://www.scs.stanford.edu/histar/s...e/net/if_arp.h
2. http://unix.superglobalmegacorp.com/....h.html#arphdr

struct arphdr
{
unsigned short int ar_hrd; /* Format of hardware address. */
unsigned short int ar_pro; /* Format of protocol address. */
unsigned char ar_hln; /* Length of hardware address. */
unsigned char ar_pln; /* Length of protocol address. */
unsigned short int ar_op; /* ARP opcode (command). */
#if 0
/* Ethernet looks like this : This bit is variable sized
however... */
unsigned char __ar_sha[ETH_ALEN]; /* Sender hardware address. */
unsigned char __ar_sip[4]; /* Sender IP address. */
unsigned char __ar_tha[ETH_ALEN]; /* Target hardware address. */
unsigned char __ar_tip[4]; /* Target IP address. */
#endif
};

Can you please assist understanding this?
 
Old 07-06-2015, 02:57 AM   #4
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
#if 0
...
#endif
it the same as commenting the code in between out
so it's comentet out, in both of you headers.

what do you want to write, an arp sniffer?
 
Old 07-06-2015, 03:07 AM   #5
aniruddha.jagdale
LQ Newbie
 
Registered: Apr 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
Yeah.. I took a note of that. Now the question is how to access those members or assign them the values. I don't want to write a sniffer, but a simple code that can inject or send manipulated ARP packet. Besides, why those members are mentioned in struct arphdr if the are to be commented or not to be used?
 
Old 07-06-2015, 03:44 AM   #6
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by aniruddha.jagdale View Post
Now the question is how to access those members or assign them the values.
you can not access or assign values to something that does not exist


possible you look for struct ether_arp from
http://www.scs.stanford.edu/histar/s...net/if_ether.h
because there are your members
 
  


Reply



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
error: â??struct sk_buffâ?? has no member named â??dstâ?? sunayanaiyer@gmail.com Linux - Newbie 2 05-29-2012 12:32 AM
[SOLVED] error: 'struct tty_struct' has no member named 'device' vlzj Programming 4 04-11-2012 07:58 PM
error: 'struct SDL_SysWMinfo' has no member named 'info' TiDjY Linux - Desktop 4 11-24-2008 06:00 AM
error: ‘struct tcphdr’ has no member named ‘th_flags’ nasim751 Linux - Software 0 04-17-2008 05:55 AM
error: ‘struct inode’ has no member named ‘u’ PankajDS Linux - Kernel 0 02-25-2008 11:34 PM

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

All times are GMT -5. The time now is 07:51 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