Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Copyright (c) 2007, IRTrans GmbH |
3 |
* All rights reserved. |
4 |
* |
5 |
* Redistribution and use in source and binary forms, with or without |
6 |
* modification, are permitted provided that the following conditions are met: |
7 |
* * Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* * Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* * Neither the name of IRTrans GmbH nor the |
13 |
* names of its contributors may be used to endorse or promote products |
14 |
* derived from this software without specific prior written permission. |
15 |
* |
16 |
* THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY |
17 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 |
* DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY |
20 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 |
*/ |
27 |
|
28 |
|
29 |
|
30 |
#ifdef WIN32 |
31 |
|
32 |
#include <winsock2.h> |
33 |
#include <windows.h> |
34 |
|
35 |
#else |
36 |
|
37 |
#include <sys/types.h> |
38 |
#include <sys/socket.h> |
39 |
#include <netinet/in.h> |
40 |
#include <sys/un.h> |
41 |
#include <arpa/inet.h> |
42 |
#include <sys/stat.h> |
43 |
#include <errno.h> |
44 |
#include <netdb.h> |
45 |
#include <signal.h> |
46 |
#include <stdio.h> |
47 |
#include <net/if.h> |
48 |
#include <sys/ioctl.h> |
49 |
#include <stdlib.h> |
50 |
|
51 |
|
52 |
typedef int SOCKET; |
53 |
typedef void* WSAEVENT; |
54 |
#define closesocket close |
55 |
#endif |
56 |
|
57 |
#include <stdio.h> |
58 |
|
59 |
typedef unsigned char byte; |
60 |
|
61 |
#ifdef WIN32 |
62 |
typedef unsigned int uint; |
63 |
typedef unsigned short ushort; |
64 |
#endif |
65 |
|
66 |
typedef struct { |
67 |
byte op; |
68 |
byte htype; |
69 |
byte hlen; |
70 |
byte hops; |
71 |
uint xid; |
72 |
ushort secs; |
73 |
ushort flags; |
74 |
uint client_ip; |
75 |
uint own_ip; |
76 |
uint server_ip; |
77 |
uint relay_ip; |
78 |
byte client_mac[16]; |
79 |
byte server_name[64]; |
80 |
byte file[128]; |
81 |
byte opt_header[13]; |
82 |
byte options[299]; |
83 |
} DHCP_REQUEST; |
84 |
|
85 |
|
86 |
typedef struct { |
87 |
uint ip; |
88 |
uint netmask; |
89 |
uint gateway; |
90 |
char password[30]; |
91 |
byte dhcp_flag; |
92 |
} IP_PARAM; |
93 |
|
94 |
typedef struct { |
95 |
uint ip; |
96 |
byte mac[6]; |
97 |
char firmware[10]; |
98 |
char ir_firmware[10]; |
99 |
byte dhcp_flag; |
100 |
} DEVICE_ENTRY; |
101 |
|
102 |
|
103 |
|
104 |
#ifdef WIN32 |
105 |
WSAEVENT IrtLanEvent; |
106 |
#endif |
107 |
|
108 |
|
109 |
SOCKET snd_socket[32],rcv_socket; |
110 |
|
111 |
int open_sockets (uint ip[],int cnt); |
112 |
void new_devicequery (byte msg,uint srvadr,DHCP_REQUEST *req); |
113 |
void new_dhcpset (byte msg,uint srvadr,byte mac[],char password[],DHCP_REQUEST *req); |
114 |
void new_ipset (byte msg,uint srvadr,byte mac[],uint ip,uint nm,uint gw,char password[],DHCP_REQUEST *req); |
115 |
void SendQuery (uint ips[],int cnt); |
116 |
int ReadDevices (DEVICE_ENTRY *dev,int cnt); |
117 |
int StoreDevice (DEVICE_ENTRY *dev,DHCP_REQUEST *req); |
118 |
void read_ip_parameter (IP_PARAM *ip); |
119 |
void SetIP (uint ips[],int cnt,DEVICE_ENTRY *dev,IP_PARAM *ip); |
120 |
int GetOwnIP (uint ips[]); |
121 |
int GetInterfaces (uint ips[]); |
122 |
|
123 |
|
124 |
int main (int argc,char *argv[]) |
125 |
|
126 |
{ |
127 |
int res,i,choice; |
128 |
char nm[100]; |
129 |
struct in_addr iadr; |
130 |
IP_PARAM ip; |
131 |
DEVICE_ENTRY irtrans[256]; |
132 |
int device_count; |
133 |
uint ip_adr[32]; |
134 |
int ip_count = 0; |
135 |
|
136 |
|
137 |
#ifdef WIN32 |
138 |
int err; |
139 |
WORD wVersionRequired; |
140 |
WSADATA wsaData; |
141 |
wVersionRequired = MAKEWORD(2,2); |
142 |
err = WSAStartup(wVersionRequired, &wsaData); |
143 |
if (err != 0) return (1); |
144 |
#endif |
145 |
|
146 |
argc++; |
147 |
for (;--argc > 2;argv++) { // Process all Command Line Arguments |
148 |
if (!strcmp (argv[1],"-interface")) { |
149 |
argc--; |
150 |
argv++; |
151 |
ip_adr[0] = inet_addr (argv[1]); |
152 |
ip_count = 1; |
153 |
continue; |
154 |
} |
155 |
|
156 |
} |
157 |
|
158 |
|
159 |
if (!ip_count) { |
160 |
ip_count = GetOwnIP (ip_adr); |
161 |
} |
162 |
|
163 |
for (i=0;i < ip_count;i++) { |
164 |
iadr.s_addr = ip_adr[i]; |
165 |
if (!i) printf ("\nOwn Interfaces / IPs: %s\n",inet_ntoa(iadr)); |
166 |
else printf (" %s\n",inet_ntoa(iadr)); |
167 |
} |
168 |
|
169 |
printf ("\n"); |
170 |
res = open_sockets (ip_adr,ip_count); |
171 |
|
172 |
|
173 |
if (res) { |
174 |
printf ("Open socket error: %d [%d]\n",res,errno); |
175 |
perror (NULL); |
176 |
exit (-1); |
177 |
} |
178 |
|
179 |
while (1) { |
180 |
SendQuery (ip_adr,ip_count); |
181 |
|
182 |
memset (irtrans,0,sizeof (irtrans)); |
183 |
device_count = ReadDevices (irtrans,ip_count); |
184 |
|
185 |
if (!device_count) { |
186 |
printf ("No IRTrans Ethernet device(s) found\n"); |
187 |
exit (0); |
188 |
} |
189 |
|
190 |
|
191 |
printf ("\n%2d IRTrans Ethernet device(s) found:\n",device_count); |
192 |
printf ("----------------------------------------------------------------\n"); |
193 |
|
194 |
for (i=0;i < device_count;i++) { |
195 |
iadr.s_addr = irtrans[i].ip; |
196 |
|
197 |
if (irtrans[i].dhcp_flag == 1) strcpy (nm,"DHCP"); |
198 |
else nm[0] = 0; |
199 |
printf ("%2d %02x-%02x-%02x-%02x-%02x-%02x %-15s %s %8s %s\n",i+1,irtrans[i].mac[0],irtrans[i].mac[1],irtrans[i].mac[2], |
200 |
irtrans[i].mac[3],irtrans[i].mac[4],irtrans[i].mac[5],inet_ntoa(iadr),irtrans[i].firmware,irtrans[i].ir_firmware,nm); |
201 |
} |
202 |
printf ("----------------------------------------------------------------\n"); |
203 |
|
204 |
|
205 |
printf ("Please select device to use (0 = Exit) "); |
206 |
fflush (stdout); |
207 |
do { |
208 |
fgets (nm,sizeof (nm),stdin); |
209 |
choice = atoi (nm); |
210 |
} while (nm[0] < '0'); |
211 |
|
212 |
if (!choice) exit (0); |
213 |
|
214 |
read_ip_parameter (&ip); |
215 |
|
216 |
SetIP (ip_adr,ip_count,irtrans + choice-1,&ip); |
217 |
} |
218 |
|
219 |
|
220 |
return (0); |
221 |
} |
222 |
|
223 |
|
224 |
int GetOwnIP (uint ips[]) |
225 |
{ |
226 |
char nm[100]; |
227 |
int count = 0; |
228 |
|
229 |
#ifdef WIN32 |
230 |
struct hostent *host; |
231 |
|
232 |
gethostname (nm,100); |
233 |
|
234 |
host = gethostbyname (nm); |
235 |
|
236 |
while (host->h_addr_list[count]) { |
237 |
if (host->h_addr_list[count][0] != 127) break; |
238 |
} |
239 |
ips[0] = *((uint *)host->h_addr_list[count]); |
240 |
count = 1; |
241 |
#else |
242 |
count = GetInterfaces (ips); |
243 |
#endif |
244 |
return (count); |
245 |
} |
246 |
|
247 |
|
248 |
#ifndef WIN32 |
249 |
int GetInterfaces (uint ips[]) |
250 |
{ |
251 |
int i,j,cnt; |
252 |
FILE *fp; |
253 |
char *pnt,ln[256]; |
254 |
struct sockaddr_in *sinp; |
255 |
struct ifreq ifr; |
256 |
int s; /* Socket */ |
257 |
char local_ip_addr[16]; |
258 |
|
259 |
fp = fopen ("/proc/net/dev","r"); |
260 |
if (!fp) return (0); |
261 |
s = socket(AF_INET, SOCK_DGRAM, 0); |
262 |
|
263 |
cnt = 0; |
264 |
pnt = fgets (ln,sizeof (ln),fp); |
265 |
while (pnt) { |
266 |
i = 0; |
267 |
while (ln[i] == ' ') i++; |
268 |
if (!memcmp (ln+i,"eth",3)) { |
269 |
j = i; |
270 |
while ((ln[j] >= '0' && ln[j] <= '9') || (ln[j] >= 'a' && ln[j] <= 'z') || (ln[j] >= 'A' && ln[j] <= 'Z')) j++; |
271 |
ln[j] = 0; |
272 |
memset (&ifr,0,sizeof (ifr)); |
273 |
strcpy(ifr.ifr_name, ln+i); |
274 |
ioctl(s, SIOCGIFADDR, &ifr); |
275 |
sinp = (struct sockaddr_in*)&ifr.ifr_addr; |
276 |
ips[cnt++] = sinp->sin_addr.s_addr; |
277 |
} |
278 |
pnt = fgets (ln,sizeof (ln),fp); |
279 |
} |
280 |
|
281 |
close (s); |
282 |
fclose (fp); |
283 |
|
284 |
return (cnt); |
285 |
} |
286 |
#endif |
287 |
|
288 |
|
289 |
void SetIP (uint server_ip[],int cnt,DEVICE_ENTRY *dev,IP_PARAM *ip) |
290 |
{ |
291 |
int i; |
292 |
DHCP_REQUEST req; |
293 |
|
294 |
for (i=0;i < cnt;i++) { |
295 |
if (ip->dhcp_flag) new_dhcpset (190,server_ip[i],dev->mac,ip->password,&req); |
296 |
|
297 |
else new_ipset (189,server_ip[i],dev->mac,ip->ip,ip->netmask,ip->gateway,ip->password,&req); |
298 |
|
299 |
send (snd_socket[i],(char *)&req,sizeof (DHCP_REQUEST),0); |
300 |
} |
301 |
} |
302 |
|
303 |
void read_ip_parameter (IP_PARAM *ip) |
304 |
{ |
305 |
char nm[100]; |
306 |
|
307 |
memset (ip,0,sizeof (IP_PARAM)); |
308 |
|
309 |
printf ("\n\nConfigure device for DHCP (Y/N) ? "); |
310 |
fflush (stdout); |
311 |
fgets (nm,sizeof (nm),stdin); |
312 |
printf ("\n"); |
313 |
|
314 |
if (*nm == 'Y' || *nm == 'y') ip->dhcp_flag = 1; |
315 |
else { |
316 |
do { |
317 |
printf ("\nEnter IP Address: "); |
318 |
fflush (stdout); |
319 |
fgets (nm,sizeof (nm),stdin); |
320 |
ip->ip = inet_addr (nm); |
321 |
} while (ip->ip == INADDR_NONE); |
322 |
do { |
323 |
printf ("\nEnter Netmask : "); |
324 |
fflush (stdout); |
325 |
fgets (nm,sizeof (nm),stdin); |
326 |
ip->netmask = inet_addr (nm); |
327 |
} while (ip->netmask == INADDR_NONE); |
328 |
do { |
329 |
printf ("\nDefault Gateway : "); |
330 |
fflush (stdout); |
331 |
fgets (nm,sizeof (nm),stdin); |
332 |
ip->gateway = inet_addr (nm); |
333 |
} while (ip->gateway == INADDR_NONE); |
334 |
} |
335 |
|
336 |
printf ("\n\nEnter device password: "); |
337 |
fflush (stdout); |
338 |
fgets (ip->password,8,stdin); |
339 |
|
340 |
printf ("\n"); |
341 |
} |
342 |
|
343 |
void SendQuery (uint ip_adr[],int cnt) |
344 |
{ |
345 |
int i; |
346 |
DHCP_REQUEST req; |
347 |
|
348 |
for (i=0;i < cnt;i++) { |
349 |
new_devicequery (187,ip_adr[i],&req); |
350 |
send (snd_socket[i],(char *)&req,sizeof (DHCP_REQUEST),0); |
351 |
} |
352 |
} |
353 |
|
354 |
|
355 |
int ReadDevices (DEVICE_ENTRY *dev,int ipcnt) |
356 |
{ |
357 |
int i; |
358 |
DHCP_REQUEST req; |
359 |
int res,cnt = 0; |
360 |
|
361 |
#ifndef WIN32 |
362 |
fd_set events; |
363 |
int maxfd,wait; |
364 |
struct timeval tv; |
365 |
#endif |
366 |
|
367 |
#ifdef WIN32 |
368 |
IrtLanEvent = WSACreateEvent (); |
369 |
WSAEventSelect (rcv_socket, IrtLanEvent,FD_READ); |
370 |
#endif |
371 |
|
372 |
while (1) { |
373 |
|
374 |
#ifdef WIN32 |
375 |
res = WaitForSingleObject (IrtLanEvent,5000); |
376 |
if (res == WAIT_TIMEOUT) break; |
377 |
ResetEvent (IrtLanEvent); |
378 |
|
379 |
#else |
380 |
|
381 |
FD_ZERO (&events); |
382 |
|
383 |
FD_SET (rcv_socket,&events); |
384 |
maxfd = rcv_socket + 1; |
385 |
|
386 |
tv.tv_sec = 1; |
387 |
tv.tv_usec = 0; |
388 |
|
389 |
wait = select (maxfd,&events,NULL,NULL,&tv); |
390 |
if (!wait) break; |
391 |
#endif |
392 |
res = recv (rcv_socket,(char *)&req,sizeof (req),0); |
393 |
cnt += StoreDevice (dev + cnt,&req); |
394 |
i = 0; |
395 |
while (i < (cnt - 1)) { |
396 |
if (!memcmp (dev[i].mac,dev[cnt-1].mac,6)) break; |
397 |
i++; |
398 |
} |
399 |
if (i < (cnt - 1)) cnt--; |
400 |
|
401 |
} |
402 |
return (cnt); |
403 |
} |
404 |
|
405 |
|
406 |
int StoreDevice (DEVICE_ENTRY *dev,DHCP_REQUEST *req) |
407 |
{ |
408 |
if (req -> op != 1) return (0); |
409 |
|
410 |
if (req -> opt_header[0] != 99 || req -> opt_header[1] != 130 || req -> opt_header[2] != 83 || req -> opt_header[3] != 99) return (0); |
411 |
if (req -> opt_header[4] != 53 || req -> opt_header[5] != 1 || req -> opt_header[6] != 188 || req -> opt_header[7] != 0xe9) return (0); |
412 |
|
413 |
if (req -> opt_header[9] != 0x78 || req -> opt_header[10] != 0xa3 || req -> opt_header[11] != 0x8b || req -> opt_header[12] != 0x84) return (0); |
414 |
|
415 |
|
416 |
if (req -> client_mac[0] != 0 || req -> client_mac[1] != 0x50 || req -> client_mac[2] != 0xC2 || |
417 |
req -> client_mac[3] != 0x52 || (req -> client_mac[4] & 0xf0) != 0x70) return (0); |
418 |
|
419 |
|
420 |
dev->ip = req -> client_ip; |
421 |
memcpy (dev->mac,req -> client_mac,6); |
422 |
dev->dhcp_flag = req->options[0]; |
423 |
memcpy (dev->firmware,req->options+1,8); |
424 |
if (req -> opt_header[8] == 23) memcpy (dev->ir_firmware,req->options+9,8); |
425 |
|
426 |
return (1); |
427 |
} |
428 |
|
429 |
|
430 |
void new_dhcpset (byte msg,uint srvadr,byte mac[],char password[],DHCP_REQUEST *req) |
431 |
{ |
432 |
int i,pos; |
433 |
|
434 |
memset (req,0,sizeof (DHCP_REQUEST)); |
435 |
|
436 |
req->op = 2; |
437 |
req->htype = 1; |
438 |
req->hlen = 6; |
439 |
req->hops = 0; |
440 |
req->xid = htonl(0xaabbccdd); |
441 |
req->secs = 0; |
442 |
req->flags = htons (0x8000); |
443 |
req->server_ip = srvadr; |
444 |
memcpy (req->client_mac,mac,6); |
445 |
|
446 |
req->opt_header[0] = 99; |
447 |
req->opt_header[1] = 130; |
448 |
req->opt_header[2] = 83; |
449 |
req->opt_header[3] = 99; |
450 |
req->opt_header[4] = 53; |
451 |
req->opt_header[5] = 1; |
452 |
req->opt_header[6] = msg; |
453 |
req->opt_header[7] = 233; |
454 |
req->opt_header[8] = 4; |
455 |
req->opt_header[9] = 0xac; |
456 |
req->opt_header[10] = 0x75; |
457 |
req->opt_header[11] = 0x20; |
458 |
req->opt_header[12] = 0xbf; |
459 |
|
460 |
pos = 0; |
461 |
req->options[pos++] = 234; |
462 |
req->options[pos++] = strlen (password) + 1; |
463 |
|
464 |
for (i=0;i < (int)strlen (password);i++) req->options[pos++] = password[i]; |
465 |
req->options[pos++] = 0; |
466 |
req->options[pos++] = 255; |
467 |
} |
468 |
|
469 |
void new_ipset (byte msg,uint srvadr,byte mac[],uint ip,uint nm,uint gw,char password[],DHCP_REQUEST *req) |
470 |
{ |
471 |
int i,pos; |
472 |
|
473 |
memset (req,0,sizeof (DHCP_REQUEST)); |
474 |
|
475 |
req->op = 2; |
476 |
req->htype = 1; |
477 |
req->hlen = 6; |
478 |
req->hops = 0; |
479 |
req->xid = htonl(0xaabbccdd); |
480 |
req->secs = 0; |
481 |
req->flags = htons (0x8000); |
482 |
req->server_ip = srvadr; |
483 |
req->own_ip = ip; |
484 |
memcpy (req->client_mac,mac,6); |
485 |
|
486 |
req->opt_header[0] = 99; |
487 |
req->opt_header[1] = 130; |
488 |
req->opt_header[2] = 83; |
489 |
req->opt_header[3] = 99; |
490 |
req->opt_header[4] = 53; |
491 |
req->opt_header[5] = 1; |
492 |
req->opt_header[6] = msg; |
493 |
req->opt_header[7] = 233; |
494 |
req->opt_header[8] = 4; |
495 |
req->opt_header[9] = 0xac; |
496 |
req->opt_header[10] = 0x75; |
497 |
req->opt_header[11] = 0x20; |
498 |
req->opt_header[12] = 0xbf; |
499 |
|
500 |
pos = 0; |
501 |
req->options[pos++] = 1; // Subnetmask |
502 |
req->options[pos++] = 4; |
503 |
memcpy (req->options+pos,&nm,4); |
504 |
pos += 4; |
505 |
|
506 |
req->options[pos++] = 3; // Default Gateway |
507 |
req->options[pos++] = 4; |
508 |
memcpy (req->options+pos,&gw,4); |
509 |
pos += 4; |
510 |
|
511 |
req->options[pos++] = 234; |
512 |
req->options[pos++] = strlen (password) + 1; |
513 |
|
514 |
for (i=0;i < (int)strlen (password);i++) req->options[pos++] = password[i]; |
515 |
req->options[pos++] = 0; |
516 |
req->options[pos++] = 255; |
517 |
|
518 |
} |
519 |
|
520 |
void new_devicequery (byte msg,uint srvadr,DHCP_REQUEST *req) |
521 |
{ |
522 |
memset (req,0,sizeof (DHCP_REQUEST)); |
523 |
|
524 |
req->op = 2; |
525 |
req->htype = 1; |
526 |
req->hlen = 6; |
527 |
req->hops = 0; |
528 |
req->xid = htonl(0xaabbccdd); |
529 |
req->secs = 0; |
530 |
req->flags = htons (0x8000); |
531 |
req->server_ip = srvadr; |
532 |
req->client_mac[0] = 0xff; |
533 |
req->client_mac[1] = 0xff; |
534 |
req->client_mac[2] = 0xff; |
535 |
req->client_mac[3] = 0xff; |
536 |
req->client_mac[4] = 0xff; |
537 |
req->client_mac[5] = 0xff; |
538 |
|
539 |
req->opt_header[0] = 99; |
540 |
req->opt_header[1] = 130; |
541 |
req->opt_header[2] = 83; |
542 |
req->opt_header[3] = 99; |
543 |
req->opt_header[4] = 53; |
544 |
req->opt_header[5] = 1; |
545 |
req->opt_header[6] = msg; |
546 |
req->opt_header[7] = 233; |
547 |
req->opt_header[8] = 4; |
548 |
req->opt_header[9] = 0x78; |
549 |
req->opt_header[10] = 0xa3; |
550 |
req->opt_header[11] = 0x8b; |
551 |
req->opt_header[12] = 0x84; |
552 |
|
553 |
req->options[0] = 255; |
554 |
} |
555 |
|
556 |
int open_sockets (uint ip[],int cnt) |
557 |
{ |
558 |
int res,i; |
559 |
struct sockaddr_in iadr; |
560 |
struct sockaddr_in serv_addr; |
561 |
|
562 |
rcv_socket = socket (PF_INET,SOCK_DGRAM,0); |
563 |
if (rcv_socket < 0) return (2); |
564 |
|
565 |
memset (&serv_addr,0,sizeof (serv_addr)); |
566 |
serv_addr.sin_family = AF_INET; |
567 |
serv_addr.sin_addr.s_addr = INADDR_ANY; |
568 |
serv_addr.sin_port = htons (67); |
569 |
|
570 |
res = bind (rcv_socket,(struct sockaddr *)&serv_addr,sizeof (serv_addr)); |
571 |
if (res) return (3); |
572 |
|
573 |
|
574 |
for (i=0;i < cnt;i++) { |
575 |
snd_socket[i] = socket (PF_INET,SOCK_DGRAM,0); |
576 |
if (snd_socket[i] < 0) return (4); |
577 |
res = 1; |
578 |
setsockopt (snd_socket[i],SOL_SOCKET,SO_BROADCAST,(char *)&res,sizeof (int)); |
579 |
|
580 |
|
581 |
#ifndef WIN32 |
582 |
memset (&serv_addr,0,sizeof (serv_addr)); |
583 |
serv_addr.sin_family = AF_INET; |
584 |
serv_addr.sin_addr.s_addr = ip[i]; |
585 |
serv_addr.sin_port = 0; |
586 |
|
587 |
res = bind (snd_socket[i],(struct sockaddr *)&serv_addr,sizeof (serv_addr)); |
588 |
if (res) return (6); |
589 |
#endif |
590 |
|
591 |
memset (&iadr,0,sizeof (struct sockaddr)); |
592 |
iadr.sin_family = AF_INET; |
593 |
iadr.sin_addr.s_addr = INADDR_BROADCAST; |
594 |
iadr.sin_port = htons (68); |
595 |
|
596 |
if (connect (snd_socket[i],(struct sockaddr *)&iadr,sizeof (struct sockaddr_in)) < 0) return (5); |
597 |
} |
598 |
|
599 |
return (0); |
600 |
} |
601 |
|