summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåkon Nessjøen <haakon.nessjoen@gmail.com>2010-11-28 23:31:13 +0100
committerHåkon Nessjøen <haakon.nessjoen@gmail.com>2010-11-28 23:32:19 +0100
commit59525a228a1ebf2aca46d5be63f8280b274a490a (patch)
treee3dd38376506985026b1aec0ad8c228d2ada9720
parent3f669049e77b87cca9168fbd55838bd679b573c4 (diff)
downloadMAC-Telnet-autointerface.tar.gz
MAC-Telnet-autointerface.zip
Added a little documentation in the source codeautointerface
-rw-r--r--mactelnet.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/mactelnet.c b/mactelnet.c
index 7f60712..387ecb6 100644
--- a/mactelnet.c
+++ b/mactelnet.c
@@ -257,7 +257,7 @@ int findInterface() {
/* Initialize receiving socket on the device chosen */
myip.sin_port = htons(sourceport);
- /* Bind to udp port */
+ /* Initialize socket and bind to udp port */
if ((testsocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
continue;
}
@@ -270,12 +270,16 @@ int findInterface() {
continue;
}
+ /* Find the mac address for the current device */
if (getDeviceMAC(testsocket, devicename, srcmac) < 0) {
close(testsocket);
continue;
}
+ /* Set the global socket handle for sendUDP() */
sendSocket = testsocket;
+
+ /* Send a SESSIONSTART message with the current device */
initPacket(&data, MT_PTYPE_SESSIONSTART, srcmac, dstmac, sessionkey, 0);
sendUDP(&data);
@@ -286,12 +290,14 @@ int findInterface() {
FD_SET(insockfd, &read_fds);
select(insockfd + 1, &read_fds, NULL, NULL, &timeout);
if (FD_ISSET(insockfd, &read_fds)) {
+ /* We got a response, this is the correct device to use */
return 1;
}
close(testsocket);
}
+ /* We didn't find anything */
return 0;
}