discover |
Subversion Repositories: |
Rev 4 | Rev 5 | |
---|---|---|
Line 27... | Line 27... | |
|
| |
struct udisc_rec_hdr { |
struct udisc_rec_hdr { | |
uint8_t type; |
uint8_t type; | |
uint16_t length; |
uint16_t length; | |
} __attribute__((packed)); |
} __attribute__((packed)); | |
| ||
struct cache_entry { | ||
unsigned long s_addr; | ||
unsigned short s_port; | ||
}; | ||
| ||
#define MAXENTRIES 1024 | ||
struct cache_entry cache[MAXENTRIES]; | ||
size_t cachep; | ||
| ||
int add_cache(unsigned long s_addr, unsigned short s_port) | ||
{ | ||
if (cachep == 1024) | ||
return 0; | ||
| ||
cache[cachep].s_addr = s_addr; | ||
cache[cachep].s_port = s_port; | ||
cachep++; | ||
| ||
return 1; | ||
} | ||
| ||
int lookup_cache(unsigned long s_addr, unsigned short s_port) | ||
{ | ||
int i; | ||
| ||
for (i = 0; i <= cachep; i++) | ||
if (cache[i].s_addr == s_addr && cache[i].s_port == s_port) | ||
return 1; | ||
return 0; | ||
} | ||
|
| |
int main(int argc, char *argv[]) |
int main(int argc, char *argv[]) | |
{ |
{ | |
|
| |
struct sockaddr_in si_srv; |
struct sockaddr_in si_srv; | |
Line 157... | Line 188... | |
|
| |
if (ntohs(si_srv.sin_port) != UBNT_PORT) |
if (ntohs(si_srv.sin_port) != UBNT_PORT) | |
continue; |
continue; | |
|
| |
responses++; |
responses++; | |
| ||
if (!lookup_cache(si_srv.sin_addr.s_addr, si_srv.sin_port)) { | ||
if (!add_cache(si_srv.sin_addr.s_addr, si_srv.sin_port)) { | ||
fprintf(stderr, "too many unique responses\n"); | ||
exit(1); | ||
} | ||
} else { | ||
continue; | ||
} | ||
|
| |
printf("\n"); |
printf("\n"); | |
printf("Response : %s:%d\n", inet_ntoa(si_srv.sin_addr), ntohs(si_srv.sin_port)); |
printf("Response : %s:%d\n", inet_ntoa(si_srv.sin_addr), ntohs(si_srv.sin_port)); | |
|
| |
p = rcvbuf; |
p = rcvbuf; |