-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec_router.c
More file actions
740 lines (609 loc) · 23 KB
/
vec_router.c
File metadata and controls
740 lines (609 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
#include "vec_router.h"
#define DEBUG
//cost Table and route table?
// no need cost table, because never used ??
// need neighbor nexthop to be transmitted. I won't update dis vec that route from me
/* Section
variables used for dis_vec routing
*/
//cost table
int costTable[256];
int takeASleep = 0;
// if it is neighbor
int IsNeighbor[256];
//costs to each neighbor
int globalCost[256];
/*
Linkstate:
actually linkstate is just the network order of the globalCost
constantly send dis_vec to neighbors, its size is 4 bytes * 256= 1024 bytes
*/
int32_t linkState[256];
// next hops for each IP
int nexthops[256];
/*
END Section
*/
//myself's ID
int globalMyID = 0;
//last time you heard from each node.
struct timeval globalLastHeartbeat[256];
struct timeval lastChangedTime[256];
struct timeval lastChangeTime;
//UDP socket, to be bound to 10.1.1.globalMyID, port 7777
int globalSocketUDP;
//addresses sending to 10.1.1.0 - 255, port 7777
struct sockaddr_in globalNodeAddrs[256];
char logbuffer[BUFFERSIZE];
int stopBeforeStable = 0;
FILE* logfile;
/* Function
debug print
*/
void debug_print(const char *msg){
#ifdef DEBUG
printf("%s\n",msg);
#endif
}
void print_cost_table(){
sprintf(logbuffer,"COSTTABLE at %d:",globalMyID);
debug_print(logbuffer);
for(int i=0;i<256;i++){
if(globalCost[i] != -1){
sprintf(logbuffer,"TO %d is %d,next %d",i,globalCost[i],nexthops[i]);
debug_print(logbuffer);
}
}
debug_print("");
}
/*
Function: min of 2 int
*/
int min2(int a,int b){
if(a<b) return a;
return b;
}
/* Fucntion
broad to only my neighbor
buf:content, length:buf size
*/
void broadToNeighbor(const void* buf, int length){
int i;
for( i=0 ; i<256 ; i++){
if(IsNeighbor[i] == 1 && i != globalMyID){
sendto(globalSocketUDP, buf,length,0,
(struct sockaddr*)&globalNodeAddrs[i], sizeof(globalNodeAddrs[1]));
}
}
}
/* Fucntion
broadcast to all IP
Using this to send linkstate as heartbeat
buf:linkstate, length:buf size
*/
void hackyBroadcast(const void* buf, int length,int target)
{
// int i;
// for(i=0;i<256;i++)
if(target != globalMyID) //(although with a real broadcast you would also get the packet yourself)
{
sendto(globalSocketUDP, buf, length, 0,
(struct sockaddr*)&globalNodeAddrs[target], sizeof(globalNodeAddrs[target]));
}
}
/*
Function
If nexthop is i, then the link don't tell i
*/
void broadCastGrained(){
for(int target = 0; target<256;target++){
if(target == globalMyID){
continue;
}
int32_t tmpLinkState[256];
for(int i=0;i<256;i++){
if(nexthops[i] == target){
tmpLinkState[i] = htonl(-1);
}
else{
tmpLinkState[i] = linkState[i];
}
}
hackyBroadcast(tmpLinkState,BUFFERSIZE,target);
}
}
/*
Function:
Check if a node is alive,
if last heartbeats more than 2RTT(something larger than 600), deeded as dead
*/
void checkAlive(){
struct timeval timeInterval;
gettimeofday(&timeInterval,0);
int i;
char logLine[80];
for(i=0;i<256;i++){
// check if a link between myself and neighbor is down
if(IsNeighbor[i]==1){
double elapsedTime = (timeInterval.tv_sec - globalLastHeartbeat[i].tv_sec) * 1000;
if(elapsedTime > 1500){ // if larger than 2 sleeping time, then something wrong, it is dead
sprintf(logbuffer," Node %d find node %d died after %lf!",globalMyID, i,elapsedTime);
debug_print(logbuffer);
costTable[i] = -1;
for(int j=0;j<256;j++){
if(j == globalMyID ) continue;
//All nodes route through i fails, change link state j
if(nexthops[j] == i){
nexthops[j] = j;
globalCost[j] = costTable[j];
linkState[j] = htonl(globalCost[j]);
}
}
print_cost_table();
IsNeighbor[i]=0;
//tell neighbors this link dead
broadCastGrained();
// hackyBroadcast(linkState, BUFFERSIZE);
}
}
}
}
void my_sleep(int time){
struct timespec sleepFor;
sleepFor.tv_sec = 0;
sleepFor.tv_nsec = time * 1000 * 1000;
nanosleep(&sleepFor, 0);
}
/*
Function:
Annoce to neighbor the dis_vec every 300ms
Also check neighbor's aliveness
*/
void* announceToNeighbors(void* params)
{
struct timespec sleepFor;
sleepFor.tv_sec = 0;
sleepFor.tv_nsec = 100 * 1000 * 1000; //100 ms
while(1)
{
if(takeASleep){
my_sleep(200);
}
checkAlive();
broadCastGrained();
// hackyBroadcast(linkState, BUFFERSIZE);
nanosleep(&sleepFor, 0);
}
}
/*
Function:
checkAlive every 300 ms
*/
void* checkAliveNeighbors(void* params)
{
struct timespec sleepFor;
sleepFor.tv_sec = 0;
sleepFor.tv_nsec = 300 * 1000 * 1000; //300 ms
while(1)
{
checkAlive();
nanosleep(&sleepFor, 0);
}
}
void listenForNeighbors()
{
char fromAddr[100];
struct sockaddr_in theirAddr;
socklen_t theirAddrLen;
//recvd info
unsigned char recvBuf[BUFFERSIZE];
//line for logfile
char tmpLine[BUFFERSIZE];
while(1)
{
theirAddrLen = sizeof(theirAddr);
memset(&recvBuf[0],0,sizeof(recvBuf));
int numbytes;
if ((numbytes = recvfrom(globalSocketUDP, recvBuf, BUFFERSIZE , 0,
(struct sockaddr*)&theirAddr, &theirAddrLen)) == -1)
{
perror("recvfrom:");
exit(1);
}
recvBuf[numbytes] = '\0';
inet_ntop(AF_INET, &theirAddr.sin_addr, fromAddr, 100);
short int heardFrom = -1;
int somethingChanged = 0;
// if messageh is our format, receive it or forward it
if(!strncmp(recvBuf,"dnes",4)){
int length;
// because message <= 100 bits, and there are 6bits header, so it will not exceed 106 bits, plus one '\0'
char message[BUFFERSIZE];
char payLoad[BUFFERSIZE];
short int networkDestID;
memcpy(&networkDestID, &recvBuf[4],2);
// network to host destID
short int hostDestID = ntohs(networkDestID);
// sprintf(logbuffer,"message dst host id is %hu\n", hostDestID);
// debug_print(logbuffer);
strcpy(payLoad, &recvBuf[6]);
if(globalMyID == hostDestID){
sprintf(logbuffer,"%d receiving message",globalMyID);
debug_print(logbuffer);
sprintf(tmpLine, "receive packet message %s\n", payLoad);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
}
else{
if(globalCost[hostDestID] == -1) {
debug_print("cost -1 unreachable\n");
sprintf(tmpLine, "unreachable dest %d\n", hostDestID);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
}
else{
// check if forward successfully
int payLoadSize = strlen(payLoad);
// sprintf(logbuffer,"payload size is %d",payLoadSize);
debug_print(logbuffer);
//TODO: is something wrong here?
if(sendto(globalSocketUDP, recvBuf, payLoadSize+6, 0,
(struct sockaddr*)&globalNodeAddrs[nexthops[hostDestID]], sizeof(globalNodeAddrs[nexthops[hostDestID]])) < 0){
perror("sendto()");
debug_print("send fail unreachable\n");
sprintf(tmpLine, "unreachable dest %d\n", hostDestID);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
}
else{
sprintf(tmpLine, "forward packet dest %d nexthop %d message %s\n", hostDestID, nexthops[hostDestID],payLoad);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
sprintf(logbuffer, "%d forward packet dest %d nexthop %d,cost is %d, message %s\n",globalMyID, hostDestID, nexthops[hostDestID],globalCost[hostDestID], payLoad);
debug_print(tmpLine);
}
}
}
}
// packet from manager, reassemble packet to our format
else if(!strncmp(recvBuf, "send", 4))
{
int length;
// because message <= 100 bits, and there are 6bits header, so it will not exceed 106 bits, plus one '\0'
char message[BUFFERSIZE];
char payLoad[BUFFERSIZE];
short int networkDestID;
memcpy(&networkDestID, &recvBuf[4],2);
// network to host destID
short int hostDestID = ntohs(networkDestID);
//print payload to logfile
strcpy(payLoad, &recvBuf[6]);
//copy payload into message
// write unreachable if cost == -1
if(globalCost[hostDestID] == -1) {
debug_print("cost -1 unreachable");
sprintf(tmpLine, "unreachable dest %d\n", hostDestID);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
}
else{
// fowward, write send first to the newly constructed packet
strcpy(message,"dnes");
// write network order destID back to message
// begins at 4 because send takes 4 bits
memcpy(&message[4], &networkDestID, sizeof(short int));
strcpy(&message[6],payLoad);
int payLoadSize = strlen(payLoad);
// sprintf(logbuffer,"payload size is %d",payLoadSize);
// check if forward successfully
if(sendto(globalSocketUDP, message, payLoadSize+6, 0,
(struct sockaddr*)&globalNodeAddrs[nexthops[hostDestID]], sizeof(globalNodeAddrs[nexthops[hostDestID]])) < 0){
perror("sendto()");
debug_print("send fail unreachable");
sprintf(tmpLine, "unreachable dest %d\n", hostDestID);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
debug_print("sending translated message failed");
}
// if reachable
else{
sprintf(tmpLine, "sending packet dest %d nexthop %d message %s\n", hostDestID, nexthops[hostDestID], payLoad);
fwrite(tmpLine, 1, strlen(tmpLine), logfile);
sprintf(logbuffer,"At %d,sending packet dest %d nexthop %d cost %d ",globalMyID,hostDestID,nexthops[hostDestID],globalCost[hostDestID]);
debug_print(logbuffer);
}
}
}
// sent from manager, cost, destID and newCost. Need to send dst to change cost
else if(!strncmp(recvBuf, "cost", 4))
{
//parse dstID and newCost
short int networkNeighborID;
memcpy(&networkNeighborID,&recvBuf[4],2);
short int hostNeighborId = ntohs(networkNeighborID);
int networkCost;
memcpy(&networkCost,&recvBuf[6],4);
int hostCost = ntohl(networkCost);
costTable[hostNeighborId] = hostCost;
sprintf(logbuffer,"at %d Manager says cost to %hu is %d\n", globalMyID,hostNeighborId,hostCost);
debug_print(logbuffer);
globalCost[hostNeighborId] = hostCost;
// update dis_vec. using network order cost
linkState[hostNeighborId] = networkCost;
somethingChanged = 1;
//prepare for new cost sending
char message[BUFFERSIZE];
//send new cost to neighbor
// strcpy(message,"ncos");
// int myNetId = htons(globalMyID);
// memcpy(&recvBuf[4],&myNetId,2);
// memcpy(&recvBuf[6],&networkCost,4);
// if(sendto(globalSocketUDP, message, 10, 0,
// (struct sockaddr*)&globalNodeAddrs[hostNeighborId], sizeof(globalNodeAddrs[hostNeighborId])) < 0){
// perror("sendto()");
// }
// else{
// sprintf(logbuffer,"at %d sends new cost %d to neighbor %d\n", globalMyID,hostCost,hostNeighborId);
// debug_print(logbuffer);
// }
}
// //receive new cost
// else if(!strncmp(recvBuf, "ncos", 4))
// {
// //parse dstID and newCost
// short int networkNeighborID;
// memcpy(&networkNeighborID,&recvBuf[4],2);
// short int hostNeighborId = ntohs(networkNeighborID);
// int networkCost;
// memcpy(&networkCost,&recvBuf[6],4);
// int hostCost = ntohl(networkCost);
// costTable[hostNeighborId] = hostCost;
// char message[BUFFERSIZE];
// sprintf(logbuffer,"at %hd receiveis from %hd says cost to %d\n", globalMyID,hostNeighborId,hostCost);
// debug_print(logbuffer);
// globalCost[hostNeighborId] = hostCost;
// // update dis_vec. using network order cost
// linkState[hostNeighborId] = networkCost;
// somethingChanged = 1;
// }
// Received dis_vec from neighbor
else
{
heardFrom = atoi(strchr(strchr(strchr(fromAddr,'.')+1,'.')+1,'.')+1);
// sprintf(logbuffer, "dis_vec from %d",heardFrom);
// debug_print(logbuffer);
int i;
IsNeighbor[heardFrom] = 1;
//update cost from dis_vec, its now directly connected
if(costTable[heardFrom] == -1){
sprintf(logbuffer,"node %d find new direclty linked neighbor %d",globalMyID, heardFrom);
debug_print(logbuffer);
costTable[heardFrom] = 1;
globalCost[heardFrom] = 1;
nexthops[heardFrom] = heardFrom;
linkState[heardFrom] = htonl(globalCost[heardFrom]);
somethingChanged = 1;
}
// will the cost be something apart from 1??
// int costToMe;
// memcpy(&costToMe,&recvBuf[4*globalMyID],4);
// costToMe = ntohl(costToMe);
// //set up initial cost, if has neihbor, then default next hop is him
// if(costToMe != -1 && globalCost[heardFrom] == -1){
// sprintf(logbuffer,"At %d optimize neighbor cost according to thei said: %d to me is %d",globalMyID,heardFrom,costToMe);
// debug_print(logbuffer);
// globalCost[heardFrom] = costToMe;
// nexthops[heardFrom] = heardFrom;
// linkState[heardFrom] = htonl(globalCost[heardFrom]);
// somethingChanged = 1;
// }
// read each dis_vec send from heardFrom,
// linkstate is actually an edge so its their cost for pos i
for(i=0;i<256;i++){
//!! this is always 0, Not use this to route
if(i == heardFrom || i == globalMyID ){
continue;
}
int theirCostFori;
//extract cur dis_vec from recvbuf
memcpy(&theirCostFori,&recvBuf[4*i],4);
theirCostFori = ntohl(theirCostFori);
if(theirCostFori != -1){
sprintf(logbuffer,"%d receivve from %d to %d is %d",globalMyID,heardFrom,i,theirCostFori);
debug_print(logbuffer);
}
// Find some unreachable nodes can now be reached with heardFrom
if( globalCost[i] == -1 and theirCostFori != -1){
struct timeval timeInterval;
gettimeofday(&timeInterval,0);
double elapsedTime = (timeInterval.tv_sec - lastChangedTime[i].tv_sec) * 1000;
sprintf(logbuffer,"After %lf after last change\n",elapsedTime);
debug_print(logbuffer);
if(elapsedTime < 0.001){
my_sleep(5);
}
else{
sprintf(logbuffer,"At %d,%d said it to %d is %d",globalMyID,heardFrom,i,theirCostFori);
debug_print(logbuffer);
globalCost[i] = globalCost[heardFrom] + theirCostFori;
/*
If next hop fo heardFrom is HeardFrom, then to previous unreachable nodes shall go from heardFrome
Otherwise go from next hops to heardFrom
*/
if(nexthops[heardFrom] == heardFrom) nexthops[i] = heardFrom;
else nexthops[i] = nexthops[heardFrom];
somethingChanged = 1;
}
gettimeofday(&lastChangedTime[i],0);
}
/*
Route through this node
if there is a shorter path with the help of this nodes
this should not be else if, because it may be optimized
*/
if( theirCostFori != -1 and globalCost[i] != -1 and globalCost[i] > theirCostFori + globalCost[heardFrom]){
sprintf(logbuffer,"At %d,%d said it to %d is %d",globalMyID,heardFrom,i,theirCostFori);
debug_print(logbuffer);
globalCost[i] = theirCostFori + globalCost[heardFrom];
nexthops[i] = heardFrom;
somethingChanged = 1;
}
/*
For tie condition
LS: when choosing which node to move to the finished set next
if there is a tie, choose the lowest node ID
this situation only needs to update nexthops, dis_vec is no need to update
*/
if( theirCostFori != -1 and globalCost[i] != -1 and globalCost[i] == theirCostFori + globalCost[heardFrom] ){
nexthops[i] = min2(nexthops[i],heardFrom);
}
/*
This is for a link goes down, his neighbor report this.
Or link distance increase we need to find better path.
Because our nexthop goes through this node, then we shall cut off this link and refind new path
*/
// if(nexthops[i] == heardFrom && (theirCostFori+globalCost[heardFrom] > globalCost[i] || globalCost[i] == -1)){
if( nexthops[i] == heardFrom && globalCost[i] != -1 && (theirCostFori == -1 || theirCostFori+globalCost[heardFrom] > globalCost[i] ) ){
sprintf(logbuffer,"At %d, %d said its distance to %d changed to %d",globalMyID,heardFrom,i,theirCostFori);
debug_print(logbuffer);
globalCost[i] = costTable[i];
nexthops[i] = i;
somethingChanged = 1;
}
//update dis_vec
linkState[i] = htonl(globalCost[i]);
}
//record that we heard from heardFrom just now.
gettimeofday(&globalLastHeartbeat[heardFrom], 0);
}
if(somethingChanged){
struct timeval timeInterval;
gettimeofday(&timeInterval,0);
double elapsedTime = (timeInterval.tv_sec - lastChangeTime.tv_sec) * 1000;
if(elapsedTime < 1){
takeASleep = 1;
my_sleep(50);
takeASleep = 0;
}
sprintf(logbuffer,"elasepd %lf after last change\n",elapsedTime);
debug_print(logbuffer);
broadCastGrained();
// hackyBroadcast(linkState,BUFFERSIZE);
print_cost_table();
gettimeofday(&lastChangeTime, 0);
}
// debug_print("write flush");
//write to log file immediately
fflush(logfile);
}
//(should never reach here)
close(globalSocketUDP);
}
int main(int argc, char** argv)
{
if(argc != 4)
{
fprintf(stderr, "Usage: ./vec_router mynodeid initialcostsfile logfile\n");
exit(-1);
}
/*
Section:
Set up node's ID, record its time and setup sockaddr_in
*/
globalMyID = atoi(argv[1]);
int i;
for(i=0;i<256;i++)
{
gettimeofday(&globalLastHeartbeat[i], 0);
gettimeofday(&lastChangedTime[i], 0);
char tempaddr[100];
sprintf(tempaddr, "10.1.1.%d", i);
memset(&globalNodeAddrs[i], 0, sizeof(globalNodeAddrs[i]));
globalNodeAddrs[i].sin_family = AF_INET;
globalNodeAddrs[i].sin_port = htons(7777);
inet_pton(AF_INET, tempaddr, &globalNodeAddrs[i].sin_addr);
}
/* End Section */
gettimeofday(&lastChangeTime, 0);
/*
Section:
init cost and next hop,
parse cost file
setup log file
If you don't find an entry for a node, default to cost 1.
We will only use positive costs – never 0 or negative.
*/
//init
for(int i = 0; i < 256; i++)
{
IsNeighbor[i] = 0;
globalCost[i] = -1;
nexthops[i] = i;
costTable[i] = -1;
}
//set self cost to 0
// globalCost[globalMyID] = 0;
FILE* initialcostsfile = fopen(argv[2], "r");
if(initialcostsfile == NULL){
fprintf(stderr,"cannot open initial cost file\n");
exit(-1);
}
while (!feof(initialcostsfile)){
int nodeId, tmpCost;
fscanf(initialcostsfile, "%d", &nodeId);
fscanf(initialcostsfile, "%d", &tmpCost);
globalCost[nodeId] = tmpCost;
costTable[nodeId] = tmpCost;
//!! attention here node is not neighbor
// IsNeighbor[nodeId] = 1
}
fclose(initialcostsfile);
/*
Section:
Set Up dis_vec used for gossiping
*/
for(i=0;i<256;i++){
int networkglobalCost = htonl(globalCost[i]);
linkState[i] = networkglobalCost;
}
/* END Section */
if((logfile = fopen(argv[3], "w+")) == NULL){
fprintf(stderr,"not a valid logfile");
exit(-1);
}
logfile = fopen(argv[3], "w+");
/*
End Section for initcostfile paring
*/
/*
Section:
socket() and bind() for mysocket
// creating socket for myself and bind myself addr
*/
if((globalSocketUDP=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
perror("socket");
exit(1);
}
char myAddr[100];
struct sockaddr_in bindAddr;
sprintf(myAddr, "10.1.1.%d", globalMyID);
memset(&bindAddr, 0, sizeof(bindAddr));
bindAddr.sin_family = AF_INET;
bindAddr.sin_port = htons(7777);
inet_pton(AF_INET, myAddr, &bindAddr.sin_addr);
if(bind(globalSocketUDP, (struct sockaddr*)&bindAddr, sizeof(struct sockaddr_in)) < 0)
{
perror("bind");
close(globalSocketUDP);
exit(1);
}
/*
End Section for socket() and bind() for mysocket
*/
/* Section:
Start Threads and begin listenning:
*/
pthread_t announcerThread;
pthread_create(&announcerThread, 0, announceToNeighbors, (void*)0);
// pthread_t checkAliveThread;
// pthread_create(&checkAliveThread, 0, checkAliveNeighbors, (void*)0);
listenForNeighbors();
/*
End Section
*/
}