Sponsored Content
Full Discussion: SIOCSARP: Invalid Argument.
Top Forums Programming SIOCSARP: Invalid Argument. Post 302447551 by semash! on Monday 23rd of August 2010 01:23:17 PM
Old 08-23-2010
SIOCSARP: Invalid Argument.

Hello everybody,
I've been programming an alternative to linux's standard 'arp' program. I can delete arp entries (SIOCDARP), get arp entries (SIOCGARP), but i'm having troubles setting entries with ioctl.

I can't set any PERM, USETRAILERS, or COM address. It only adds PUB entries and i don't know why.

This is the code:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <netinet/in.h>
#include <net/if.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if_arp.h>

char *mac_ntoa(unsigned char *ptr){
static char address[30];

sprintf(address, "%02X:%02X:%02X:%02X:%02X:%02X",
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);

return(address);
} /* End of mac_ntoa */

void mac_aton(char *buffer, char *pointer){
int i;
char c, val;
for(i = 0; i < 6; i++){
if(!(c = tolower(*pointer++))){
fprintf(stderr, "Invalid MAC Address.\n");
exit(-1);
        }/* End of If*/
if(isdigit(c)){
val = c - '0';
        }/* End of If*/
else if(c >= 'a' && c <= 'f'){
val = c - 'a' + 10;
        }/* End of Else If*/
else{
fprintf(stderr, "Invalid MAC Address.\n");
exit(-1);
        }/* End of Else */
if(isdigit(c)){
val = c - '0';
        } /* End of If*/
else if(c >= 'a' && c <= 'f'){
val = c - 'a' + 10;
        } /* End of Else If*/
else{
fprintf(stderr, "Invalid MAC Address.\n");
exit(-1);
        } /*End of Else*/
*buffer++ |= val; /* Store into buffer */
if(*pointer == ':'){
pointer++;
        } /* End of If */
} /* End of For */
} /* End of mac_aton */


