1 diff -up iputils-s20071127/arping.c.infiniband iputils-s20071127/arping.c
2 --- iputils-s20071127/arping.c.infiniband 2007-11-27 01:57:27.000000000 +0100
3 +++ iputils-s20071127/arping.c 2008-08-08 10:05:04.000000000 +0200
4 @@ -50,14 +50,26 @@ int unicasting;
8 -struct sockaddr_ll me;
9 -struct sockaddr_ll he;
11 + * Make these two structs have padding at the end so the overly long Infiniband
12 + * hardware addresses can have the remainder of their address tacked onto
13 + * the end of the struct without overlapping anything.
15 +struct sockaddr_ll me[2];
16 +struct sockaddr_ll he[2];
18 struct timeval start, last;
21 int received, brd_recv, req_recv;
23 +#define SYSFS_MNT_PATH "/sys"
24 +#define SYSFS_CLASS "class"
25 +#define SYSFS_NET "net"
26 +#define SYSFS_BROADCAST "broadcast"
27 +#define SYSFS_PATH_ENV "SYSFS_PATH"
28 +#define SYSFS_PATH_LEN 256
30 #define MS_TDIFF(tv1,tv2) ( ((tv1).tv_sec-(tv2).tv_sec)*1000 + \
31 ((tv1).tv_usec-(tv2).tv_usec)/1000 )
33 @@ -124,7 +136,8 @@ int send_pack(int s, struct in_addr src,
36 gettimeofday(&now, NULL);
37 - err = sendto(s, buf, p-buf, 0, (struct sockaddr*)HE, sizeof(*HE));
38 + err = sendto(s, buf, p-buf, 0, (struct sockaddr*)HE, (ah->ar_hln > 8) ?
39 + sizeof(*HE) + ah->ar_hln - 8 : sizeof(*HE));
43 @@ -172,7 +185,7 @@ void catcher(void)
46 if (last.tv_sec==0 || MS_TDIFF(tv,last) > 500) {
47 - send_pack(s, src, dst, &me, &he);
48 + send_pack(s, src, dst, &me[0], &he[0]);
49 if (count == 0 && unsolicited)
52 @@ -219,7 +232,7 @@ int recv_pack(unsigned char *buf, int le
56 - if (ah->ar_hln != me.sll_halen)
57 + if (ah->ar_hln != me[0].sll_halen)
59 if (len < sizeof(*ah) + 2*(4 + ah->ar_hln))
61 @@ -230,7 +243,7 @@ int recv_pack(unsigned char *buf, int le
63 if (src.s_addr != dst_ip.s_addr)
65 - if (memcmp(p+ah->ar_hln+4, &me.sll_addr, ah->ar_hln))
66 + if (memcmp(p+ah->ar_hln+4, &me[0].sll_addr, ah->ar_hln))
70 @@ -248,7 +261,7 @@ int recv_pack(unsigned char *buf, int le
72 if (src_ip.s_addr != dst.s_addr)
74 - if (memcmp(p, &me.sll_addr, me.sll_halen) == 0)
75 + if (memcmp(p, &me[0].sll_addr, me[0].sll_halen) == 0)
77 if (src.s_addr && src.s_addr != dst_ip.s_addr)
79 @@ -264,7 +277,7 @@ int recv_pack(unsigned char *buf, int le
80 printf("for %s ", inet_ntoa(dst_ip));
83 - if (memcmp(p+ah->ar_hln+4, me.sll_addr, ah->ar_hln)) {
84 + if (memcmp(p+ah->ar_hln+4, me[0].sll_addr, ah->ar_hln)) {
88 @@ -290,12 +303,69 @@ int recv_pack(unsigned char *buf, int le
92 - memcpy(he.sll_addr, p, me.sll_halen);
93 + memcpy(he[0].sll_addr, p, me[0].sll_halen);
99 +int get_sysfs_mnt_path(char *mnt_path, size_t len)
101 + const char *sysfs_path_env;
104 + if (len == 0 || mnt_path == NULL)
107 + /* possible overrride of real mount path */
108 + sysfs_path_env = getenv(SYSFS_PATH_ENV);
109 + memset(mnt_path, 0, len);
111 + sysfs_path_env != NULL ? sysfs_path_env : SYSFS_MNT_PATH,
114 + if ((pth_len = strlen(mnt_path)) > 0 && mnt_path[pth_len-1] == '/')
115 + mnt_path[pth_len-1] = '\0';
120 +int make_sysfs_broadcast_path(char *broadcast_path, size_t len)
122 + char mnt_path[SYSFS_PATH_LEN];
124 + if (get_sysfs_mnt_path(mnt_path, len) != 0)
127 + snprintf(broadcast_path, len,
128 + "%s/" SYSFS_CLASS "/" SYSFS_NET "/%s/" SYSFS_BROADCAST,
134 +char * read_sysfs_broadcast(char *brdcast_path)
138 + char *brdcast = NULL;
140 + if ((fd = open(brdcast_path, O_RDONLY)) > -1) {
141 + len_to_read = lseek(fd, 0L, SEEK_END);
142 + if ((brdcast = malloc(len_to_read+1)) != NULL) {
143 + lseek(fd, 0L, SEEK_SET);
144 + memset(brdcast, 0, len_to_read+1);
145 + if (read(fd, brdcast, len_to_read) == -1) {
157 main(int argc, char **argv)
159 @@ -459,9 +529,9 @@ main(int argc, char **argv)
163 - me.sll_family = AF_PACKET;
164 - me.sll_ifindex = ifindex;
165 - me.sll_protocol = htons(ETH_P_ARP);
166 + me[0].sll_family = AF_PACKET;
167 + me[0].sll_ifindex = ifindex;
168 + me[0].sll_protocol = htons(ETH_P_ARP);
169 if (bind(s, (struct sockaddr*)&me, sizeof(me)) == -1) {
172 @@ -474,14 +544,33 @@ main(int argc, char **argv)
176 - if (me.sll_halen == 0) {
177 + if (me[0].sll_halen == 0) {
179 printf("Interface \"%s\" is not ARPable (no ll address)\n", device);
185 + char brdcast_path[SYSFS_PATH_LEN];
189 + if (make_sysfs_broadcast_path(brdcast_path, sizeof brdcast_path) != 0) {
190 + perror("sysfs attribute broadcast");
194 + if ((brdcast_val = read_sysfs_broadcast(brdcast_path)) == NULL) {
195 + perror("sysfs read broadcast value");
198 + for (ch=0; ch<he[0].sll_halen; ch++) {
199 + he[0].sll_addr[ch] = strtol(brdcast_val + (ch*3), &next_ch, 16);
203 - memset(he.sll_addr, -1, he.sll_halen);
208 printf("ARPING %s ", inet_ntoa(dst));
209 @@ -501,12 +590,12 @@ main(int argc, char **argv)
211 sigset_t sset, osset;
212 unsigned char packet[4096];
213 - struct sockaddr_ll from;
214 + struct sockaddr_ll from[2];
215 socklen_t alen = sizeof(from);
218 if ((cc = recvfrom(s, packet, sizeof(packet), 0,
219 - (struct sockaddr *)&from, &alen)) < 0) {
220 + (struct sockaddr *)&from[0], &alen)) < 0) {
221 perror("arping: recvfrom");
224 @@ -514,7 +603,7 @@ main(int argc, char **argv)
225 sigaddset(&sset, SIGALRM);
226 sigaddset(&sset, SIGINT);
227 sigprocmask(SIG_BLOCK, &sset, &osset);
228 - recv_pack(packet, cc, &from);
229 + recv_pack(packet, cc, &from[0]);
230 sigprocmask(SIG_SETMASK, &osset, NULL);
233 diff -up iputils-s20071127/Makefile.infiniband iputils-s20071127/Makefile
234 --- iputils-s20071127/Makefile.infiniband 2008-08-08 09:17:35.000000000 +0200
235 +++ iputils-s20071127/Makefile 2008-08-08 10:02:10.000000000 +0200
236 @@ -37,6 +37,8 @@ rdisc_srv: rdisc_srv.o
238 $(CC) $(CFLAGS) -DRDISC_SERVER -o rdisc_srv.o rdisc.c
241 + $(CC) $(LDFLAGS) arping.o $(LOADLIBES) $(LDLIBS) -o arping
244 ifeq ($(KERNEL_INCLUDE),)