请高人指点!
+ C0 b! b$ o/ W想实现 arp --set 192.168.0.100 00:e0:4c:e0:f8:36 pub0 X+ p' P. N/ q+ Q3 i3 j, a* f
结果:SIOCSARP : protocol family not support.: O( ]0 s8 m$ m& I: A$ v
5 M1 q. b o0 C* t1 D7 ~' U9 [, S8 P6 h- A, ]* ~( i- u
#include <sys/types.h>
* @) Q: ?: m d1 ~#include <sys/socket.h>
2 `; W2 o& s0 Z; K#include <sys/ioctl.h>
+ _9 L0 U& D) r4 ?7 p4 h8 p#include <net/if.h>
) e; W, ^+ F9 m' Z/ c! d& ^ h/* #include <linux/netdevice.h> *// d, a, m- y" p" `% s- R
/* #include <linux/if_arp.h> */5 H0 B2 n$ c6 K, A; V! Y- G
#include <net/if_arp.h>! v2 I/ W! e7 z! e; a
#include <stdlib.h>
) U' J' X ^0 D( I% u#include <stdio.h># r2 L, l5 t; }: X5 c
#include <errno.h>1 {% O( d" `2 r* g: `5 N( y
#include <ctype.h>/ |. ]# g( \. l t& z z
#include <fcntl.h>
6 `. I0 `" H" {3 W5 j3 J- P#include <string.h>5 F/ `8 R% m+ M9 ~( s( i
#include <getopt.h>
# O4 t! m4 n" B$ G/ c' @+ F#include <unistd.h>
8 t0 z( y& F3 G2 E
$ x/ ]1 b a4 [) J6 G/* Set an entry in the ARP cache. */
' }& A$ N! a" bint main(int argc, char **argv)3 U0 T; T# G5 ?
{
, R! x1 L! J0 t; u3 B% K struct arpreq req;6 `* o4 w4 x+ c6 `* S+ p% n" G
int flags;
. e( Q+ S# U u" t! R+ b char ip_addr[]={0xc0,0xa8,0x00,0x64};
+ p+ R q, J4 a p/ p* X, r char hw_addr[]={0x00,0xe0,0x4c,0xe0,0xf8,0x36};
) z$ }( T* l$ B9 [0 R int sockfd;' p& D# p4 E9 ^3 c3 t3 _
! t8 p6 Q" \7 n if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
* g5 G2 n$ q. I* R1 m5 P {- i$ T5 h1 F3 _2 N
perror("socket");
2 a% S0 N2 Q1 ]- n9 \4 v exit(-1);5 r0 L$ ~0 G9 {: C3 c7 a0 V: X1 A
}' M' f9 |& s+ w! c+ h7 |4 i
memset((char *) &req, 0, sizeof(req));+ @+ W# b! Z6 J) j) T
memcpy((char *) &req.arp_pa, ip_addr, 4);& [, d% i# s9 b6 p. U- O* A
memcpy((char *)&req.arp_ha,hw_addr,6);
6 R/ a! [6 D) i& |& i# F1 {2 t. K
1 \3 b) X ^% v9 M flags = ATF_PERM | ATF_COM | ATF_PUBL;
4 P6 K/ H- e0 c% J) T$ C /* Fill in the remainder of the request. */
+ [, c8 z! j& x5 O
/ {* Z' Y% ?3 S2 G! ]0 n req.arp_flags = flags;
9 U$ ?1 `7 c* ~" q! J8 @2 b. g! g& T5 Y if (ioctl(sockfd, SIOCSARP, &req) < 0) {
2 E U: s* u& a/ H& Z$ ?: l perror("SIOCSARP");
- W o% [# K0 D' ] return (-1);+ G! m0 \- W3 n: U" b$ S& ]0 B
}$ @3 u. m2 F, S* Q( O
return (0);5 r' b1 e8 M9 U
}
7 H: i& Z3 k1 D9 F \- l: W6 J- v3 @# d% ]9 g
* j& q r7 d! p1 v0 m; s# G( L. _
! w6 |4 S. _' t4 [7 E- G) i