#include "opengatemmng.h"
-/************************************/
-/* arp form is reformed to ndp form */
-/* format macAddr for ndp or arp */
-/* match the form of two program */
-/* mac addr by arp 00:01:12:0b:.. */
-/* mac addr by ndp 0:1:12:b:.. */
-/************************************/
+/***************************************/
+/* arp form is reformed to arp form */
+/* mac addr by arp 00:01:12:0b:.. */
+/* mac addr by ndp 0:1:12:b:.. */
+/* these are formated to 00:01:12:0b:..*/
+/***************************************/
int reFormatMacAddr(char* macAddr)
{
int m1,m2,m3,m4,m5,m6;
return TRUE;
}
-/**********************************************************************/
-/* get MAC address for clientAddr (nnnn:nnnn::nnnn:nnnn) by ndp entry */
-/* result is stored in queue */
-/**********************************************************************/
-int getMacAddrListFromNdp(char* interface)
-{
+/************************************************************************/
+/* get MAC address from ndp entry for clientAddr (nnnn:nnnn::nnnn:nnnn) */
+/* result is stored in queue */
+/************************************************************************/
+int getMacAddrListFromNdp(char* interface){
FILE *fpipe;
char buf[BUFFMAXLN];
char* firstTokenP;
char ifStr[WORDMAXLN];
char* ndpPath=NULL;
- /* if null, error return */
+ /* if interface is null, error return */
if(isNull(interface)){
err_msg("ERR at %s#%d: NIC device name is not set",__FILE__,__LINE__);
return -1;
}
- /* exec proc */
- /* exec proc */
+ /* exec NDP 'ndp -a' , output to pipe */
if(isNull(ndpPath=GetConfValue("NdpPath"))){
err_msg("ERR at %s#%d:ndp path is not set in conf",__FILE__,__LINE__);
return -1;
return -1;
}
- /* get ndp response */
+ /*** get ndp response from pipe */
/* skip first title line */
if(fgets(buf, BUFFMAXLN, fpipe)==NULL){
err_msg("ERR at %s#%d: readin error",__FILE__,__LINE__);
return -1;
}
+ /* get MAC address from arp response */
/* arp response takes following format */
- /* "[IPv6 Addr] [Mac] [InterfaseID] [Expire] [Status] [Flags] [Prbs]" */
- /* get MAC address from above string */
+ /* "[IPv6 Addr] [Mac] [InterfaceID] [Expire] [Status] [Flags] [Prbs]" */
while(fgets(buf, BUFFMAXLN, fpipe)!=NULL){
firstTokenP = strtok(buf," "); /* first token */
/* if other interface, skip */
if(strstr(thirdTokenP, interface)==NULL) continue;
- /* remove interface description */
- /* form fe80::202:b3ff:fe0a:c30e%fxp1 */
+ /* remove interface description(%fxp1) from the following form */
+ /* 'fe80::202:b3ff:fe0a:c30e%fxp1' */
snprintf(ifStr, WORDMAXLN, "%%%s", interface);
if((p=strstr(firstTokenP, ifStr))!=NULL) *p='\0';
- /* Insert to queue */
+ /* Convert to ARP format */
strlcpy(macAddr, secondTokenP, ADDRMAXLN);
ReFormatMacAddr(macAddr);
+
+ /* Insert to queue */
+ /* initializing queue Initqueue() is needed previously */
Enqueue(macAddr, firstTokenP);
}
/* get MAC address for clientAddr (nnn.nnn.nnn.nnn) by arp request */
/* result is stored in queue */
/*******************************************************************/
-int getMacAddrListFromArp(char* interface)
-{
+int getMacAddrListFromArp(char* interface){
char buf[BUFFMAXLN];
char *startp;
char *endp;
/* set arp options */
snprintf(options, WORDMAXLN, "-a -i %s", interface);
- /* exec arp */
+ /* exec arp 'arp -a -i fxp1', output to pipe */
if(isNull(arpPath=GetConfValue("ArpPath"))){
err_msg("ERR at %s#%d: arp path is not set in conf",__FILE__,__LINE__);
return -1;
return -1;
}
- /* get arp response */
+ /* get arp response from pipe */
while(fgets(buf, BUFFMAXLN, fpipe)!=NULL){
- /* arp response takes following format */
- /* "? (133.49.22.1) at 8:0:20:a5:4:62 [ethernet]"*/
- /* get ip address from above string */
+ /* arp response takes following format */
+ /* "? (133.49.22.1) at 8:0:20:a5:4:62 [ethernet]" */
+ /* get ip address from above string */
if((startp=strstr(buf," ("))==NULL) continue;
startp=startp+2;
if((endp=strstr(startp, ") "))==NULL) continue;
if((strstr(macAddr, ":"))==NULL) continue;
/* save to queue */
+ /* initializing queue Initqueue() is needed previously */
Enqueue(macAddr, ipAddr);
}