int main(int argc, char* argv[]){
int s;

struct arpreq req;
struct hostent *hp;
struct sockaddr_in *sin;

char *host = argv[1];

bzero((caddr_t)&req, sizeof(req));
sin = (struct sockaddr_in *)&req.arp_pa;
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = inet_addr(host);
if(sin->sin_addr.s_addr ==-1){
if(!(hp = gethostbyname(host))){
fprintf(stderr, "arp: %s ", host);
herror((char *)NULL);
return(-1);
}
bcopy((char *)hp->h_addr, (char *)&sin->sin_addr, 
sizeof(sin->sin_addr));
}
strcpy(req.arp_dev, "eth0");
mac_aton(req.arp_ha.sa_data, argv[2]);

argc -=2;
argv +=2;

req.arp_flags = ATF_PERM;

while(argc-- > 0){
if(!(strncmp(argv[0], "temp", 4))){
req.arp_flags &= ~ATF_PERM;
    } else if (!(strncmp(argv[0], "pub", 3))){
req.arp_flags |= ATF_PUBL;
    } else if (!(strncmp(argv[0], "trail", 5))){
req.arp_flags |= ATF_USETRAILERS;
}
argv++;
}/* End of While */

if((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
perror("socket() failed.");
exit(-1);
}

if(ioctl(s, SIOCSARP, (caddr_t)&req) <0){
perror(host);
exit(-1);
}
printf("added.\n");
close(s);
return(0);
}

when i run it, it gives me the following error:
Code:
root@host:~# ./a.out 192.168.0.2 AA:BB:CC:DD:EE:FF temp
192.168.0.2: Invalid argument

The only entry which it adds is of type "pub".

Can someone tell me where is the error, or what am i missing?
Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

stty: : Invalid argument

Hello Everyone; I have a script that is throwing the following message: stty: : Invalid argument The line that gives the message is the following, sailormoon$ scp home/voice.xml newwave@silvermoon:/newwave/config/radius stty: : Invalid argument voice.xml | ... (2 Replies)
Discussion started by: tony3101
2 Replies

2. Solaris

ps: 65535 is an invalid non-numeric argument for -p option

I want to figure out what is the reason of error message I have in Solaris 10. Why Solaris 10 dosn't recognize 65535? ps: 65535 is an invalid non-numeric argument for -p option usage: ps 'format' is one or more of: Thank you (5 Replies)
Discussion started by: gogogo
5 Replies

3. Programming

error "Invalid argument" returned after call sched_setscheduler

the code is below and the was run on Solaris 9. ----------------------------- struct sched_param param; param.sched_priority = 99; if(sched_setscheduler(0, SCHED_RR, &param) == -1) { perror("setting priority"); exit(1); } ------------------------------- after the... (1 Reply)
Discussion started by: robin.zhu
1 Replies

4. UNIX for Dummies Questions & Answers

msgrcv : Invalid argument

Hi All, Please guide me how to get rid : msgrcv : Invalid argument. I am using message queues: msgsnd and msgrcv, I am able to send through msgsnd and receive through msgrcv, but at times i get the belo error. msgrcv : Invalid argument. (1 Reply)
Discussion started by: answers
1 Replies

5. Solaris

Invalid Argument and glassfish

I tried to install glassfish on Solaris 10 and it worked fine on other instances. I got the below message bash-3.00# ./sjsas-9_1_01-solaris-sparc.bin -console bash: ./sjsas-9_1_01-solaris-sparc.bin: Invalid argument I logged on as root and the file has execute permission. So strange. Do... (1 Reply)
Discussion started by: Andrew2008
1 Replies

6. IP Networking

sendto invalid argument

Hi I lost a lot of time in understanding the message "sendto Invalid argument" when I execute the following code. This code is a simple UDP sender improved with some reliability feature. My goal is to send a file. I've reported only the code which may be useful. Can anyone help me? Thank you... (0 Replies)
Discussion started by: Puntino
0 Replies

7. UNIX for Dummies Questions & Answers

Need FIX for: RTNETLINK answers: Invalid argument

OK...I'm using the latest version of Fedora 10. My network connection was working fine, and I had several network LAN shares on my desktop. Then I rebooted the system without dismounting those shares first. ooops. <:( ...When the system came back up, my network connection was gone. All... (2 Replies)
Discussion started by: Pudnik
2 Replies

8. UNIX for Advanced & Expert Users

invalid argument in semctl()

When I am using the function semctl() it is giving me error as the INVALID ARGUMENT. Can any body give me the possible reasons??? (2 Replies)
Discussion started by: asimibm
2 Replies

9. UNIX for Advanced & Expert Users

NFS : Invalid argument (Remote share mounting issue)

Hi Guru's, I am unable to mount NFS share on unix system (DG/UX) which is nfs client. Error: mount: /nfsshare: Invalid argument mount: giving up on: /mountpoint i tried following command mount -t nfs remotehost:/nfsshare /mountpoint Error: (5 Replies)
Discussion started by: Justin John
5 Replies

10. UNIX for Beginners Questions & Answers

Mount error in Linux: invalid argument

hi i have an android phone which i think is bricked, so wanted to see what the actual issue is, I flashed it with TWRP recovery image and launched terminal i, was able understand that mount is not happening, it says invalid argument and no such file or directory. Below is what i get while... (32 Replies)
Discussion started by: nanz143
32 Replies
ARP(8)							    BSD System Manager's Manual 						    ARP(8)

NAME
arp -- address resolution display and control SYNOPSIS
arp [-n] hostname arp [-nv] -a arp [-v] -d -a arp [-v] -d hostname [proxy] arp -s hostname ether_addr [temp] [pub [proxy]] arp -f filename DESCRIPTION
The arp program displays and modifies the Internet-to-Ethernet address translation tables used by the address resolution protocol (arp(4)). With no flags, the program displays the current ARP entry for hostname. The host may be specified by name or by number, using Internet dot notation. Available options: -a The program displays all of the current ARP entries. -d A super-user may delete an entry for the host called hostname with the -d flag. If the proxy keyword is specified, only the pub- lished ``proxy only'' ARP entry for this host will be deleted. If used with -a instead of a hostname, it will delete all arp entries. -f Causes the file filename to be read and multiple entries to be set in the ARP tables. Entries in the file should be of the form hostname ether_addr [temp] [pub] with argument meanings as described below. -n Show network addresses as numbers (normally arp attempts to display addresses symbolically). -s hostname ether_addr Create an ARP entry for the host called hostname with the Ethernet address ether_addr. The Ethernet address is given as six hex bytes separated by colons. The entry will be permanent unless the word temp is given in the command. If the word pub is given, the entry will be "published"; i.e., this system will act as an ARP server, responding to requests for hostname even though the host address is not its own. If the word proxy is also given, the published entry will be a ``proxy only'' entry. -v Display verbose information when adding or deleting ARP entries. SEE ALSO
inet(3), arp(4), ifconfig(8) HISTORY
The arp command appeared in 4.3BSD. BSD
January 31, 2006 BSD
All times are GMT -4. The time now is 03:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy